PAAudioOutputStream.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 "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         //      CheckConsistency();
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                 // MRJ: Let's check if the capabilities of the selected
00064                 // device meet the requirements expressed in the stream
00065                 // configuration object
00066 
00067                 // I don't like much this but I don't see clearly the
00068                 // utility of using CLAM_ASSERT's beyond saving me
00069                 // of typing the conditionals...
00070 
00071                 // Check number of channels
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                 // Check the sample rate. Let's determine wether
00076                 // the requested sample rate is supported
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                 // Requested sample rate is not supported
00089                 if ( !isSupported ) 
00090                         throw ErrPortAudio( "Error opening the stream:\nRequested Sample rate not supported by the device" );
00091 
00092                 // These ones are asserts
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 

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