PAAudioFullDuplexStream.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 "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(&params, &params, mConfig.GetSampleRate()) ? false : true);
00078 
00079                 // Requested sample rate is not supported
00080                 if ( !isSupported ) 
00081                         throw ErrPortAudio( "Error opening the stream:\nRequested Sample rate not supported by the device" );
00082 
00083                 // These ones are asserts
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 

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