resonance 1.0.1
Loading...
Searching...
No Matches
Mixer Class Reference

Per-track MIDI mixer that sits between a track graph and the synthesiser. More...

#include <mixer.h>

Inheritance diagram for Mixer:
Collaboration diagram for Mixer:

Public Member Functions

 Mixer (int nTrack, unsigned char nChannel)
 Construct a mixer on one channel.
virtual ~Mixer ()
void SetGainFactor (int nIndex, unsigned char nFactor)
 Set one of the four gain factors and send the combined level.
void SetMuted (int bMuted)
 Mute or unmute the channel.
void ApplyControlChange (StdMidiMsg *pMsg)
 Act on one control-change message.
void SendPan ()
 Send the pan for the current section.
Public Member Functions inherited from MsgSink
void * operator new (size_t nSize)
 Allocate a sink from the tagged heap under the tag "MsgSink".
void operator delete (void *pBlock)
 Release a sink to the tagged heap.
virtual ~MsgSink ()
virtual void Dispatch (Message *pMsg)
 Accept a message.

Public Attributes

MsgSink * mOutput
 The sink every message this mixer emits is sent to.

Protected Member Functions

void OnTrackSelect (TrackSelectMsg *pMsg)
 React to a TrackSelectMsg.
void OnTracksOn (TracksOnMsg *pMsg)
 React to a TracksOnMsg.
void RecomputeGain ()
 Recompute the gain from the game state and send it as gain factor 3.
virtual void DispatchPriv (Message *pMsg)
 Act on a message.

Detailed Description

Per-track MIDI mixer that sits between a track graph and the synthesiser.

Its RTTI descriptor is at 0x008f0770. It has MsgSink as its one base, and the inherited vptr sits at offset 0. The allocations in BGTrackGraph::CreateMixer() and ScoreTrackGraph's constructor both measure the object at 0x58 bytes. Its vtable is at 0x007df900 and runs four entries.

It is a MIDI filter on one channel. Every message it emits is a StdMidiMsg built on the stack and handed to mOutput, with the channel taken from mChannel. A StdMidiMsg arriving with a control-change status goes through ApplyControlChange().

SetGainFactor() is what fixes the four factors. It multiplies all four together and divides by 127 cubed, which normalises a product of four 7-bit values back into a 7-bit value, and sends that as controller 11. Four independent gains therefore scale one channel's expression.

The name comes from the RTTI descriptor.

Constructor & Destructor Documentation

◆ Mixer()

Mixer::Mixer ( int nTrack,
unsigned char nChannel )

Construct a mixer on one channel.

The routine reads mOwnsPan from configuration code 0x398, mBoostVolume from code 0x399, and mTrackLevels from code 0x39f, sets mLevel and all four gain factors to 127, mTracksOnBar to -1, and mSelection to NullPlayer::sInstance, and zeroes mZeroedBytes twice over. mEndBar takes PlayMap::GetEndBar() of Globals::GetPlayMap(). It does not write mOutput.

Parameters
nTrackThe track this mixer serves. BGTrackGraph passes -1, which matches no track.
nChannelThe MIDI channel every message it emits is sent on.
Ghidra address:
NTSC-U/C: 0x001a7110
Ghidra address:
PAL: 0x001ace78

◆ ~Mixer()

virtual Mixer::~Mixer ( )
virtual
Ghidra address:
NTSC-U/C: 0x001a8130
Ghidra address:
PAL: 0x001ade98

Member Function Documentation

◆ SetGainFactor()

void Mixer::SetGainFactor ( int nIndex,
unsigned char nFactor )

Set one of the four gain factors and send the combined level.

Recomputes the product of all four factors divided by 127 cubed. When the result differs from the level already sent, and the channel is not muted, it stores the result and sends it as controller 11 on mChannel.

The compiler emits its divide-by-zero check against the constant divisor, so the trap it guards can never fire.

Parameters
nIndexWhich factor, 0 through 3.
nFactorThe factor, 0 through 127.
Ghidra address:
NTSC-U/C: 0x001a73a8
Ghidra address:
PAL: 0x001ad110

◆ SetMuted()

void Mixer::SetMuted ( int bMuted)

Mute or unmute the channel.

A change to unmuted sends the level already computed as controller 11, and a change to muted sends zero. A call that does not change the flag sends nothing.

Parameters
bMutedNon-zero to mute.
Ghidra address:
NTSC-U/C: 0x001a7490
Ghidra address:
PAL: 0x001ad1f8

◆ ApplyControlChange()

void Mixer::ApplyControlChange ( StdMidiMsg * pMsg)

Act on one control-change message.

A 41-entry jump table over controller numbers 0x0a through 0x32 decides what happens. Controllers 0x2f through 0x32 set gain factors 0 through 3, controller 0x2e drives SetMuted(), controller 0x0b is discarded because the mixer sends its own expression, controller 0x0a is discarded while mOwnsPan is set and forwarded otherwise, and everything else including a controller outside the table's range is forwarded to mOutput unchanged.

The member is inline. DispatchPriv() has its own emission of the whole body with its own copy of the jump table, which is why two addresses exist for one member.

Parameters
pMsgThe control-change message.
Ghidra address:
NTSC-U/C: 0x001a8390
Ghidra address:
PAL: 0x001ae0f8

◆ SendPan()

void Mixer::SendPan ( )

Send the pan for the current section.

Derives a three-bit index from mTrack less mLastSection and maps it through a six-entry jump table to one of 0, 0, 0x20, 0x40, 0x60, and 0x7f, which it sends as controller 10. An index the table does not reach sends zero.

Ghidra address:
NTSC-U/C: 0x001a72b8
Ghidra address:
PAL: 0x001ad020

◆ OnTrackSelect()

void Mixer::OnTrackSelect ( TrackSelectMsg * pMsg)
protected

React to a TrackSelectMsg.

A message for mTrack installs its player as mSelection and recomputes the gain. Then, for any track, a selection whose Player::GetInputSlot() reports zero takes the message's track as mLastSection and, when mOwnsPan is set, sends the pan.

Parameters
pMsgThe TrackSelectMsg.
Ghidra address:
NTSC-U/C: 0x001a75d8
Ghidra address:
PAL: 0x001ad340

◆ OnTracksOn()

void Mixer::OnTracksOn ( TracksOnMsg * pMsg)
protected

React to a TracksOnMsg.

Stores the message's bar in mTracksOnBar and its track count in mLevelIndex, and recomputes the gain.

Parameters
pMsgThe TracksOnMsg.
Ghidra address:
NTSC-U/C: 0x001a76d0
Ghidra address:
PAL: 0x001ad438

◆ RecomputeGain()

void Mixer::RecomputeGain ( )
protected

Recompute the gain from the game state and send it as gain factor 3.

While GameStats::mCompleted is set the factor is 115. Otherwise a real mSelection gets 127, and the stand-in gets 127 less the low byte of mTrackLevels[mLevelIndex].

Inline. OnTrackSelect() and OnTracksOn() expand it, and the image keeps this out-of-line copy.

Ghidra address:
NTSC-U/C: 0x001a82f0
Ghidra address:
PAL: 0x001ae058

◆ DispatchPriv()

virtual void Mixer::DispatchPriv ( Message * pMsg)
protectedvirtual

Act on a message.

Table slot 3.

Parameters
pMsgThe message.
Ghidra address:
NTSC-U/C: 0x001a7780
Ghidra address:
PAL: 0x001ad4e8

Implements MsgSink.

Member Data Documentation

◆ mOutput

MsgSink* Mixer::mOutput

The sink every message this mixer emits is sent to.

The constructor does not write it. Public because BGTrackGraph::AttachMixerToSynth() stores it directly at 0x001404c4, and the image has no accessor. +0x04


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