Tutorial: Sending sound to the loudspeakers

This tutorial explains how to send sound to NAO's loudspeakers.

Note:

This tutorial is written in C++. All the examples described below are included in the example source code provided with the SDK in "modules/src/examples/mysendingsoundmodule". This example sends the content of a wav file from a remote desktop onto the nao's loudspeakers

Creating a proxy on the module

Before to access to the ALAudioDevice module, create first a proxy on it.

// Create a proxy on the ALAudioDevice module AL::ALPtr<AL::ALProxy> audioDeviceProxy = getParentBroker()->getProxy( "ALAudioDevice" );

Sending sound to the loudspeakers

You can send sound to the loudspeakers with the sendLocalBufferToOutput or sendRemoteBufferToOutput functions, depending whether your module is local or remote.

  • If your module is local, you must pass to the sendLocalBufferToOutput function a pointer to the buffer to send (that you have to cast to an integer), and the number of frames per channel. The buffer must contain 16bits stereo interleaved samples.

    // Example: send a buffer containing 16384 16 bits stereo samples from a local module onto the loudspeakers int NbOfFrames=16384; // maximum buffer size that ALAudioDevice can send int NbOfChannels=2; short *pDataShort = new short [NbOfFrames*NbOfChannels]; // put samples in your buffer here audioDeviceProxy->call <bool> ("sendLocalBufferToOutput",NbOfFrames,(int) pDataShort);

    Note: The sample rate of the AudioDevice output can be adjust with the setParameter function. If your buffer is sampled at 44100Hz, you can set the sample rate as below:

    audioDeviceProxy->callVoid ( "setParameter",std::string( "outputSampleRate" ),44100 );

    The synthesis provided by Aldebaran runs at 16000 Hz or 22050 Hz (depending of the language). So, if you want to use the synthesis and send your owns buffers at same time, you need to send buffers sampled at the same frequency that the ALTextToSpeech module.
  • If your module is remote, the sendRemoteBufferToOutput function needs your buffer (in an AlValue converted to binary), and the number of frames per channel. The buffer must contain 16bit stereo interleaved samples.

    // Example: send a buffer containing 16384 16 bits stereo samples from a remote module onto the loudspeakers int NbOfFrames=16384; // maximum buffer size that ALAudioDevice can send int NbOfChannels=2; short *pDataShort = new short [NbOfFrames*NbOfChannels]; // put samples in your buffer here ALValue pDataBin; pDataBin.SetBinary( pDataShort, NbOfFrames*sizeof(short)*NbOfChannels ); audioDeviceProxy->call <bool> ("sendRemoteBufferToOutput",NbOfFrames,pDataBin);





Copyright © 2010 Aldebaran-Robotics - All rights reserved