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 #ifndef __PAAUDIOSTREAM__ 00023 #define __PAAUDIOSTREAM__ 00024 00025 #include <portaudio.h> 00026 #include "PortAudioUtils.hxx" 00027 #include "DoubleBuffer.hxx" 00028 00029 namespace CLAM 00030 { 00031 00032 class PAAudioStreamConfig 00033 { 00034 public: 00035 00036 PAAudioStreamConfig() 00037 : mSampleRate( 44100 ), mNChannels(2), 00038 mCallback( NULL ) 00039 { 00040 } 00041 00042 ~PAAudioStreamConfig() 00043 { 00044 } 00045 00046 inline void SetSampleRate( unsigned srate ) 00047 { 00048 mSampleRate = srate; 00049 } 00050 00051 inline unsigned GetSampleRate() const 00052 { 00053 return mSampleRate; 00054 } 00055 00056 inline void SetChannelNumber( unsigned char nchann ) 00057 { 00058 mNChannels = nchann; 00059 } 00060 00061 inline unsigned char GetChannelNumber() const 00062 { 00063 return mNChannels; 00064 } 00065 00066 inline void SetCallback( PortAudioCallback cb ) 00067 { 00068 mCallback = cb; 00069 } 00070 00071 inline PortAudioCallback GetCallback( ) const 00072 { 00073 return mCallback; 00074 } 00075 00076 inline void SetInputDblBuffer( DoubleBuffer* buffer ) 00077 { 00078 mBuffer.mInputDblBuff = buffer; 00079 } 00080 00081 inline DoubleBuffer* GetInputDblBuffer() 00082 { 00083 return mBuffer.mInputDblBuff; 00084 } 00085 00086 inline void SetOutputDblBuffer( DoubleBuffer* buffer ) 00087 { 00088 mBuffer.mOutputDblBuff = buffer; 00089 } 00090 00091 inline DoubleBuffer* GetOutputDblBuffer() 00092 { 00093 return mBuffer.mOutputDblBuff; 00094 } 00095 00096 inline FullDuplexDoubleBuffer* GetDblBuffer() 00097 { 00098 return &mBuffer; 00099 } 00100 00101 inline void SetDeviceID( PaDeviceIndex devID ) 00102 { 00103 mDevID = devID; 00104 } 00105 00106 inline PaDeviceIndex GetDeviceID( ) const 00107 { 00108 return mDevID; 00109 } 00110 00111 private: 00112 00113 unsigned mSampleRate; 00114 unsigned char mNChannels; 00115 PaDeviceIndex mDevID; 00116 PortAudioCallback mCallback; 00117 FullDuplexDoubleBuffer mBuffer; 00118 00119 }; 00120 00121 class PAAudioStream 00122 { 00123 public: 00124 00125 PAAudioStream( PAAudioStreamConfig& ); 00126 00127 void Start(); 00128 00129 void Stop(); 00130 00131 ~PAAudioStream(); 00132 00133 protected: 00134 00135 virtual void SetupStream() = 0; 00136 00137 00138 PAAudioStreamConfig mConfig; 00139 PaStream* mStream; 00140 }; 00141 00142 } 00143 00144 #endif 00145