Basic audio programming
-
Upload
iulian-nicu-serbanoiu -
Category
Technology
-
view
167 -
download
1
description
Transcript of Basic audio programming
Basic audio programming
Iulian Şerbănoiu - March 2010
Contents
●Basic notions○ Sample ○ Sample rate○ Audio bit depth
●Example○ portaudio
●Other audio libraries●References
Basic notions - sample
Each square ( <fi> i=1..12 ) represents a sample
Basic notions - sample rate
Sample rate = number of samples in a secondgreater T -> smaller sample rate -> lower qualitysmaller T -> greater sample rate -> higher quality
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
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
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
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
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
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
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/