Aria  2.8.0
ArSoundPlayer Class Reference

This class provides a cross-platform interface for playing short sound samples. More...

#include <ArSoundPlayer.h>

Static Public Member Functions

static ArRetFunctor2< bool, const char *, const char * > * getPlayWavFileCallback ()
 Return the static functor for playWavFile.
 
static ArFunctorgetStopPlayingCallback ()
 Return the static functor for stopPlaying(). More...
 
static bool playNativeFile (const char *filename, const char *params)
 Play a file in some native file format for the compilation platform. More...
 
static bool playSoundPCM16 (char *data, int numSamples)
 Play raw uncompressed PCM16 sound data. More...
 
static bool playWavFile (const char *filename, const char *params)
 Play a WAV (Windows RIFF) file. More...
 
static bool playWavFile (const char *filename)
 
static void setVolume (double v)
 Set a volume adjustment applied to all sounds right before playing. More...
 
static void setVolumePercent (double pct)
 Set volume as a "percent" of normal, where 100% is normal or natural volume, 50% is increased by 50%, -50% is decreased by 50%, etc. More...
 
static void stopPlaying ()
 Cancel (interrupt) any current sound or file playback. More...
 

Static Protected Attributes

static int ourPlayChildPID = -1
 Only used on Linux.
 
static ArGlobalRetFunctor2< bool, const char *, const char * > ourPlayWavFileCB
 
static ArGlobalFunctor ourStopPlayingCB
 
static double ourVolume = 1.0
 

Detailed Description

This class provides a cross-platform interface for playing short sound samples.

(Currently implemented for Windows and Linux).

See also
For I/O and network transfer of encoded audio, see the ArNetAudio library.
ArSoundsQueue
Note
Uses an external program to play WAV files on Linux. If an environment variable named PLAY_WAV is set, that program is used, otherwise, 'play' from the 'sox' toolset is used. PLAY_WAV must contain one word (the command; no arguments) A call to playWavFile() will return immediately after 'play' has finished, even though Linux may still be playing back the sound data. In general, this kind of thing is a problem, especially with speech recognition immediately after playing a sound. Ideally, we should be able to truly block until the sound has finished playback. Alas, it is not an ideal world. Another potential pitfall due to the use of an external program invocation: the program you call must not attempt to issue any output. 'play' from the 'sox' toolset automatically supresses normal output if it isn't called from an interactive terminal, but it may still issue some error messages, which will cause it to hang indefinately.

The volume (level) of audio output from a robot is determined by two things: the computer sound device mixer, and also the amplifier which drives the speakers. The computer's mixer can be adjusted through the operating system: on Linux, you can use the 'aumix' program to adjust the Master and PCM levels. On Windows, use the Windows mixer program. If on Linux, ArSoundPlayer also prodives the setVolume() method, which adjusts the volume of the sound before it is played.

Member Function Documentation

◆ getStopPlayingCallback()

ArFunctor * ArSoundPlayer::getStopPlayingCallback ( )
static

Return the static functor for stopPlaying().

Examples:
soundsQueueExample.cpp.

◆ playNativeFile()

bool ArSoundPlayer::playNativeFile ( const char *  filename,
const char *  params 
)
static

Play a file in some native file format for the compilation platform.

◆ playSoundPCM16()

bool ArSoundPlayer::playSoundPCM16 ( char *  data,
int  numSamples 
)
static

Play raw uncompressed PCM16 sound data.

The format of this data is numSamples samples of two bytes each. Each byte pair is a signed little endian integer. The sound will be played back at 16kHz, monaurally.

Returns
false on error, true on success.

◆ playWavFile()

bool ArSoundPlayer::playWavFile ( const char *  filename,
const char *  params 
)
static

Play a WAV (Windows RIFF) file.

Note
Uses an external program to play WAV files on Linux. If an environment variable named PLAY_WAV is set, that program is used, otherwise, 'play' from the 'sox' toolset is used. See detailed note in the overview for this cass.
Parameters
filenameName of the file to play
paramsignored

◆ setVolume()

void ArSoundPlayer::setVolume ( double  v)
static

Set a volume adjustment applied to all sounds right before playing.

(So this adjusts the volume in addition to, not instead of, the computer audio mixer). Any value less than or equal to 0 is no volume i.e. muted or no output.

Note
Available on Linux only

◆ setVolumePercent()

void ArSoundPlayer::setVolumePercent ( double  pct)
static

Set volume as a "percent" of normal, where 100% is normal or natural volume, 50% is increased by 50%, -50% is decreased by 50%, etc.

(-100.0% is no volume, or mute.)

Note
Available on Linux only
Examples:
soundsQueueExample.cpp.

◆ stopPlaying()

void ArSoundPlayer::stopPlaying ( )
static

Cancel (interrupt) any current sound or file playback.


The documentation for this class was generated from the following files: