00001 /* 00002 * Copyright (c) 2001-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 "AudioOut.hxx" 00023 #include "AudioManager.hxx" 00024 #include "ProcessingFactory.hxx" 00025 00026 00027 00028 namespace CLAM 00029 { 00030 00031 namespace Hidden 00032 { 00033 static const char * metadata[] = { 00034 "key", "AudioOut", 00035 // "category", "Audio I/O", 00036 // "description", "AudioOut", 00037 0 00038 }; 00039 static FactoryRegistrator<ProcessingFactory, AudioOut> reg = metadata; 00040 } 00041 00042 AudioOut::AudioOut() 00043 : mInput( "Audio Input", this ) 00044 { 00045 mpDevice = 0; 00046 Configure(AudioIOConfig()); 00047 } 00048 00049 AudioOut::AudioOut(const AudioIOConfig &c) 00050 : mInput( "Audio Input", this ) 00051 { 00052 mpDevice = 0; 00053 Configure(c); 00054 } 00055 00056 AudioOut::~AudioOut() 00057 { 00058 try { 00059 if (mpDevice) 00060 mpDevice->Unregister(*this); 00061 } 00062 catch (Err &e) { 00063 std::cerr << "AudioOut::~AudioOut: unregistering processing: " << e.what() << std::endl; 00064 } 00065 } 00066 00067 bool AudioOut::ConcreteConfigure(const ProcessingConfig& c) 00068 throw(ErrProcessingObj) 00069 { 00070 CopyAsConcreteConfig(mConfig, c); 00071 00072 if (mpDevice) 00073 mpDevice->Unregister(*this); 00074 00075 AudioManager *m; 00076 00077 try { 00078 m = &(AudioManager::Current()); 00079 } 00080 catch (Err &e) { 00081 ErrProcessingObj ne("AudioOut::ConcreteConfigure(): No AudioManager found.",this); 00082 ne.Embed(e); 00083 throw(ne); 00084 } 00085 00086 bool res; 00087 try { 00088 res = m->Register(*this); 00089 } 00090 catch (Err &e) { 00091 AddConfigErrorMessage( e.what() ); 00092 res = false; 00093 } 00094 00095 if (res == false) 00096 AddConfigErrorMessage( "AudioOut::ConcreteConfigure(): " 00097 "Failed to register in AudioManager.") ; 00098 00099 mInput.SetSize(mConfig.GetFrameSize()); 00100 return res; 00101 } 00102 00103 bool AudioOut::ConcreteStart(void) 00104 { 00105 if (!mpDevice) 00106 throw Err("AudioOut::ConcreteStart(): No Device found!"); 00107 try 00108 { 00109 mpDevice->Start(); 00110 } 00111 catch (Err &e) { 00112 std::cerr << " AudioOut::ConcreteStart(): could not start audio device: maybe another program is blocking it" << std::endl; 00113 std::cerr << " Received error message: <"<<e.what() << std::endl; 00114 } 00115 return true; 00116 } 00117 00118 bool AudioOut::ConcreteStop() 00119 { 00120 mpDevice->Stop(); 00121 return true; 00122 } 00123 00124 void AudioOut::GetDeviceInfo(AudioDevice::TInfo &info) const 00125 { 00126 if (mpDevice) 00127 mpDevice->GetInfo(info); 00128 else 00129 info.Reset(); 00130 } 00131 00132 bool AudioOut::Do() 00133 { 00134 bool res = Do(mInput.GetAudio()); 00135 mInput.Consume();; 00136 return res; 00137 } 00138 00139 } 00140