libalaudio  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
alsoundextractor.cpp
Go to the documentation of this file.
1 
8 #include <alproxies/almemoryproxy.h>
9 #include <alcommon/alproxy.h>
10 #include <alcommon/albroker.h>
11 #include <iostream>
12 
13 namespace AL
14 {
15 
16 ALSoundExtractor::ALSoundExtractor(boost::shared_ptr<ALBroker> pBroker,
17  std::string pName)
18  : ALExtractor(pBroker, pName)
19  , fIsRunning(false)
20  , fbDebugMode(false)
21  , audioDevice()
22 {
23  functionName("setDebugMode",
24  "ALSoundExtractor",
25  "enable/disable the printing of some debug information");
26  addParam("bSetOrUnset",
27  "enable the functionnality when true.");
28  BIND_METHOD(ALSoundExtractor::setDebugMode);
29 
30  functionName("processRemote",
31  "ALSoundExtractor",
32  "enable/disable the printing of some debug information");
33  addParam("nbOfChannels",
34  "Provides the number of channels of the buffer.");
35  addParam("nbOfSamplesByChannel",
36  "Provides the number of samples by channel.");
37  addParam("timestamp",
38  "Provides the timestamp of the buffer.");
39  addParam("buffer",
40  "Provides the audio buffer as an ALValue.");
41  BIND_METHOD(ALSoundExtractor::processRemote);
42 
43  functionName("processSoundRemote",
44  "ALSoundExtractor",
45  "enable/disable the printing of some debug information");
46  addParam("nbOfChannels",
47  "Provides the number of channels of the buffer.");
48  addParam("nbOfSamplesByChannel",
49  "Provides the number of samples by channel.");
50  addParam("buffer",
51  "Provides the audio buffer as an ALValue.");
53 
54 
55  try
56  {
57  audioDevice = getParentBroker()->getProxy("ALAudioDevice");
58  }
59  catch(const ALError& e)
60  {
61  qiLogWarning("audio.alsoundextractor") << e.what()
62  << " Sound capture will not work.";
63  }
64 
65  fNullTimestamp.arrayReserve(2);
66  fNullTimestamp.arrayPush(0);
67  fNullTimestamp.arrayPush(0);
68 }
69 
71 {
72  stopDetection();
73 }
74 
76 {
77  if(!fIsRunning)
78  {
79  qiLogVerbose("audio.alsoundextractor", "ALSoundExtractor : startDetection");
80  try
81  {
82  if(!audioDevice)
83  audioDevice = getParentBroker()->getProxy("ALAudioDevice");
84  audioDevice->callVoid("subscribe", this->getName());
85  }
86  catch(ALError & error)
87  {
88  fIsRunning = false;
89  throw ALError(getName(), "startDetection", error.what());
90  }
91 
92  fIsRunning = true;
93  }
94 }
95 
97 {
98  if(fIsRunning)
99  {
100  qiLogVerbose("audio.alsoundextractor", "ALSoundExtractor : stopDetection");
101  fIsRunning = false;
102  audioDevice->callVoid("unsubscribe", this->getName());
103  }
104 }
105 
106 void ALSoundExtractor::process(const int & nbOfChannels,
107  const int & nbrOfSamplesByChannel,
108  const AL_SOUND_FORMAT * buffer,
109  const ALValue & timestamp)
110 {
111  /* Since ALAudioDevice CLient is only calling the process method,
112  * we call the deprecated method processSound here.
113  */
114 
115  processSound(nbOfChannels, nbrOfSamplesByChannel, buffer);
116 }
117 
118 void ALSoundExtractor::processSound(const int pNbOfInputChannels,
119  const int pNbrSamples,
120  const AL_SOUND_FORMAT * bBuffer)
121 {
122 }
123 
124 void ALSoundExtractor::processSoundRemote(const int & pNbOfInputChannels,
125  const int & pNbrSamples,
126  const ALValue & pBuffer)
127 {
128 }
129 
130 
131 void ALSoundExtractor::processRemote(const int & pNbOfInputChannels,
132  const int & pNbrSamples,
133  const ALValue & timestamp,
134  const ALValue & buffer)
135 {
136  process(pNbOfInputChannels,
137  pNbrSamples,
138  (const AL_SOUND_FORMAT *)buffer.GetBinary(),
139  timestamp);
140 
141  processSoundRemote(pNbOfInputChannels,
142  pNbrSamples,
143  (const AL_SOUND_FORMAT *)buffer.GetBinary());
144 }
145 
146 std::vector<std::string> ALSoundExtractor::getOutputNames(void)
147 {
148  return getParentBroker()->getProxy("ALMemory")->
149  call<std::vector<std::string> >("getExtractorEvent", getName());
150 }
151 
152 } // namespace AL
signed short AL_SOUND_FORMAT
virtual QI_API_DEPRECATED void processSound(const int nbOfChannels, const int nbrOfSamplesByChannel, const AL_SOUND_FORMAT *buffer)
virtual void startDetection(void)
ALSoundExtractor(boost::shared_ptr< AL::ALBroker > pBroker, std::string pName)
QI_API_DEPRECATED void setDebugMode(const bool &pbSetOrUnset=true)
virtual void process(const int &nbOfChannels, const int &nbrOfSamplesByChannel, const AL_SOUND_FORMAT *buffer, const ALValue &timestamp)
boost::shared_ptr< ALProxy > audioDevice
virtual void stopDetection(void)
virtual QI_API_DEPRECATED void processSoundRemote(const int &nbOfChannels, const int &nbrOfSamplesByChannel, const ALValue &buffer)