00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <portaudio.h>
00023 #include "PAAudioOutputStream.hxx"
00024 #include "PortAudioUtils.hxx"
00025 #include "Assert.hxx"
00026
00027 namespace CLAM
00028 {
00029
00030 void PAAudioOutputStream::SetupStream()
00031 {
00032 PaError errval;
00033
00034
00035
00036 errval = Pa_OpenStream(
00037 &mStream,
00038 paNoDevice,
00039 0,
00040 paInt16,
00041 NULL,
00042 mConfig.GetDeviceID(),
00043 mConfig.GetChannelNumber(),
00044 paInt16,
00045 NULL,
00046 mConfig.GetSampleRate(),
00047 mConfig.GetOutputDblBuffer()->GetSize()/mConfig.GetChannelNumber(),
00048 0,
00049 0,
00050 mConfig.GetCallback(),
00051 mConfig.GetOutputDblBuffer() );
00052
00053 CHECK_PA_ERROR( "Error opening the stream: ", errval );
00054 }
00055
00056 void PAAudioOutputStream::CheckConsistency()
00057 {
00058 const PaDeviceInfo* devnfo = Pa_GetDeviceInfo( mConfig.GetDeviceID() );
00059
00060 if ( devnfo == NULL )
00061 throw ErrPortAudio("Error opening stream\nThe device id is not valid");
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 if ( mConfig.GetChannelNumber() > devnfo->maxOutputChannels )
00073 throw ErrPortAudio("Error opening the stream:\nNumber of output channels requested is not supported by the device\n" );
00074
00075
00076
00077
00078 unsigned supportedSr;
00079 bool isSupported = false;
00080
00081 for ( int k = devnfo->numSampleRates - 1; k >= 0; k-- )
00082 {
00083 supportedSr = (unsigned)devnfo->sampleRates[k];
00084 if ( mConfig.GetSampleRate() == supportedSr )
00085 isSupported = true;
00086 }
00087
00088
00089 if ( !isSupported )
00090 throw ErrPortAudio( "Error opening the stream:\nRequested Sample rate not supported by the device" );
00091
00092
00093 CLAM_ASSERT( mConfig.GetDblBuffer()!=NULL, "The double buffer for the stream cannot be nil!" );
00094 CLAM_ASSERT( mConfig.GetCallback()!=NULL, "The callback for the stream is nil!" );
00095 }
00096
00097 }
00098