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 "PAAudioFullDuplexStream.hxx"
00024 #include "PortAudioUtils.hxx"
00025 #include "Assert.hxx"
00026
00027 namespace CLAM
00028 {
00029
00030 void PAAudioFullDuplexStream::SetupStream()
00031 {
00032 PaError errval;
00033
00034 CheckConsistency();
00035
00036 PaStreamParameters in_stream_params;
00037 in_stream_params.device = mConfig.GetDeviceID();
00038 in_stream_params.channelCount = mConfig.GetChannelNumber();
00039 in_stream_params.sampleFormat = paInt16;
00040 in_stream_params.suggestedLatency = Pa_GetDeviceInfo(in_stream_params.device)->defaultLowInputLatency;
00041 in_stream_params.hostApiSpecificStreamInfo = NULL;
00042
00043 PaStreamParameters out_stream_params;
00044 out_stream_params.device = mConfig.GetDeviceID();
00045 out_stream_params.channelCount = mConfig.GetChannelNumber();
00046 out_stream_params.sampleFormat = paInt16;
00047 out_stream_params.suggestedLatency = Pa_GetDeviceInfo(out_stream_params.device)->defaultLowOutputLatency;
00048 out_stream_params.hostApiSpecificStreamInfo = NULL;
00049
00050 errval = Pa_OpenStream(
00051 &mStream,
00052 &in_stream_params,
00053 &out_stream_params,
00054 mConfig.GetSampleRate(),
00055 mConfig.GetDblBuffer()->GetSize()/mConfig.GetChannelNumber(),
00056 0,
00057 mConfig.GetCallback(),
00058 mConfig.GetDblBuffer() );
00059
00060 CHECK_PA_ERROR( "Error opening the stream: ", errval );
00061 }
00062
00063 void PAAudioFullDuplexStream::CheckConsistency()
00064 {
00065 const PaDeviceInfo* devnfo = Pa_GetDeviceInfo( mConfig.GetDeviceID() );
00066
00067 if ( devnfo == NULL )
00068 throw ErrPortAudio("Error opening stream\nThe device id is not valid");
00069
00070 PaStreamParameters params;
00071 params.device = mConfig.GetDeviceID();
00072 params.channelCount = mConfig.GetChannelNumber();
00073 params.sampleFormat = paInt16;
00074 params.suggestedLatency = 0;
00075 params.hostApiSpecificStreamInfo = 0;
00076
00077 bool isSupported = (Pa_IsFormatSupported(¶ms, ¶ms, mConfig.GetSampleRate()) ? false : true);
00078
00079
00080 if ( !isSupported )
00081 throw ErrPortAudio( "Error opening the stream:\nRequested Sample rate not supported by the device" );
00082
00083
00084 CLAM_ASSERT( mConfig.GetDblBuffer()!=NULL, "The double buffer for the stream cannot be nil!" );
00085 CLAM_ASSERT( mConfig.GetCallback()!=NULL, "The callback for the stream is nil!" );
00086 }
00087
00088 }
00089