ScummVM API documentation
MADS::Phantom::ASound Class Reference
Inheritance diagram for MADS::Phantom::ASound:
MADS::SoundDriver MADS::Phantom::ASound1 MADS::Phantom::ASound2 MADS::Phantom::ASound3 MADS::Phantom::ASound4 MADS::Phantom::ASound5 MADS::Phantom::ASound9 MADS::Phantom::ASoundDemo

Public Member Functions

 ASound (Audio::Mixer *mixer, const Common::Path &filename, int dataOffset, int dataSize)
 
 ~ASound () override
 
virtual int stop () override
 
int poll () override
 
void noise () override
 
void setVolume (int volume) override
 
- Public Member Functions inherited from MADS::SoundDriver
 SoundDriver (Audio::Mixer *mixer, const Common::Path &filename, int dataOffset, int dataSize)
 
virtual int command (int commandId, int param)=0
 

Static Public Member Functions

static void validate (bool isDemo)
 

Protected Member Functions

void write (uint8 reg, uint8 value)
 
uint16 getRandomNumber ()
 
void adlib_channelOn (uint8 portIndex, uint8 vol)
 
void signalSoundPlaying ()
 
void pollAllChannels ()
 
void pollActiveChannel ()
 
bool isSoundActive (byte *ptr) const
 
void findFreeChannel (byte *soundData)
 
void findFreeChannelFull (byte *soundData)
 
byte * loadData (int offset)
 
void playSound (int offset)
 
int command0 ()
 
int command1 ()
 
int command2 ()
 
int command3 ()
 
int command4 ()
 
int command5 ()
 
int command6 ()
 
int command7 ()
 
int command8 ()
 
virtual void callFunction (uint16 offset)
 
- Protected Member Functions inherited from MADS::SoundDriver
Common::MemoryReadStream getDataStream (int offset) const
 

Protected Attributes

AdlibChannel _channel0
 
AdlibChannel _channel1
 
AdlibChannel _channel2
 
AdlibChannel _channel3
 
AdlibChannel _channel4
 
AdlibChannel _channel5
 
AdlibChannel _channel6
 
AdlibChannel _channel7
 
AdlibChannel _channel8
 
AdlibChannel_channels [9]
 
uint8 _adlibPorts [0x100] = { 0 }
 
Common::Array< AdlibSample_samples
 
- Protected Attributes inherited from MADS::SoundDriver
Audio::Mixer_mixer
 
Common::Array< byte > _soundData
 
Common::Mutex _driverMutex
 

Constructor & Destructor Documentation

◆ ASound()

MADS::Phantom::ASound::ASound ( Audio::Mixer mixer,
const Common::Path filename,
int  dataOffset,
int  dataSize 
)

Constructor

Parameters
mixerMixer
filenameSpecifies the adlib sound player file to use
dataOffsetOffset in the file of the data segment

◆ ~ASound()

MADS::Phantom::ASound::~ASound ( )
inlineoverride

Destructor

Member Function Documentation

◆ write()

void MADS::Phantom::ASound::write ( uint8  reg,
uint8  value 
)
protected

write(register, value)

Updates the local port-shadow array so that subsequent reads from _adlibPorts[reg] return the last-written value, then sends the byte pair to the real hardware (or whatever back-end is wired in).

◆ getRandomNumber()

uint16 MADS::Phantom::ASound::getRandomNumber ( )
protected

Updates and returns _asound_randomSeed.

◆ adlib_channelOn()

void MADS::Phantom::ASound::adlib_channelOn ( uint8  portIndex,
uint8  vol 
)
protected

Restores one output operator: clears the forced-max bits (0x3F) and writes the caller-supplied volume nibble (bh in the asm). 'portIndex' is the operator register index; 'vol' is the volume nibble.

◆ signalSoundPlaying()

void MADS::Phantom::ASound::signalSoundPlaying ( )
protected

Sets the poll-result flags to indicate that sound is playing.

◆ pollAllChannels()

void MADS::Phantom::ASound::pollAllChannels ( )
protected

Polls all the channels

◆ pollActiveChannel()

void MADS::Phantom::ASound::pollActiveChannel ( )
protected

Per-channel update, called once per frame by pollAllChannels. Implements a bytecode interpreter : the sound data stream is a sequence of (note, duration) pairs plus command bytes(0x80-0xFF). Commands with high bit clear are notes; high bit set triggers the switch below.

The interpreter loop re-enters the top of the dispatch after each command that does not consume a duration tick. Note bytes consume one tick per call (activeCount counts down).

◆ isSoundActive()

bool MADS::Phantom::ASound::isSoundActive ( byte *  ptr) const
protected

Returns true if a given sound data is already active.

◆ findFreeChannel()

void MADS::Phantom::ASound::findFreeChannel ( byte *  soundData)
protected

Channel finder helpers Scan channels in priority order and call AdlibChannel_load on the first inactive (or pending-stop) one found.

Searches channels 0-5 for an empty slot, falling through to asound_findFreeChannelFull (channels 6-8) if none found. _findChannelMode == 1 means "only search 0-5".

◆ findFreeChannelFull()

void MADS::Phantom::ASound::findFreeChannelFull ( byte *  soundData)
protected

Extends the search to channels 6-8 and then checks for pending-stop channels (which can be pre-empted), in reverse priority order.

◆ loadData()

byte* MADS::Phantom::ASound::loadData ( int  offset)
inlineprotected

Returns data for the specified offset.

◆ playSound()

void MADS::Phantom::ASound::playSound ( int  offset)
protected

Plays the sound data at a given offset

◆ command0()

int MADS::Phantom::ASound::command0 ( )
protected

Silences every voice and mutes the hardware:

  1. Reset all 9 channels.
  2. Mute all operator total-level registers (0x40-0x55) to max attenuation.
  3. Zero remaining operator registers (0x60-0xFF and 0x01-0x3F).
  4. Write Waveform Select Enable (register 0x01 = 0x20).
  5. Reset the tick callback.

◆ command2()

int MADS::Phantom::ASound::command2 ( )
protected

Fade out music channels 0-5.

◆ command3()

int MADS::Phantom::ASound::command3 ( )
protected

Fade out low channels

◆ command4()

int MADS::Phantom::ASound::command4 ( )
protected

Fade out SFX channels 6-8.

◆ command6()

int MADS::Phantom::ASound::command6 ( )
protected

Saves each channel's current freqSweepCounter into savedFreqSweep, zeroes freqSweepCounter on all channels, then mutes the output operators for voices 3-5 (the secondary operator set at 0x43-0x55).

◆ command7()

int MADS::Phantom::ASound::command7 ( )
protected

Resume playback after a pause. Restores operator volumes for channels 0-5, re-saves sweep counters from the live values (which were frozen to 0 by command6), then re-enables the audio engine.

The OPL2 voice-to-operator mapping used here: voice 0 -> operator index 67 (0x43) voice 1 -> operator index 68 (0x44) voice 2 -> operator index 69 (0x45) voice 3 -> operator index 75 (0x4B) voice 4 -> operator index 76 (0x4C) voice 5 -> operator index 77 (0x4D)

◆ command8()

int MADS::Phantom::ASound::command8 ( )
protected

Returns non-zero if any of the 9 Adlib channels has a non-zero _activeCount (i.e. sound is currently playing).

◆ callFunction()

virtual void MADS::Phantom::ASound::callFunction ( uint16  offset)
protectedvirtual

Calls a function at a fixed offset within the sound driver.

Parameters
offsetOffset of the function

◆ validate()

static void MADS::Phantom::ASound::validate ( bool  isDemo)
static

Validates the presence of the sound driver files.

◆ stop()

virtual int MADS::Phantom::ASound::stop ( )
overridevirtual

Stop all currently playing sounds

Implements MADS::SoundDriver.

◆ poll()

int MADS::Phantom::ASound::poll ( )
overridevirtual

Main poll method to allow sounds to progress

Implements MADS::SoundDriver.

◆ noise()

void MADS::Phantom::ASound::noise ( )
overridevirtual

Noise channel : each tick picks a random frequency offset masked by noiseFreqMask, adds freqAccum, and writes the result.

Implements MADS::SoundDriver.

◆ setVolume()

void MADS::Phantom::ASound::setVolume ( int  volume)
inlineoverridevirtual

Set the volume

Implements MADS::SoundDriver.

Member Data Documentation

◆ _channels

AdlibChannel* MADS::Phantom::ASound::_channels[9]
protected
Initial value:
= {
&_channel0, &_channel1, &_channel2, &_channel3, &_channel4,
&_channel5, &_channel6, &_channel7, &_channel8
}

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