使用指导:访问NAO (脑) 扩音器的声音数据
本指导介绍如何编写可以访问NAO扩音器声音数据的模块,以及如何处理信号。
注释: |
本指导使用C++语言编写。所有范例都包含随SDK提供的范例源代码中:"modules/src/examples/audio" |
---|
创建模块
要访问由扩音器收集的数据,您需要创建一个从ALSoundExtractor类继承的模块。
声明函数,以便访问由NAO扩音器收集的数据
要访问扩音器收集的声音数据时,您必须声明一个回调函数。根据模块类型,即本地(作为动态库编译)或远程(remote,作为可执行档编译),选择"processSound"或"processSoundRemote"。 如果您的模块为远程模块,还需绑定该方法。 这个函数由AudioDevice模块调用。包含扩音器声音数据的缓冲区会被定期发送至该方法。
// Example for a local module (dynamic library) : void MyModule::processSound( const int pNbOfInputChannels, const int pNbrSamples, const signed short *pDataInterleaved) { // pNbOfInputChannels is the number of channels contained in the input buffer (actual value : 4) // pNbrSamples is the number of samples per channel // pDataInterleaved is a pointer to the buffer containing the samples. The buffer contained 16 bits interleaved samples, that's to say that he // contains s1m1,s1m2,s1m3,s1m4,s2m1,s2m2, ... where simj is the sample number i of microphone j // The order of microphones is as follow : 1 : left microphone / 2 : right microphone / 3 : front microphone / 4 : rear microphone // Make your signal processing here // Note : An example of how to desinterleave samples is provided in the example source code }
// Example for a remote module (executable) : void MyModule::processSoundRemote( const int &pNbOfInputChannels, const int &pNbrSamples, const AL::ALValue &pDataInterleaved) { // pNbOfInputChannels is the number of channels contained in the input buffer (actual value : 4) // pNbrSamples is the number of samples per channel // pDataInterleaved is a pointer to the buffer containing the samples. The buffer contained 16 bits interleaved samples, that's to say that he // contains s1m1,s1m2,s1m3,s1m4,s2m1,s2m2, ... where simj is the sample number i of microphone j // The order of microphones is as follow : 1 : left microphone / 2 : right microphone / 3 : front microphone / 4 : rear microphone // Make your signal processing here // Note : An example of how to desinterleave samples is provided in the example source code // }
如上所述,对于远程模块,您必须在类的构造函数里绑定"processSoundRemote"这一方法。
functionName("processSoundRemote", getName(), "processSoundRemote"); addParam("pNbOfInputChannels", "Number of input channels"); addParam("pNbrSamples", "Number of samples per channel"); addParam("pDataInterleaved", "buffer containing the samples"); BIND_METHOD(MyModule::processSoundRemote)
运行处理过程
由于您的模块继承自ALSoundExtractor类,因此您需要调用其subscribe()方法来运行处理过程。