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).
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
Smart pointer on the module
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
Smart pointer on the module
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 & pNbOfInputChannels, const int & pNbrSamples, const ALValue & 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
Name of the remote module
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
Name of the remote module to unsuscribe from ALAudioDevice
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
Number of 16 bits samples per channel to send.
Buffer to send
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
Number of 16 bits samples per channel to send.
Buffer to send
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
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
Name of the parameter to set ('outputSampleRate' or 'inputBufferSize').
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.
Name of the parameter to get ('outputSampleRate' or 'inputBufferSize').
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
Name of the file where to record the sound.
void stopMicrophonesRecording ()
This method stops the recording of the sound collected by the microphones.
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 [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.
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 in Hertz
Volume Gain between 0 and 100
Stereo Pan set to either {-1,0,+1}
Duration of the sine wave in seconds
float getLeftMicEnergy ()
Returns the energy of the left microphone signal
energy of the left microphone signal
float getRightMicEnergy ()
Returns the energy of the right microphone signal
energy of the right microphone signal
float getFrontMicEnergy ()
Returns the energy of the front microphone signal
energy of the front microphone signal
float getRearMicEnergy ()
Returns the energy of the rear microphone signal
energy of the rear microphone signal
string version ()
Returns the version of the module.
A string containing the version of the module.
AL::ALValue getMethodHelp (const string& methodName)
Retrieves a method's description.
The name of the method.
A structure containing the method's description.
AL::ALValue getModuleHelp ()
Retrieves the module's description.
A structure describing the module.
string getUsage (const string& name)
Gets the method usage string. This summarise how to use the method.
The name of the method.
A string that summarises the usage of the method.