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