Tutorial: Accessing sound data of NAO's microphones

This tutorial explains how to write a module which can access the sound data of the NAO's microphones, and how to process this signal.

Note:

This tutorial is written in C++. All the examples described in this tutorial are included in the example source code provided with the SDK in "modules/src/examples/mysoundprocessingmodule"

Creating your module

To access the data collected by microphones, you need to create a module which inherits from the ALSoundExtractor class

Declaration of the function which allows to access the data collected by the nao's microphones

To access the sound data collected by nao's microphones, you must declare a callBack function called "processSound" or "processSoundRemote" depending on whether your module is local (compiled as a dynamic library) or remote (compiled as an executable). If your module is remote, you also need to bind this method. This function is called by the AudioDevice module and the buffer containing the sound data of the microphones is then regularly sent to this method.

// 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 it // 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 it // 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 // }

As mentioned above, for a remote module, you must bind the "processSoundRemote" method in the constructor of your class.

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)

Launching of the processing

As your module inherits from the ALSoundExtractor class, to launch the processing you need to call its subscribe() method





Copyright © 2010 Aldebaran-Robotics - All rights reserved