Overview

The ALAudioDevice module allows other modules to access to the sound data of the nao's microphones, and to send sound toward its loudspeakers The way to receive or send the audio data depends whether the modules are local (dynamic library) or remote (executable).

Methods

bool subscribeLocalModule (const N2AL5ALPtrINS_16ALSoundExtractorEEE& pModule)

This function allows a local module which inherits from the ALSoundExtractor class to subscribe to the ALAudioDevice module. Once your local module is subscribed, the function 'processSound' of your module (you need to declare one) will be automatically and regularly called with raw data from microphones as inputs.
This function must be declared as follows: processSound( const int & pNbOfInputChannels, const int & pNbrSamples, const AL_SOUND_FORMAT * pDataInterleaved).
As for remote modules, when this function will be called, the received pDataInterleaved buffer will contain pNbrSamples 16 bits interleaved samples, ordered as follows : s1m1,s1m2,s1m3,s1m4,s2m1,s2m2, ... where simj is the sample number i of microphone j.
The indices of microphones are the followings : 1 : left microphone / 2 : right microphone / 3 : front microphone / 4 : rear microphone.
For more informations see the audio part of the red documentation

pModule

Smart pointer on the module

Returns

True if the module has subscribed successfully - False otherwise

Example in C++ :

#Subscribes a local module to the ALAudioDeviceModule
ALPtr<ALProxy> AudioDevice=getParentBroker()->getProxy( "ALAudioDevice" );
audioDevice->call <bool> ("subscribeLocalModule", getThis());;

bool unSubscribeLocalModule (const N2AL5ALPtrINS_16ALSoundExtractorEEE& pModule)

This function unsuscribes a local module from the ALAudioDevice module

pModule

Smart pointer on the module

Returns

True if the module has unsubscribed successfully - False otherwise

Example in C++ :

#Unsubscribes a local module to the ALAudioDeviceModule
ALPtr<ALProxy> AudioDevice=getParentBroker()->getProxy( "ALAudioDevice" );
audioDevice->call <bool> ("unSubscribeLocalModule",getThis());

bool subscribeRemoteModule (const string& pModule)

This function allows a remote module to subscribe to the ALAudioDevice module.
Once your remote module is subscribed, the function 'processSoundRemote' of your module (you need to declare one) will be automatically and regularly called with raw data from microphones as inputs.
This function must be declared as follow : processSoundRemote( const int &#38; pNbOfInputChannels, const int &#38; pNbrSamples, const ALValue &#38; pDataInterleaved).
When she will be called, the received pDataInterleaved buffer will contain pNbrSamples 16 bits interleaved samples, ordered as follows : s1m1,s1m2,s1m3,s1m4,s2m1,s2m2, ... where simj is the sample number i of microphone j.
The indices of microphones are the followings : 1 : left microphone / 2 : right microphone / 3 : front microphone / 4 : rear microphone.
For more informations see the audio part of the red documentation

pModule

Name of the remote module

Returns

True if module has subscribed successfully - False otherwise

Example in C++ :

#Subscribes a module to the ALAudioDeviceModule
ALPtr<ALProxy> AudioDevice=getParentBroker()->getProxy("ALAudioDevice");
AudioDevice->call <bool> ("subscribeRemoteModule",getName());

bool unSubscribeRemoteModule (const string& pModule)

This function unsubscribes a remote module (identified by its name) from the ALAudioDevice module

pModule

Name of the remote module to unsuscribe from ALAudioDevice

Returns

True if module has been unsubscribed successfully - False otherwise

Example in C++ :

#Unsubscribes a module from the ALAudioDevice Module
ALPtr<ALProxy> AudioDevice=getParentBroker()->getProxy("ALAudioDevice");
AudioDevice->call <bool> ("unSubscribeRemoteModule",getName());

bool sendLocalBufferToOutput (const int& nbOfFrames, const int& pBuffer)

This function allows a local module to send sound onto the nao's loudpseakers
You must pass to this function a pointer to the stereo buffer to send, and the number of frames per channel. The buffer must contain 16bits stereo interleaved samples, and the number of frames does not exceed 16384

nbOfFrames

Number of 16 bits samples per channel to send.

pBuffer

Buffer to send

Returns

True if the operation is successfull - False otherwise

Example in C++ :

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

bool sendRemoteBufferToOutput (const int& nbOfFrames, const AL::ALValue& pBuffer)

This function allows a remote module to send sound onto the nao's loudpseakers
You must pass to this function the stereo buffer you want to send as an ALValue converted to binary, and the number of frames per channel. The number of frames does not exceed 16384. For more information please see the red documentation

nbOfFrames

Number of 16 bits samples per channel to send.

pBuffer

Buffer to send

Returns

True if the operation is successfull - False otherwise

Example in C++ :

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

void setFileAsInput (const string& pFileName)

This method allows to send sound samples contained in a sound file at the input of ALAudioDevice, instead of the nao's microphones sound data The sound file must be a .wav file containing 16bits / 4 channels / interleaved samples. Once the file has been read, microphones sound data will again taken as input

pFileName

Name of the input file.

void setParameter (const string& pParamName, const int& pParamValue)

This method sets the specified internal parameter ('outputSampleRate' or 'inputBufferSize')
inputBufferSize can bet set to 8192 or 16384. Warning: when speech recognition is running, a buffer size of 8192 is used. Don't change it during the recognition process.
outputSampleRate can bet set to 16000 Hz, 22050 Hz, 44100 Hz or 48000 Hz. Warning: if speech synthesis is running, a sample rate of 16000 Hz or 22050 Hz is used (depending of the language). Don't change it during the synthesis process

pParamName

Name of the parameter to set ('outputSampleRate' or 'inputBufferSize').

pParamValue

The value to which the specified parameter should be set.

int getParameter (const string& pParamName)

This method returns the specified internal parameter ('outputSampleRate' or 'inputBufferSize'). The value -1 is returned if the specified parameter is not valid.

pParamName

Name of the parameter to get ('outputSampleRate' or 'inputBufferSize').

Returns

value of the specified parameter

void startMicrophonesRecording (const string& pFileName)

This method allows to record the signal collected on the nao's microphones. You can choose to record only the front microphone in a ogg file, or the 4 microphones in a wav file. In this last case the format of the file is 4 channels, 16 bits little endian, 48 KHz

pFileName

Name of the file where to record the sound.

void stopMicrophonesRecording ()

This method stops the recording of the sound collected by the microphones.

void stopAudioOut ()

This method calls a procedure to stop and clear the audio output buffers.

void resetAudio ()

reset ALSA driver. Use this method only when no audio module is subscribed to ALAudioDevice

void setOutputVolume (const int& volume)

Sets the output sound level of the system.

volume

Volume [0-100].

Example in python :

#Sets the output sound level of the system to maximum
ad.setOutputVolume(100)

int getOutputVolume ()

Gets the output sound level of the system.

Returns

outputVolume of the system

Example in python :

#Gets the output sound level of the system
int vol = ad.getOutputVolume()

void openAudioInputs ()

Opens the audio device for capture. If you closed the audio inputs with the closeAudioInputs method, you must call this method to be able to access to the sound data of the nao's microphones.

void openAudioOutputs ()

Opens the audio device for playback. If you closed the audio outputs with the closeAudioOutputs method, you must call this method to ear or send sound onto the nao's loudspeakers.

void closeAudioInputs ()

Closes the audio device for capture. You can call this method if you want to have access to the alsa input buffers in another program than naoqi while naoqi is running (with a record for example)

void closeAudioOutputs ()

Closes the audio device for playback. close the audio device for capture. You can call this method if you want to send sound to alsa in another program than naoqi while naoqi is running (with aplay for example)

void playSine (const int& frequence, const int& gain, const int& pan, const int& duration)

Play a sine wave which specified caracteristics.

frequence

Frequence in Hertz

gain

Volume Gain between 0 and 100

pan

Stereo Pan set to either {-1,0,+1}

duration

Duration of the sine wave in seconds

void enableEnergyComputation ()

Enables the computation of the energy of each microphone signal

void disableEnergyComputation ()

Disables the computation of the energy of each microphone signal

float getLeftMicEnergy ()

Returns the energy of the left microphone signal

Returns

energy of the left microphone signal

float getRightMicEnergy ()

Returns the energy of the right microphone signal

Returns

energy of the right microphone signal

float getFrontMicEnergy ()

Returns the energy of the front microphone signal

Returns

energy of the front microphone signal

float getRearMicEnergy ()

Returns the energy of the rear microphone signal

Returns

energy of the rear microphone signal


Methods inherited from ALModule

void exit ()

Exits and unregisters the module.

string version ()

Returns the version of the module.

Returns

A string containing the version of the module.

bool ping ()

Just a ping. Always returns true

Returns

returns true

vector<string> getMethodList ()

Retrieves the module's method list.

Returns

An array of method names.

AL::ALValue getMethodHelp (const string& methodName)

Retrieves a method's description.

methodName

The name of the method.

Returns

A structure containing the method's description.

AL::ALValue getModuleHelp ()

Retrieves the module's description.

Returns

A structure describing the module.

string getBrokerName ()

Gets the name of the parent broker.

Returns

The name of the parent broker.

string getUsage (const string& name)

Gets the method usage string. This summarise how to use the method.

name

The name of the method.

Returns

A string that summarises the usage of the method.


Copyright © 2010 Aldebaran Robotics - All rights reserved