wavelength 1.0.0
Loading...
Searching...
No Matches
Voice Class Reference

One SPU2 voice and the note it plays. More...

#include <voice.h>

Collaboration diagram for Voice:

Public Member Functions

 Voice ()
 Construct a free voice with no descriptor.
void Init ()
 Free the voice.
void Dump () const
 Print the voice's descriptor to the console.
void ComputeVolume (unsigned int *left, unsigned int *right) const
 Compute the voice's volume registers from its channel, bank, program, and descriptor.
unsigned int ComputePitch () const
 Compute the voice's pitch register from its channel, program, and descriptor, without vibrato.

Static Public Member Functions

static int FindFree (Voice *voices, int count, int *stealIndex)
 Find the first free voice of a core, or else the best voice to steal.
static void CalculateVolume (unsigned char velocity, unsigned char bankVolume, unsigned char programVolume, unsigned char sampleVolume, unsigned char channelVolume, unsigned char channelExpression, unsigned char pan, unsigned int *left, unsigned int *right, signed char surround)
 Compute the left and right volume registers of a note.
static unsigned int CalculatePitch (unsigned char note, unsigned char baseKey, int semitones, int cents, int sampleRate)
 Compute the pitch register of a note.

Public Attributes

unsigned char mChannel
unsigned char mNote
unsigned short mBank
unsigned char mVelocity
int mPitch
int mVibratoPhase
int mVibratoTable
unsigned int mAge
int mState
BankSampleDesc * mSampleDesc
unsigned char mPriority

Detailed Description

One SPU2 voice and the note it plays.

The class has no RTTI, and its name is inferred from its role. The synthesiser has one per hardware voice of each core and a list of retired copies of voices whose one-shot waveform ended before the note-off.

Constructor & Destructor Documentation

◆ Voice()

Voice::Voice ( )
inline

Construct a free voice with no descriptor.

Member Function Documentation

◆ Init()

void Voice::Init ( )

Free the voice.

Ghidra address:
NTSC-U/C: 0x00002190
Ghidra address:
PAL: 0x00002190

◆ Dump()

void Voice::Dump ( ) const

Print the voice's descriptor to the console.

Ghidra address:
NTSC-U/C: 0x000021dc
Ghidra address:
PAL: 0x000021dc

◆ FindFree()

int Voice::FindFree ( Voice * voices,
int count,
int * stealIndex )
static

Find the first free voice of a core, or else the best voice to steal.

The steal candidate is the playing voice with the lowest priority, the oldest among equals. The search starts from the first voice whatever its state.

Parameters
voicesThe core's voices.
countNumber of voices.
stealIndexReceives -1 when a voice is free, otherwise the steal candidate.
Returns
The free voice's index, or -1 when none is free.
Ghidra address:
NTSC-U/C: 0x0000220c
Ghidra address:
PAL: 0x0000220c

◆ CalculateVolume()

void Voice::CalculateVolume ( unsigned char velocity,
unsigned char bankVolume,
unsigned char programVolume,
unsigned char sampleVolume,
unsigned char channelVolume,
unsigned char channelExpression,
unsigned char pan,
unsigned int * left,
unsigned int * right,
signed char surround )
static

Compute the left and right volume registers of a note.

Every level is an index into the volume curve. With surround set, one side is inverted for the surround decoder.

Parameters
velocityNote velocity.
bankVolumeBank volume.
programVolumeProgram volume.
sampleVolumeDescriptor volume.
channelVolumeChannel volume.
channelExpressionChannel expression.
panCombined pan, zero to 127.
leftReceives the left volume.
rightReceives the right volume.
surroundNonzero to invert one side.
Ghidra address:
NTSC-U/C: 0x00002330
Ghidra address:
PAL: 0x00002330

◆ CalculatePitch()

unsigned int Voice::CalculatePitch ( unsigned char note,
unsigned char baseKey,
int semitones,
int cents,
int sampleRate )
static

Compute the pitch register of a note.

Parameters
noteNote to play.
baseKeyNote at which the sample plays at its sample rate.
semitonesTransposition in semitones.
centsTransposition in cents, borrowed into semitones when negative.
sampleRateRate of the sample in hertz.
Returns
The pitch register value scaled from 48000 hertz to sampleRate.
Ghidra address:
NTSC-U/C: 0x00002498
Ghidra address:
PAL: 0x00002498

◆ ComputeVolume()

void Voice::ComputeVolume ( unsigned int * left,
unsigned int * right ) const

Compute the voice's volume registers from its channel, bank, program, and descriptor.

The outputs are not written when the channel has no program.

Parameters
leftReceives the left volume.
rightReceives the right volume.
Ghidra address:
NTSC-U/C: 0x000042f0
Ghidra address:
PAL: 0x000042f0

◆ ComputePitch()

unsigned int Voice::ComputePitch ( ) const

Compute the voice's pitch register from its channel, program, and descriptor, without vibrato.

Returns
The pitch register value.
Ghidra address:
NTSC-U/C: 0x00004698
Ghidra address:
PAL: 0x00004698

Member Data Documentation

◆ mChannel

unsigned char Voice::mChannel

MIDI channel of the note.

◆ mNote

unsigned char Voice::mNote

Note number.

◆ mBank

unsigned short Voice::mBank

Bank slot of the note's program.

◆ mVelocity

unsigned char Voice::mVelocity

Note velocity.

◆ mPitch

int Voice::mPitch

Pitch register value before vibrato.

◆ mVibratoPhase

int Voice::mVibratoPhase

Offset into the vibrato table, or -1 for no vibrato.

◆ mVibratoTable

int Voice::mVibratoTable

Zero for the fast table, one for the slow one.

◆ mAge

unsigned int Voice::mAge

Note-on serial; smaller is older.

◆ mState

int Voice::mState

◆ mSampleDesc

BankSampleDesc* Voice::mSampleDesc

Descriptor of the note.

◆ mPriority

unsigned char Voice::mPriority

Channel priority at the note-on.


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