PAAudioInputStream.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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(&params, 0, mConfig.GetSampleRate()) ? false : true);
00073 
00074                 // Requested sample rate is not supported
00075                 if ( !isSupported ) 
00076                         throw ErrPortAudio( "Error opening the stream:\nRequested Sample rate not supported by the device" );
00077 
00078                 // These ones are asserts
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 

Generated on Tue Aug 12 22:33:43 2008 for CLAM by  doxygen 1.5.5