Data AcQuisition And Real-Time Analysis
Scope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
The following is from the Daqarta Help system:



Spectrum Analyzer

Signal Generator

(Absolutely FREE!)


Pitch Tracker


DaqMusiq Generator
(Free Music... Forever!)

Engine Simulator

LCR Meter

Remote Operation

DC Measurements

True RMS Voltmeter

Sound Level Meter

Frequency Counter
    Spectral Event

    MHz Frequencies

Data Logger

Waveform Averager


Post-Stimulus Time
Histogram (PSTH)

THD Meter

IMD Meter

Precision Phase Meter

Pulse Meter

Macro System

Multi-Trace Arrays

Trigger Controls


Spectral Peak Track

Spectrum Limit Testing

Direct-to-Disk Recording



Frequency response

Distortion measurement

Speech and music

Microphone calibration

Loudspeaker test

Auditory phenomena

Musical instrument tuning

Animal sound

Evoked potentials

Rotating machinery


Product test

Contact us about
your application!

WAV File Stereo-to-Mono Macro


The WAV_to_Mono Stereo-to-Mono macro is included with Daqarta. (See Macro Examples and Mini-Apps for the list.) It allows you to convert a stereo .WAV file to mono automatically, saving it in the original folder but with '_1' appended to the original file name.

To run WAV_to_Mono, hit the F8 key followed by the shifted 'W' key. Note that this macro ID is case-sensitive because the WAV_to_16bit macro uses a lowercase 'w' as its ID.

Alternatively, hit CTRL+F8 to open the Macro Dialog and then double-click on WAV_to_Mono in the Macro List.

This macro demonstrates how to use Macro Arrays (here Buf0 and Buf1), including Macro Array File Operations and Math Operations, as well as File Path and Name macros GetFilePath and FileName.

WAV_to_Mono first clears any old Custom Messages using Msg=, then invokes an Open dialog to allow file selection. It does this by first specifying the number of channels to load using Buf0#N=0, which indicates that the following Buf0="<LoadWAV:" command will be a "dummy" load that just tests for existence and reads the number of channels from the .WAV file header.

Since there was no A. prefix ahead of the load command, an Open dialog is shown. Since there was no file name after the colon, the Open dialog will show no default name.

After the file is selected, the returned number of channels is tested via IF.Buf0?N=2 to make sure it is stereo. If not (the final ELSE clause), the macro exits with a message reporting the actual number of channels and stating that it is not a stereo WAV file.

If the file is stereo, the macro copies the file path with GetFilePath=1. It then sets Buf1#N=0 and attempts a dummy load of a file of that name with an added '_1', using:

    A.Buf1="<LoadWAV:" + FileName?P + "_1"

The A. prefix means that this is done automatically, with no Open dialog. The explicit file name after the colon is built up as a string expression using the existing path and name FileName?P plus a quoted "_1" immediate string. The 'P' option to include the path allows the file to reside in any folder; if FileName?n had been used, Daqarta's default User_Data folder would be assumed.

If the file does not exist the number of channels from the dummy load will be zero in IF.Buf1?N=0. (Otherwise, the macro exits with an "already exists" message for that name.)

WAV_to_Mono uses a {\b WHILE} loop that loads 1024 stereo points (2048 total samples) at a time from the file, putting the left channel 1024 samples into Buf0 and the right into Buf1 via A.Buf0="<LoadWAV:" + FileName?P.

The macro uses variable US to hold the number of points actually read each time, defaulting to 1024 before the loop start. When it finds less than that via US=Buf0?L, it means the end of the file has been reached and the next WHILE loop test will exit without further action.

In order to work through the entire file, the macro must keep advancing the file pointer. It uses variable UF for that, which it initializes to 0 before the loop, and uses to set the pointer via Buf0#L=UF before each load. At the end of each loop pass, the pointer is updated for the next pass via UF=UF+US, which adds the points read to the running total.

The loop adds each left sample from Buf0 to the right sample in Buf1 via Buf1="<+B0", then divides the total in Buf1 by 2 to get the average via Buf1="</(2)". This is needed to prevent overflow of the 16-bit data format of the resulting file, since both original channels could hold large values at the same time. (Buf1 is in no danger of overflow since it holds 32-bit integers. The 32-bit fraction portion is unused here.)

Finally, the resulting 1024 mono points in Buf1 are saved to the output file via

    A.Buf1="<SAveWAV:" + FileName?P + "_1"

The UF pointer is updated as mentioned above, and the WEND causes the loop to return for the next WHILE test.

After each 1024-point block is saved, a status message is shown in the main Daqarta window just above the long Generator title area, such as "123456 bytes written to MyFile.WAV". Typically this happens so fast it is just a blur, then the final value remains.

WAV_to_Mono Macro Listing:

    A.Buf1="<LoadWAV:" + FileName?P + "_1"
            A.Buf0="<LoadWAV:" + FileName?P
            A.Buf1="<SAveWAV:" + FileName?P + "_1"
        Msg=FileName?n + "_1.WAV already exists."
    Msg=Buf0?N + " channel(s)... not a stereo WAV file."

See also Macro Examples and Mini-Apps


Questions? Comments? Contact us!

We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2017 by Interstellar Research
All rights reserved