Classes | |
struct | Command |
Public Types | |
enum | WaveForm { kWaveFormSquare = 0, kWaveFormSine, kWaveFormSaw, kWaveFormTriangle, kWaveFormSilence } |
Public Member Functions | |
PCSpeaker (int rate=44100) | |
void | play (WaveForm wave, int freq, int32 length) |
void | playQueue (WaveForm wave, float freq, uint32 lengthus) |
void | stop (int32 delay=0) |
void | setVolume (byte volume) |
bool | isPlaying () const |
int | readBuffer (int16 *buffer, const int numSamples) |
bool | isStereo () const |
bool | endOfData () const |
bool | endOfStream () const |
int | getRate () const |
Protected Types | |
typedef int8(* | generatorFunc) (uint32, uint32) |
Protected Attributes | |
Common::Mutex | _mutex |
int | _rate |
WaveForm | _wave |
bool | _playForever |
uint32 | _oscLength |
uint32 | _oscSamples |
uint32 | _remainingSamples |
uint32 | _mixedSamples |
byte | _volume |
Common::Queue< Command > * | _commandQueue |
bool | _commandActive |
Static Protected Attributes | |
static const generatorFunc | generateWave [] |
void Audio::PCSpeaker::play | ( | WaveForm | wave, |
int | freq, | ||
int32 | length | ||
) |
Play a note for length ms.
If length is negative, play until told to stop.
void Audio::PCSpeaker::playQueue | ( | WaveForm | wave, |
float | freq, | ||
uint32 | lengthus | ||
) |
Queue the specified playback instruction. It will be executed when all previously queued instructions have finished. Use this method for playback of effects which require timing precision of less than a millisecond.
Calling this method will terminate any waveform started with the play method. Calling the play method will terminate the active queued instruction and clear the instruction queue.
Use isPlaying to check if all queued instructions have finished playing. This will return true even if the current instruction is "playing" silence.
wave | The waveform to use. For PC speaker, use square wave or silence. |
freq | The frequency (in Hertz) to play. |
lengthus | The length in microseconds for which to play the waveform. |
void Audio::PCSpeaker::stop | ( | int32 | delay = 0 | ) |
Stop the currently playing note after delay ms.
void Audio::PCSpeaker::setVolume | ( | byte | volume | ) |
Adjust the volume.
|
virtual |
Fill the given buffer with up to numSamples
samples.
Data must be in native endianness, 16 bits per sample, signed. For stereo stream, the buffer will be filled with interleaved left and right channel samples, starting with the left sample. Furthermore, the samples in the left and right are summed up. So if you request 4 samples from a stereo stream, you will get a total of two left channel and two right channel samples.
Implements Audio::AudioStream.
|
inlinevirtual |
Check whether this is a stereo stream.
Implements Audio::AudioStream.
|
inlinevirtual |
Check whether end of data has been reached.
If this returns true, it indicates that at this time there is no data available in the stream. However, there might be more data in the future.
This is used by e.g. a rate converter to decide whether to keep on converting data or to stop.
Implements Audio::AudioStream.
|
inlinevirtual |
Check whether end of stream has been reached.
If this returns true, it indicates that all data in this stream is used up and no additional data will appear in it in the future.
This is used by the mixer to decide whether a given stream shall be removed from the list of active streams (and thus be destroyed). By default, this maps to endOfData().
Reimplemented from Audio::AudioStream.
Reimplemented in Freescape::SizedPCSpeaker.
|
inlinevirtual |
Sample rate of the stream.
Implements Audio::AudioStream.