Skip to main content

PlaySound

PlaySound [/A [=a ] /BITS=bits /C] soundWave

PlaySound /A [=a ] /BITS=bits {soundWave1, soundWave2 [, soundWaveN...]}

The PlaySound operation plays the audio samples in the named wave. The various sound output parameters -- number of samples, sample rate, number of channels, and number of bits of resolution -- are determined by the corresponding parameters of the wave.

Flags

/A[=a ]Plays sounds asynchronously so that sounds will continue to play after the command itself has executed.
/A=0:Same as no /A flag.
/A=1:Plays sounds asynchronously; same as /A.
/A=2:Stop playing any current sound before starting this one
/A=3:Return with user abort error if output buffers are full (rather than waiting.) Use GetRTError(1) to detect and clear the error condition.
/BITS=bitsControls the number of bits used for each sound sample sent to the sound output hardware.
Use /BITS=24 with a 32-bit integer wave for 24-bit sound data capable of representing values from -8,388,608 to +8,388,607.
If you omit /BITS or use /BITS=0, PlaySound uses the wave's data type and size to determine how many bits are used for each sound sample.
The /BITS flag was added in Igor Pro 9.00.
/CObsolete - do not use.
/C causes sound wave data greater than 16-bits to be converted to 16-bit integer. Such data should range from -32768 to +32767.

Details

The wave's time per point, as determined by its X scaling, must be a valid sampling rate. A value of 1/44100 (CD standard) is typical.

Sound waves can be 8, 16, or 32-bit signed integer waves, or single-precision floating point waves:

  • 8-bit integer waves support a sample range of -128 to +127.
  • 16-bit inter waves support a sample range of -32768 to +32767.
  • 32-bit integer waves are used to hold both 24-bit and 32-bit audio. Use /BITS=24 to tell PlaySound that the wave contains 24-bit instead of 32-bit values.
  • 32-bit floating point waves support a range of -1 to +1.

Do not use complex waves with PlaySound.

To play a stereo sound, provide a 2 column wave with the left channel in column 0. Actually, the software will attempt to play as many channels as there are columns in the wave. You can also use multiple1D waves with the /A flag. To use this method, enclose the list of 1D waves in braces.

If the /A flag is provided then the sound is played asynchronously (i.e., the command returns before the sound is finished). If another command is issued before the sound is finished then the new command will wait until the last sound finishes. A PlaySound without the /A flag can play on top of the current sound. The transition between sounds might be slightly delayed.

It is OK to kill the sound wave immediately after PlaySound returns even if the /A flag is used.

Examples

Make/B/O/N=1000 sineSound       // 8 bit samples
SetScale/P x,0,1e-4,sineSound // Set sample rate to 10Khz
sineSound= 100*sin(2*Pi*1000*x) // Create 1Khz sinewave tone
PlaySound sineSound

The following example will create a rising pitch in the left channel and a falling pitch in the right channel:

Make/W/O/N=(20000,2) stereoSineSound    // 16 bit data
SetScale/P x,0,1e-4,stereoSineSound // Set sample rate to 10Khz
stereoSineSound= 20000*sin(2*Pi*(1000 + (1-2*q)*150*x)*x)
PlaySound/A stereoSineSound // 16 bit, asynchronous

Multichannel sounds as in the previous example but from multiple 1D waves:

Make/W/O/N=20000 stereoSineSoundL,stereoSineSoundR      // 16 bit data
SetScale/P x,0,1e-4,stereoSineSoundL,stereoSineSoundR // Set sample rate to 10Khz
stereoSineSoundL= 20000*sin(2*Pi*(1000 + 150*x)*x) // rising pitch in left
stereoSineSoundR= 20000*sin(2*Pi*(1000 - 150*x)*x) // falling in right
PlaySound/A {stereoSineSoundL,stereoSineSoundR} // two 1D waves

See Also

SoundLoadWave, SoundSaveWave