Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Sound Card Auto_Recorder (Sound-Activated) Mini-App
Daqarta includes a Sound-Activated Recorder macro mini-app called Auto_Recorder. It records sound or other signal events that may be separated by long periods of relative quiet, without recording those quiet periods themselves. This simplifies later analysis since you don't have to scan through empty sections. Auto_Recorder also allows you to create a companion text log file of the recorded event start times.
To run Auto_Recorder, hit the F8 key followed by the SHIFT+A keys. Note that this macro ID is case-sensitive because the Audible Phase Demonstration macro uses a lowercase a as its ID.
Auto_Recorder uses a Custom Controls dialog that allows adjustment of various parameters. You can open this Help topic by right-clicking anywhere in the dialog. (You can also open it by clicking on the Help button when Auto_Recorder is selected in the Macro List, or in the Macro Edit dialog.)
Auto_Recorder starts in setup mode (Record button off), which allows you to set the various controls for optimum event detection before you start the actual recording. Two custom meter displays will appear during setup: The first is the Auto-Record Events meter which shows "Wait for Event 0" until the initial event is detected, and "Detecting Event 0" in green text while the event is going on. When the initial Event 0 is over it waits for Event 1, etc. This same meter is present during actual recording, except instead of "Detecting..." in green it shows "Recording..." in red.
The second meter is Auto-Record Setup and only appears when the Record button is off. It shows the current maximum and minimum signal levels, to aid in setting thresholds. Both meters can be dragged and resized as desired.
The Event Threshold control at the upper left sets the minimum sound or signal event level that will initiate recording; softer sounds are ignored until this threshold is reached.
Once the Event Threshold is reached, the event is considered to have begun. With the Record button off the Event meter changes to green text for the duration of the event, but nothing else happens until the event ends. The event ends when the sound drops below the Quiet Threshold and remains below it for the Minimum Quiet duration. This prevents stuttering from multiple rapid events, or missing critical tail-end features of a slow-decaying event.
By default the Left input is monitored for events. You can toggle the Event = Left button to Event = Right or Event = Both as needed.
Detection defaults to RMS Mode, which means that the Event and Quiet Threshold controls monitor the Root Mean Square value of each 1024-sample frame, about 21 msec at the default 48000 Hz sample rate. The Setup meter also shows the current RMS value, with a response time set by the Setup TC (Time Constant) button that can be toggled between 10, 100 (default), and 1000 frames. (See Meter Time Constants under Custom Meters for more information.)
Toggling the RMS Mode button to Peak Mode changes the detection scheme such that the Event and Quiet thresholds look for instantaneous positive or negative peak values, no matter how brief or of which polarity.
Note that the Event = Both mode is handled differently for RMS and Peak; in RMS mode the sum of the Left and Right RMS values is used, while in Peak mode it is the greater of the Left or Right peak values.
The reason for separate RMS and Peak modes is to allow you to optimize detection based on the nature of the signal, compared to whatever background noise you want to ignore. Steady signals are favored by the RMS process, compared to brief noise spikes or bursts which contribute less to the average. Conversely, Peak mode is best for detecting events that are themselves peaky, and for ignoring steady low-level background noise.
As an example, suppose you are studying animals in the wild and want to record infrequent distant roars, but not nearby loud insect chirps. Assuming the chirps are not too frequent (like a steady buzz), the RMS mode will probably be best.
On the other hand, if you want to record infrequent nearby chirps above a backround of wind noises like rustling grass or tree leaves, Peak mode should be your first choice.
Whichever mode you use, the basic setup procedure is to first set the Event Threshold so you detect every event: Too high and the Auto-Record Events meter will just sit in the "Waiting for Event" state, while too low and it will detect spurious "events" due to the background noise. If the events are very brief, it may be hard to see the "Detecting" message before it switches to waiting for the next event, but you will see the event number increase.
Note that the optimum Auto-Record Setup meter values may be quite different between the two detection modes. Also note that the threshold values in Peak mode correspond directly to the peaks on the waveform display, since the values are in percent of full scale (FS). However, even though RMS readings are also in percent of full scale, they will only correspond to the RMS amplitudes of a steady waveform, and will never reach more than about 70% (the RMS value of a full-scale pure sine wave).
Next, set the Quiet Threshold so that once an event is detected (and the Events meter shows "Detecting Event..."), it switches to waiting as soon as the event is over. If your events have long-decaying tails, or tend to have an initital event followed by a series of "echoes" or trailing events, set the Minimum Quiet delay time to include those.
Finally, set the PreStart time to include any below-threshold "leading edge" of the event, which can be up to 1 second before the Event Threshold is detected. This can be useful when events build up slowly to a level high enough for reliable triggering, but it can also be used for abrupt events that are preceded (and perhaps caused) by something else that you want to record. This may include a signal on the other (Left or Right) channel, which doesn't need to be the other channel of a conventional stereo microphone setup; it can be a separate (and possibly distant) microphone or other possible stimulus source. Setting the best PreStart may require several trial recordings (see below) since it doesn't show up in the Setup or Events meters.
When you are ready to make a trial recording, toggle the Record button on. The default file name is AutoRec0.DQA, as shown on the button to the left of Record; any existing file of that name will be overwritten without a confirmation prompt.
The Setup Meter will vanish and the count on the Event Meter will be reset to zero and begin waiting for the next event. As each event is recorded, the message line (just above the main Daqarta Generator Title window) will show total bytes written to the file, along with the file name.
This default file allows you to make a quick trial recording, with the idea that you will exit Auto_Recorder and check that the file is what you expected. You can make the trial recording simply by waiting until the Event meter indicates some reasonable number of events recorded, then toggling Record off.
Before you exit Auto_Recorder to check the trial recording, you may want to save the current settings by clicking the Save Settings button at the lower left. This saves the Event Threshold, Quiet Threshold, PreStart, Minimum Quiet, RMS/Peak state, Event channel, and Setup TC to a separate file. You can then restore these settings later (in the same session or a subsequent one) via the Load Settings button at the lower right. See the Save / Load Settings subtopic below for more information.
To exit Auto_Recorder, hit the OK button at the bottom of the Auto-Recorder Controls dialog, or the [X] at the upper left.
Note that you will then need to toggle the Input button off (and Generator as well, if it was active) so that the DDisk button changes to DD/Open. Click on DD/Open and open the file you just created. You can scroll through it with the <> keys (plus SHIFT or ALT for larger steps), or with the little buttons below the DD/Open button. See Reading DDisk Files for more about file navigation, and see also the File_Nav File Navigator Mini-App.
If the trial file isn't quite right, you can restart the Input and Auto_Recorder and try again, overwriting the AutoRec0.DQA file. As noted above, use Load Settings to restore the previously-saved settings to proceed from the prior values. Be sure to use Save Settings for each trial.
When you are ready to make a "keeper" recording, you should first enter the file name by clicking the File: AutoRec0.DQA button and entering the desired name in the Windows Save As dialog. The default file type is shown as "Buffer Daqarta Files (.DQA)", but you can optionally use the Save as type drop-down selector at the bottom of the dialog to select .WAV or .DAT instead.
Pay no attention to the "Buffer" here; it simply indicates that the file will be created using Macro Arrays Buf0-7, but it will still be a normal .DQA (or .WAV or .DAT) file. .DQA is Daqarta's extended .WAV format, which has the advantage that it includes information about relevant Daqarta parameters such as calibration, as well as any Notes you have entered. Notes can be especially important for saving your observations during a long recording; see also Saving Notes to the Log File under Event Logging, below.
(The .DQA format is fully compatible with .WAV, but other software may not realize that; such software may refuse to include the file in its selection list unless you rename the file to have a .WAV extension.)
You can stop and start the recording operation by toggling the Record button. When it is off, the Setup Meter returns and the Event Meter count is reset to zero. When you restart the recording, the Setup Meter vanishes again, and the Event Meter count resumes from where it originally left off.
Note that the file name button is disabled during recording, and is re-enabled when you toggle Record off. You can then enter a new file name; when Record is toggled back on, the Event Meter count will start from 0 for the new file.
When the Event Logging button is active, any event in Record mode will be logged to a text file whose name is the same as the main data file, but with a .TXT extension. Each event entry consists of Event, Date, Time, and File Time. The latter is the time relative to the start of the data file, to aid in later locating the event.
A header is sent to the log file before the initial entry. It consists of an empty line, a line with the file name, two lines showing the current settings (labels and values for Event Channel, RMS/Peak mode, Event Threshold, Quiet Threshold, PreStart, Minimum Quiet, and Setup TC), and a line showing the column labels. If you toggle Record off (which of course stops event logging), then when you restart recording the header is given again to mark the discontinuity.
Likewise, if you toggle Event Logging off during a recording, then when you toggle it back on the header is given again.
When Event Logging is active during recording, you can save the current contents of the Notes area to the log file by holding down the ALT key while clicking the Event Logging button. (The button will flicker off and back on once when you do this.)
Notes are ordinarily saved with the .DQA data file, and are displayed when you later open that file for analysis. However, for a long recording where you want to save many comments, you may overflow the 2047-character Notes limit.
If you are also using Event Logging, you can save Notes to the log file after each comment, then delete Notes to provide a fresh space. (That also prevents cluttering up the log file with redundant notes on later saves.)
TIP: Unlike normal event logging, there is no automatic date and time entry when you save Notes to the log file. Thus, when entering comments in Notes, you may want to use CTRL+ALT+D to enter the current date, and/or CTRL+ALT+T to enter the current time for each comment. This provides a record of the time of your observation.
You can change the settings during the recording. If you do, you should also click Save Settings. That not only saves them to the settings file, it also sends them to the log file (if active) along with the current date and time, to help with later analysis.
If you make temporary changes and do not save them, you can restore the previously-saved changes for the recording using Load Settings. This will likewise send them to the log file, if active.
By default, settings are saved to a file whose name consists of the main recording file name, but with a .BUF extension. For example, the default recording goes to AutoRec0.DQA, while its settings are saved to AutoRec0.BUF.
Alternatively, you can save the settings to a .BUF file whose name you choose. To do this, hold the CTRL key down while you click the Save Settings button; a Save As dialog will open showing all .BUF files, allowing you to select one for replacement, or enter a new name of your choice. This file will then become the default for Save Settings and Load Settings until changed.
Likewise, you can load settings from a file other than the current default by holding down the CTRL key while you click Load Settings. This allows you to switch between multiple settings, either during a long recording, or when starting a new recording with known settings requirements. Again, note that the selected file becomes the new default for both Save and Load Settings.
If you change the settings but forget to save them, you can do it after ending the recording as long as you have not entered a new file name for the next recording.
You can also send a time-stamped copy of the settings to Notes by holding down the ALT key while clicking Save Settings. Notes are saved along with the main recording as long as you use the default .DQA file extension. When you later open the file for analysis in Daqarta, the Notes will be displayed. This is independent of Event Logging, and keeps a record of the relevant changes with the data itself.
However, please keep in mind that Notes holds a maximum of 2047 characters, and each save takes at least 175. That limits you to about 11 change saves, assuming you don't enter other notes during the recording. If you are going to be using Event Logging anyway, which saves a copy of all settings when you use Save Settings or Load Settings, you may not want to send them to Notes. If you enter a lot of Notes manually, see the Saving Notes to the Log File subtopic, above.
The following summary of variable, control, and array usage is intended to aid in understanding the macro script operation. It can also help in modifying the script, including avoiding accidental re-use of critical variables.
Variables: B Current Input position, samples C Time Constant for Setup meter E Event threshold (32767 = 100% FS) F Input position at start of file L Left input signal value, RMS or Peak M Max signal value, avg w. time constant C N Min signal value, avg w. time constant C P Input pointer to PreStart sample Q Quiet threshold (32767 = 100% FS) QC Working Quiet count, 1024-sample blocks QE File Event count QM Quiet block count limit QN Inverted Negative of R or L peak QP Max PreStart setting, msec QR Recording status flag Qm Max signal value, %FS for Setup display Qn Min signal value, %FS for Setup display R Right input signal value, RMS or Peak S Effective input signal value, RMS or Peak T Time of event relative to file start UE Working Event count UN Number of Input channels UP PreStart block count (1024 samples/block) UT Event Trigger flag Controls: Ctrl0 Event Threshold Ctrl1 Quiet Threshold Ctrl2 Prestart msec Ctrl3 Minimum Quiet msec Btn0 File name Btn1 Record toggle Btn2 RMS / Peak toggle Btn3 Event Logging toggle Btn4 Event channel (Left, Right, Both) Btn5 Setup TC (10, 100, 1000) Btn6 Save Settings Btn7 Load Settings Arrays: Buf0 Left input data Buf1 Right input data Buf2 Left PreStart data Buf3 Right PreStart data Buf7 Save/Load Settings Str0 Control label strings, Save/Load Settings file name Str1 File name for recording
;<Help=H4920 IF.Input=0 ;Input active? Msg="No Input! Macro cancelled." LoopBreak=-1 ;Exit macro if not ENDIF. Enable#IG=0 ;Prevent Input/Gen changes or toggle UN=InL + InR ;UN = number of Input chans ;Control labels in Str0 with terminal nulls (z): Str0="RMS Event Threshold, %FS" +z ;Ctrl0 w. Btn2 = 0 Str0="Peak Event Threshold, %FS" +z ;Ctrl0 w. Btn2 = 1 Str0[2*32]="RMS Quiet Threshold, %FS" +z ;Ctrl1 w. Btn2 = 0 Str0[3*32]="Peak Quiet Threshold, %FS" +z ;Ctrl1 w. Btn2 = 1 Str0="RMS Mode" +z ;Btn2 = 0 Str0[130 + 16]="Peak Mode" +z ;Btn2 = 1 Str0="Event = Left " +z ;Btn4 = 0 Str0[170 + 16]="Event = Right" +z ;Btn4 = 1 Str0[170 + 2*16]="Event = Both " +z ;Btn4 = 2 Str0="Setup TC = 10 " +z ;Btn5 = 0 Str0[220 + 16]="Setup TC = 100 " +z ;Btn5 = 1 Str0[220 + 2*16]="Setup TC = 1000" +z ;Btn5 = 2 Str0="AutoRecSet0" +z ;Save/Load Settings filename Ctrls="<<Auto-Recorder Controls" ;Dialog title Ctrl0="<<" + Str0 ;Ctrl0 title = "RMS Event..." Ctrl0="<S(1,100)" ;Ctrl0 slider range = 0-100% Ctrl0="<p(0)" ;Integer only (no decimal places) Ctrl0=25 ;Default = 25% of full scale E=Ctrl0 / 100 * 32767 ;%FS to binary event thresh QE=0 ;File event count UE=0 ;Working count Ctrl1="<<" + Str0 ;"<<RMS Quiet Threshold, %FS" Ctrl1="<S(0,100)" ;0-100% range Ctrl1="<p(0)" ;Integer only Ctrl1=1 ;Default = 1% FS Q=Ctrl1 / 100 * 32767 ;%FS to binary quiet thresh QC=0 ;Count of quiet blocks Ctrl2="<<PreStart, ms" ;ms to save *before* event QP=1000 * 48000 / SmplRate ;Max PreStart, msec Ctrl2="<S(0,QP)" ;1000 ms at 48000 Hz sample rate Ctrl2="<p(0)" ;Integer only Ctrl2=20 ;Default = 20 ms UP=ceil((Ctrl2 / 1000) * SmplRate / 1024) ;ms to 1024-sample blocks Ctrl3="<<Minimum Quiet, ms" ;ms of quiet to end event Ctrl3="<S(0,5000)" ;5 secs max Ctrl3="<p(0)" ;Integer only Ctrl3=40 ;Default = 40 ms QM=ceil((Ctrl3 / 1000) * SmplRate / 1024) Btn0="<T" ;Btn0 = Filename toggle Btn0=0 ;Default state Btn0="File: AutoRec0.DQA" ;Default filename Btn1="<T" ;Btn1 = Record toggle Btn1=0 Btn1="Record" QR=0 ;Recording status flag Btn2="<T" ;Btn2 = RMS / Peak toggle Btn2=0 Btn2="" + Str0 ;"RMS Mode" Btn3="<T" ;Btn3 = data logging toggle Btn3=0 Btn3="Event Logging" Btn4=0 ;Btn4 = Left/Right/Both chan select IF.UN=2 ;Stereo? Btn4="<M(2)" ;3-state button ELSE. ;Else mono IF.InR=1 ;Right-only? Btn4=1 ENDIF. Btn4="<D" ;No toggle if mono ENDIF. Btn4="" + Str0[170 + 16 * Btn4] ;"Event = Left", etc Btn5="<M(2)" Btn5=1 Btn5="" + Str0[220+ 16 * Btn5] ;"Setup TC = 100" C=10 * 10^(Btn5) ;Time constant for Setup meter Btn6="Save Settings" Btn6="<M" Btn7="Load Settings" Btn7="<M" Mtr0="<F(32)" ;Default Mtr0 font Mtr0="<C(0,0,0)" ;Default black text Mtr0="<<Auto-Record Events" ;Mtr0 title Mtr1="<F(32)" ;Default Mtr1 font Mtr1="<C(0,0,0)" ;Black text Mtr1="<<Auto-Record Setup" ;Title UT=0 ;Event trigger flag M=0 ;Default max event level N=32767 ;Default min event level Mtr0="Wait for Event " + UE B=Posn?I ;Initial input block posn Task="_Auto_Rec_Task" ;Start background Task @_Auto_Rec_Ctrls=Ctrls ;Start Controls handler Task="-_Auto_Rec_Task" ;End task on Ctrls exit Mtr0= ;Remove main meter Mtr0="<C(0,0,0)" ;Restore default black text Mtr1= ;Remove Setup meter A.LogName="DqaLog" ;Restore default Log file Enable#IG=1 ;Enable Input/Gen changes
;<Help=H4920 IF.Ctrls=0 ;Event Threshold % E=Ctrl0 / 100 * 32767 ;%FS to binary event thresh ENDIF. IF.Ctrls=1 ;Quiet Threshold % Q=Ctrl1 / 100 * 32767 ;%FS to binary quiet thresh ENDIF. IF.Ctrls=2 ;PreStart ms UP=ceil((Ctrl2 / 1000) * SmplRate / 1024) ENDIF. IF.Ctrls=3 ;Min Quiet, ms QM=ceil((Ctrl3 / 1000) * SmplRate / 1024) ENDIF. IF.Ctrls=4 ;Btn0 = File name IF.Btn0=1 ;Going down? Buf0#N=UN ;Set number of chans to save Buf0#S=1 ;Save only one sample / chan Buf0="<SaveDQA:" ;Get file name from Save As dialog IF.Posn?f=1 ;Valid name entered? GetFilePath=2 ;Get Save path and name Str1=FileName +z ;Save full path with name Str1=FileName?n +z ;Save name only Str1=FileName?N +z ;Save name with extension Btn0=""+Str1 ;Show name on Btn0 ELSE. ;Else exit, no valid file name Btn0="File: AutoRec0.DQA" ;Restore default file name Btn0=0 ;Restore default button state ENDIF. Buf0#S=1024 ;Save full blocks from now on ELSE. ;Else going up Btn0="File: AutoRec0.DQA" ;Restore default file name ENDIF. QE=0 ;Clear event count for new file QR=0 ;Clear Recording status flag ENDIF. IF.Ctrls=5 ;Btn1 = Record toggle IF.Btn1=1 ;Going on? Btn0="<D" ;Disable filename change Mtr1= ;Remove Setup meter IF.Btn0=0 ;No user-set file name? Buf0#N=UN ;Set number of chans to save Buf0#S=1 ;Save only one sample / chan A.Buf0="<SaveDQA:AutoRec0" ;Use default file name GetFilePath=2 ;Get Save path and name Str1=FileName +z ;Save full path with name Str1=FileName?n +z ;Save name only Str1=FileName?N +z ;Save name with extension Buf0#S=1024 ;Save full blocks from now on ENDIF. UE=QE ;Event number IF.Btn3=1 ;Data Logging on? A.LogName=FileName?n ;Use data file name w. TXT ext. LogTxt=n +n +FileName?N ;Header for new log section LogTxt=n +"Chan" +p7 +"Mode" +p13 +"Thresh" +p21 _ ;Settings +"QuTh" +p27 +"PreSt" +p34 +"MinQu" +p42 +"TC" _ +n + Str0[178 + 16*Btn4,-5] +p8 +Str0[32*Btn2,-4] _ +p16 +Ctrl0(0) +p23 +Ctrl1(0) +p29 +Ctrl2(0) _ +p36 +Ctrl3(0) +p43 +Str0[231 + 16*Btn5] LogTxt=n +"Event" +p10 +"Date" +p23 +"Time" _ ;Event header +p40 +"File Time" ENDIF. QR=1 ;Recording has started ELSE. ;Else Record going off Btn0="<N" ;Enable filename change QE=UE ;Save current event count M=0 ;Reset Setup meter peak N=32767 ;Reset Setup meter min UE=0 ;Reset event number ENDIF. Mtr0="Wait for Event " + UE UT=0 ;No trigger yet QC=0 ;Reset quiet count B=Posn?D ;Current input block posn = display start IF.QE=0 ;Start of file? F=B ;File-relative start posn ENDIF. ENDIF. IF.Ctrls=6 ;Btn2 = RMS / Peak Mode Btn2="" + Str0[130 + 16*Btn2] ;"RMS Mode", etc Ctrl0="<<" + Str0[32*Btn2] ;"RMS Event..." Ctrl1="<<" + Str0[64 + 32*Btn2] ;"RMS Quiet..." M=0 ;Reset Setup meter max N=32767 ;Reset Setup meter min ENDIF. IF.Ctrls=7 ;Btn3 = Event Logging toggle IF.Btn3=0 ;Going off? IF.(Key?$ & 2)=2 ;Due to ALT+click while on? Btn3=1 ;Back on if so IF.Btn1=1 ;Recording? LogTxt=+n +Notes ;Save Notes to log ENDIF. ENDIF. ELSE. ;Else going on IF.Btn1=1 ;Recording? A.LogName=FileName?n ;Log file name = data name w. TXT LogTxt=n +n +FileName?N ;Send header for new log section LogTxt=n +"Chan" +p7 +"Mode" +p13 +"Thresh" +p21 _ ;Settings +"QuTh" +p27 +"PreSt" +p34 +"MinQu" +p42 +"TC" _ +n + Str0[178 + 16*Btn4,-5] +p8 +Str0[32*Btn2,-4] _ +p16 +Ctrl0(0) +p23 +Ctrl1(0) +p29 +Ctrl2(0) _ +p36 +Ctrl3(0) +p43 +Str0[231 + 16*Btn5] LogTxt=n +"Event" +p10 +"Date" +p23 +"Time" _ ;Event header +p40 +"File Time" ENDIF. ENDIF. ENDIF. IF.Ctrls=8 ;Btn4 = Left/Right/Both event channel Btn4="" + Str0[170 + 16 * Btn4] ;"Event = Left", etc ENDIF. IF.Ctrls=9 ;Btn5 = Time Constant Btn5="" + Str0[220 + 16 * Btn5] ;"Setup TC = 10". etc C=10 * 10^(Btn5) ;10, 100, 1000 M=0 ;Reset Setup meter max N=32767 ;Reset Setup meter min ENDIF. IF.Ctrls=10 ;Btn6 = Save Settings IF.(Key?$ & 2)=2 ;ALT key down when Save Settings clicked? Notes=Notes + n + d +b4 +t _ ;Date and time to Notes +n +"Chan" +p9 +"Mode" +p16 +"Thresh" +p28 _ ;Settings +"QuTh" +p38 +"PreSt" +p48 +"MinQu" +p58 +"TC" _ +n + Str0[178 + 16*Btn4,-5] +p12 +Str0[32*Btn2,-4] _ +p23 +Ctrl0(0) +p40 +Ctrl1(0) +p54 +Ctrl2(0) _ +p66 +Ctrl3(0) +p80 +Str0[231 +16*Btn5] ENDIF. Buf7=Ctrl0 ;Event Thresh to start of Buf7 Buf7=Ctrl1 ;Quiet Thresh Buf7=Ctrl2 ;PreStart Buf7=Ctrl3 ;Min Quiet Buf7=Btn2 ;RMS/Peak state Buf7=Btn4 ;Event channel Buf7=Btn5 ;Setup TC Buf7#S=7 ;Only save 7 items Buf7#N=1 ;Single channel IF.(Key?$ &1)=1 ;CTRL key down when Save Settings clicked? Buf7="<Save:" + Str0 ;Open Save dialog w. current name IF.Posn?f=1 ;Name selected or entered? GetFilePath=2 ;Get Save path Str0=FileName +z ;Store Save path ELSE. ;Else Cancel hit, no name A.Buf7="<Save:" + Str0 ;Use prior stored name ENDIF. ELSE. ;No CTRL key, do immediate Save A.Buf7="<Save:" + Str0 ;Use prior stored name ENDIF. IF.(Btn3 & QR)=1 ;Logging & Recording active? LogTxt=n+n + d +b4 +t _ ;Log header date and time +n +"Chan" +p7 +"Mode" +p13 +"Thresh" +p21 _ ;Settings +"QuTh" +p27 +"PreSt" +p34 +"MinQu" +p42 +"TC" _ +n + Str0[178 + 16*Btn4,-5] +p8 +Str0[32*Btn2,-4] _ +p16 +Ctrl0(0) +p23 +Ctrl1(0) +p29 +Ctrl2(0) _ +p36 +Ctrl3(0) +p42 +Str0[231 + 16*Btn5] LogTxt=n +"Event" +p10 +"Date" +p23 +"Time" _ ;Event header +p40 +"File Time" ENDIF. ENDIF. IF.Ctrls=11 ;Btn7 = Load Settings Buf7#K=1 ;Don't clear Buf7 before load Buf7#N=1 ;Single channel IF.(Key?$ &1)=1 ;CTRL + Load Settings click? Buf7="<Load:" + Str0 ;Open dialog with current name IF.Posn?f=1 ;Name selected or entered? GetFilePath=1 ;Get Open path Str0=FileName +z ;Store path ELSE. ;Else Cancel hit, no name A.Buf7="<Load:" + Str0 ;Use prior stored name ENDIF. ELSE. ;No CTRL, immediate load A.Buf7="<Load:" + Str0 ;Use prior stored name ENDIF. Ctrl0=Buf7 ;Event Thresh was loaded into Buf7 E=Ctrl0 / 100 * 32767 ;%FS to binary event thresh Ctrl1=Buf7 ;Quiet Thresh from Buf7 Q=Ctrl1 / 100 * 32767 ;%FS to binary quiet thresh Ctrl2=Buf7 ;PreStart from Buf7 UP=ceil((Ctrl2 / 1000) * SmplRate / 1024) Ctrl3=Buf7 ;Min Quiet from Buf7 QM=ceil((Ctrl3 / 1000) * SmplRate / 1024) Btn2=Buf7 ;RMS/Peak state from Buf7 Btn2="" + Str0[130 + 16*Btn2] ;"RMS Mode", etc Ctrl0="<<" + Str0[32*Btn2] ;"RMS Event..." Ctrl1="<<" + Str0[64 + 32*Btn2] ;"RMS Quiet..." Btn4=Buf7 ;Event chan from Buf7 Btn4="" + Str0[170 + 16*Btn4] ;"Event = Left", etc Btn5=Buf7 ;Setup TC from Buf7 Btn5="" + Str0[220 + 16*Btn5] ;"Setup TC = 10". etc C=10 * 10^(Btn5) ;10, 100, 1000 M=0 ;Reset Setup meter max N=32767 ;Reset Setup meter min IF.(Btn3 & QR)=1 ;Logging & Recording? LogTxt=n+n + d +b4 +t _ ;Log header date and time +n +"Chan" +p7 +"Mode" +p13 +"Thresh" +p21 _ +"QuTh" +p27 +"PreSt" +p34 +"MinQu" +p42 +"TC" _ +n + Str0[178 + 16*Btn4,-5] +p8 +Str0[32*Btn2,-4] _ +p16 +Ctrl0(0) +p23 +Ctrl1(0) +p29 +Ctrl2(0) _ +p36 +Ctrl3(0) +p43 +Str0[231 + 16*Btn5] LogTxt=n +"Event" +p10 +"Date" +p23 +"Time" _ +p40 +"File Time" ENDIF. ENDIF.
;<Help=H4920 WHILE.Posn?I=>B + 1024 ;Wait for 1024 new samples IF.UN=2 ;Stereo? Buf0="<=D0(B)" ;Get Left data Buf1="<=D1(B)" ;Get Right data ELSE. ;Else mono IF.InR=1 ;Right mono? Buf0="<=D1(B)" ;Get Right data only ELSE. Buf0="<=D0(B)" ;Else get Left only ENDIF. ENDIF. Ch=0 ;Buf0 ptr IF.Btn2=0 ;RMS mode? L=BwSig(0,1023) ;Get RMS of all Left/mono samples IF.Btn4=>0 ;Event = Right (1) or Both (2)? Ch=1 ;Right data in Buf1 R=BwSig(0,1023) ;RMS of all Right samples IF.Btn4=2 ;Both? S=L + R ;Signal = sum for stereo ELSE. ;Else Right S=R ;Signal = Right only ENDIF. ELSE. ;Else mono S=L ;Signal = mono Left or Right ENDIF. ELSE. ;Else Peak mode L=Buf0?p ;Pos peak, Left or mono Right QN=-Buf0?n ;Inverted neg peak IF.QN=>L ;Neg larger? L=QN ;L = largest ENDIF. S=L ;Assume Signal = Left IF.Btn4=>0 ;Event = Right (1) or Both (2)? R=Buf1?p ;Right pos peak QN=-Buf1?n ;Inverted neg peak IF.QN=>R ;Neg larger? R=QN ;R = largest ENDIF. IF.Btn4=2 ;Both? IF.R=>L ;Right larger than Left? S=R ;Signal = largest of R or L ENDIF. ELSE. ;Else Right only S=R ENDIF. ENDIF. ENDIF. IF.Btn1=1 ;Record active? IF.UT=1 ;Trig event already found? IF.S=<Q ;Below quiet thresh? QC=QC+1 ;Count quiet block IF.QC=>=QM ;Enough to stop recording? UT=0 ;Trig over QC=0 ;Reset quiet count UE=UE+1 ;Next event number Mtr0="Wait for Event " + UE ELSE. ;Not quiet long enough Buf0#N=UN ;Set number of chans to record A.Buf0="<SAveDQA:" + Str1 ;Append to file, path in Str1 ENDIF. ELSE. ;Not quiet enough QC=0 ;Reset quiet count Buf0#N=UN ;Set number of chans to record A.Buf0="<SAveDQA:" + Str1 ;Append to file, path in Str1 ENDIF. ELSE. ;No trigger event yet IF.S=>E ;Event threshold exceeded? IF.UT=0 ;First time this event? Mtr0="<C(255,0,0)" ;Red Mtr text color Mtr0="Recording Event " + UE ;Show event Mtr0="<C(0,0,0)" ;Restore black text ENDIF. UT=1 ;Flag = trig event found IF.UP=>0 ;PreStart requested? P=B - (UP * 1024) ;Back up by UP blocks UI=0 ;Block counter WHILE.UI=<UP ;Save all blocks IF.UN=2 ;Stereo? Buf2="<=D0(P)" ;Get Left data Buf3="<=D1(P)" ;Get Right data ELSE. ;Else mono IF.InR=1 ;Right mono? Buf2="<=D1(P)" ;Get Right data only ELSE. Buf2="<=D0(P)" ;Else get Left ENDIF. ENDIF. Buf2#N=UN ;Set num chans to record A.Buf2="<SAveDQA:" + Str1 ;Append to file, path in Str1 P=P+1024 ;Next 1024-sample block UI=UI+1 ;Count the block WEND. ENDIF. ;PreStart done Buf0#N=UN ;Num chans for main event A.Buf0="<SAveDQA:" + Str1 ;Append to file, path in Str1 IF.Btn3=1 ;Event Logging active? T=(B - F) / SmplRate ;File-relative time LogTxt=n +UE +p10 +d +p23 +t _ ;Log event start +p40 +T(T.3) ENDIF. ENDIF. ENDIF. ELSE. ;Else Record off = Setup mode IF.S=>M ;Signal greater than max peak? M=S ;Max peak = signal ELSE. ;Else apply C time constant decay to max M=M + (S - M) / C ENDIF. IF.S=<N ;Signal less than min? N=S ;Min = signal ELSE. ;Else apply time constant to min N=N + (S - N) / C ENDIF. Qm=100 * M / 32767 ;Convert max to %FS Qn=100 * N / 32767 ;Convert min to %FS Mtr1=Qm +"%" +n + Qn +"%" ;Show current signal max and min IF.UT=1 ;Trig already found? IF.S=<Q ;Below quiet thresh? QC=QC+1 ;Count quiet block IF.QC=>=QM ;Enough to stop recording? UT=0 ;Trig over QC=0 ;Reset quiet count UE=UE+1 ;Next event number Mtr0="Wait for Event " + UE ENDIF. ELSE. ;Not quiet enough QC=0 ;Reset quiet count ENDIF. ELSE. ;No trigger event yet IF.S=>E ;Event found? IF.UT=0 ;First block of event? Mtr0="<C(0,255,0)" ;Green Mtr text color Mtr0="Detecting Event " + UE ;Show event Mtr0="<C(0,0,0)" ;Restore black text ENDIF. UT=1 ;Flag = trig event found ENDIF. ENDIF. ENDIF. B=B + 1024 ;Ptr to start of next block WEND.
See also Macro Examples and Mini-Apps
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 35 Years of Innovative Instrumentation
© Copyright 2007 - 2021 by Interstellar Research
All rights reserved