ScummVM API documentation
Audio::PCSpeaker Class Reference
Inheritance diagram for Audio::PCSpeaker:
Audio::AudioStream Freescape::SizedPCSpeaker

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)
 

Static Protected Member Functions

static int8 generateSquare (uint32 x, uint32 oscLength)
 
static int8 generateSine (uint32 x, uint32 oscLength)
 
static int8 generateSaw (uint32 x, uint32 oscLength)
 
static int8 generateTriangle (uint32 x, uint32 oscLength)
 
static int8 generateSilence (uint32 x, uint32 oscLength)
 

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 []
 

Member Function Documentation

◆ play()

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.

◆ playQueue()

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.

Parameters
waveThe waveform to use. For PC speaker, use square wave or silence.
freqThe frequency (in Hertz) to play.
lengthusThe length in microseconds for which to play the waveform.

◆ stop()

void Audio::PCSpeaker::stop ( int32  delay = 0)

Stop the currently playing note after delay ms.

◆ setVolume()

void Audio::PCSpeaker::setVolume ( byte  volume)

Adjust the volume.

◆ readBuffer()

int Audio::PCSpeaker::readBuffer ( int16 *  buffer,
const int  numSamples 
)
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.

Returns
The actual number of samples read, or -1 if a critical error occurred.
Note
You must check whether the returned value is less than what you requested. This indicates that the stream is fully used up.

Implements Audio::AudioStream.

◆ isStereo()

bool Audio::PCSpeaker::isStereo ( ) const
inlinevirtual

Check whether this is a stereo stream.

Implements Audio::AudioStream.

◆ endOfData()

bool Audio::PCSpeaker::endOfData ( ) const
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.

◆ endOfStream()

bool Audio::PCSpeaker::endOfStream ( ) const
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.

◆ getRate()

int Audio::PCSpeaker::getRate ( ) const
inlinevirtual

Sample rate of the stream.

Implements Audio::AudioStream.


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