Basic audio programming
-
Upload
iulian-nicu-serbanoiu -
Category
Technology
-
view
167 -
download
1
description
Transcript of Basic audio programming
![Page 1: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/1.jpg)
Basic audio programming
Iulian Şerbănoiu - March 2010
![Page 2: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/2.jpg)
Contents
●Basic notions○ Sample ○ Sample rate○ Audio bit depth
●Example○ portaudio
●Other audio libraries●References
![Page 3: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/3.jpg)
Basic notions - sample
Each square ( <fi> i=1..12 ) represents a sample
![Page 4: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/4.jpg)
Basic notions - sample rate
Sample rate = number of samples in a secondgreater T -> smaller sample rate -> lower qualitysmaller T -> greater sample rate -> higher quality
![Page 5: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/5.jpg)
Basic notions - audio bit depth
Bit depth = number of bits in each sample
Common bit depths● 8 bit (signed/unsigned)● 16 bit (signed) - CD quality● 32 bit integer (signed)● 32 bit float (values ranging from -1 to 1)
Greater bit depth -> better sound quality -> more space needed
![Page 6: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/6.jpg)
Example - portaudio (init/terminate)
Tipical portaudio usage:
Pa_Initialize();
...DoMyPortaudioSoundOperations();...
Pa_Terminate();
hg clone http://minvg.hg.sourceforge.net:8000/hgroot/minvg; cd minvg/trunk/PortaudioSoundPlayer
![Page 7: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/7.jpg)
Example - portaudio init/close stream
In portaudio, the stream is the primitive for sound processing Pa_Open(Default)Stream( .... );
Pa_CloseStream(createdStream);
hg clone http://minvg.hg.sourceforge.net:8000/hgroot/minvg; cd minvg/trunk/PortaudioSoundPlayer
![Page 8: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/8.jpg)
Example - portaudio stream parameters
The stream creation function receives the following parameters:
● number of Input/Output channels● sample rate, bit depth● processing callback and callback buffer size● user data that can be passed to the callback
hg clone http://minvg.hg.sourceforge.net:8000/hgroot/minvg; cd minvg/trunk/PortaudioSoundPlayer
![Page 9: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/9.jpg)
Example - portaudio callback
The callback is (asynchronously!) called periodically when: ● new input data arrived (when recording)● new output data requested
int Callback(const void *input, void *output, ... );
Return values: ● paComplete - to end playing/recording after this call● paContinue - to continue playing/recording● paAbort - to end playing/recording ASAP
hg clone http://minvg.hg.sourceforge.net:8000/hgroot/minvg; cd minvg/trunk/PortaudioSoundPlayer
![Page 10: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/10.jpg)
Other audio libraries
●RtAudio○ similar to portaudio (callback mechanism)○ object oriented design (C++)
●libsdl (audio component)○ similar to portaudio (callback mechanism)○ game development oriented
●OpenAL○ API similar to OpenGL○ higher level interface (compared to portaudio)○ game development oriented
![Page 11: Basic audio programming](https://reader036.fdocuments.net/reader036/viewer/2022083000/556946d8d8b42a2c788b5049/html5/thumbnails/11.jpg)
ReferencesBasic information http://en.wikipedia.org/wiki/Sample_%28signal%2 http://www.tweakheadz.com/16_vs_24_bit_audio.htm http://en.wikipedia.org/wiki/Sampling_rate http://en.wikipedia.org/wiki/Audio_bit_depth
Audio libraries http://www.music.mcgill.ca/~gary/rtaudio/ http://connect.creativelabs.com/openal http://www.portaudio.com/ http://www.libsdl.org/ General information http://www.dspguide.com/