libalaudio
2.0.6.8
|
00001 00007 #include <alaudio/alsoundextractor.h> 00008 #include <alproxies/almemoryproxy.h> 00009 #include <alcommon/alproxy.h> 00010 #include <alcommon/albroker.h> 00011 #include <iostream> 00012 00013 namespace AL 00014 { 00015 00016 ALSoundExtractor::ALSoundExtractor(boost::shared_ptr<ALBroker> pBroker, 00017 std::string pName) 00018 : ALExtractor(pBroker, pName) 00019 , fIsRunning(false) 00020 , fbDebugMode(false) 00021 , audioDevice() 00022 { 00023 functionName("setDebugMode", 00024 "ALSoundExtractor", 00025 "enable/disable the printing of some debug information"); 00026 addParam("bSetOrUnset", 00027 "enable the functionnality when true."); 00028 BIND_METHOD(ALSoundExtractor::setDebugMode); 00029 00030 functionName("processRemote", 00031 "ALSoundExtractor", 00032 "enable/disable the printing of some debug information"); 00033 addParam("nbOfChannels", 00034 "Provides the number of channels of the buffer."); 00035 addParam("nbOfSamplesByChannel", 00036 "Provides the number of samples by channel."); 00037 addParam("timestamp", 00038 "Provides the timestamp of the buffer."); 00039 addParam("buffer", 00040 "Provides the audio buffer as an ALValue."); 00041 BIND_METHOD(ALSoundExtractor::processRemote); 00042 00043 functionName("processSoundRemote", 00044 "ALSoundExtractor", 00045 "enable/disable the printing of some debug information"); 00046 addParam("nbOfChannels", 00047 "Provides the number of channels of the buffer."); 00048 addParam("nbOfSamplesByChannel", 00049 "Provides the number of samples by channel."); 00050 addParam("buffer", 00051 "Provides the audio buffer as an ALValue."); 00052 BIND_METHOD(ALSoundExtractor::processSoundRemote); 00053 00054 00055 try 00056 { 00057 audioDevice = getParentBroker()->getProxy("ALAudioDevice"); 00058 } 00059 catch(const ALError& e) 00060 { 00061 qiLogWarning("audio.alsoundextractor") << e.what() 00062 << " Sound capture will not work."; 00063 } 00064 00065 fNullTimestamp.arrayReserve(2); 00066 fNullTimestamp.arrayPush(0); 00067 fNullTimestamp.arrayPush(0); 00068 } 00069 00070 ALSoundExtractor::~ALSoundExtractor() 00071 { 00072 stopDetection(); 00073 } 00074 00075 void ALSoundExtractor::startDetection() 00076 { 00077 if(!fIsRunning) 00078 { 00079 qiLogVerbose("audio.alsoundextractor", "ALSoundExtractor : startDetection"); 00080 try 00081 { 00082 if(!audioDevice) 00083 audioDevice = getParentBroker()->getProxy("ALAudioDevice"); 00084 audioDevice->callVoid("subscribe", this->getName()); 00085 } 00086 catch(ALError & error) 00087 { 00088 fIsRunning = false; 00089 throw ALError(getName(), "startDetection", error.what()); 00090 } 00091 00092 fIsRunning = true; 00093 } 00094 } 00095 00096 void ALSoundExtractor::stopDetection() 00097 { 00098 if(fIsRunning) 00099 { 00100 qiLogVerbose("audio.alsoundextractor", "ALSoundExtractor : stopDetection"); 00101 fIsRunning = false; 00102 audioDevice->callVoid("unsubscribe", this->getName()); 00103 } 00104 } 00105 00106 void ALSoundExtractor::process(const int & nbOfChannels, 00107 const int & nbrOfSamplesByChannel, 00108 const AL_SOUND_FORMAT * buffer, 00109 const ALValue & timestamp) 00110 { 00111 /* Since ALAudioDevice CLient is only calling the process method, 00112 * we call the deprecated method processSound here. 00113 */ 00114 00115 processSound(nbOfChannels, nbrOfSamplesByChannel, buffer); 00116 } 00117 00118 void ALSoundExtractor::processSound(const int pNbOfInputChannels, 00119 const int pNbrSamples, 00120 const AL_SOUND_FORMAT * bBuffer) 00121 { 00122 } 00123 00124 void ALSoundExtractor::processSoundRemote(const int & pNbOfInputChannels, 00125 const int & pNbrSamples, 00126 const ALValue & pBuffer) 00127 { 00128 } 00129 00130 00131 void ALSoundExtractor::processRemote(const int & pNbOfInputChannels, 00132 const int & pNbrSamples, 00133 const ALValue & timestamp, 00134 const ALValue & buffer) 00135 { 00136 process(pNbOfInputChannels, 00137 pNbrSamples, 00138 (const AL_SOUND_FORMAT *)buffer.GetBinary(), 00139 timestamp); 00140 00141 processSoundRemote(pNbOfInputChannels, 00142 pNbrSamples, 00143 (const AL_SOUND_FORMAT *)buffer.GetBinary()); 00144 } 00145 00146 std::vector<std::string> ALSoundExtractor::getOutputNames(void) 00147 { 00148 return getParentBroker()->getProxy("ALMemory")-> 00149 call<std::vector<std::string> >("getExtractorEvent", getName()); 00150 } 00151 00152 } // namespace AL