Skip to content

Commit

Permalink
Assert legacy mixing levels and ranges
Browse files Browse the repository at this point in the history
This fixes #213.
  • Loading branch information
Gumball2415 committed May 31, 2023
1 parent b7210f8 commit f1404a9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
12 changes: 6 additions & 6 deletions Source/APU/2A03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ int C2A03::GetChannelLevelRange(int Channel) const
}


void C2A03::UpdateMixingAPU1(double v) {
void C2A03::UpdateMixingAPU1(double v, bool UseSurveyMix) {
// NSFPlay output waveform ranges from 0 - 8191
// should not affect legacy mixing
Synth2A03SS.volume(v, 8191);
// legacy mixing absolutely requires the range 10000
Synth2A03SS.volume(v, UseSurveyMix ? 8191 : 10000);
}

void C2A03::UpdateMixingAPU2(double v) {
void C2A03::UpdateMixingAPU2(double v, bool UseSurveyMix) {
// NSFPlay output waveform ranges from 0 - 8191
// should not affect legacy mixing
Synth2A03TND.volume(v, 8191);
// legacy mixing absolutely requires the range 10000
Synth2A03TND.volume(v, UseSurveyMix ? 8191 : 10000);
}

void C2A03::ClockSequence()
Expand Down
4 changes: 2 additions & 2 deletions Source/APU/2A03.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class C2A03 : public CSoundChip2
int GetChannelLevelRange(int Channel) const override;

public:
void UpdateMixingAPU1(double v);
void UpdateMixingAPU2(double v);
void UpdateMixingAPU1(double v, bool UseSurveyMix = false);
void UpdateMixingAPU2(double v, bool UseSurveyMix = false);

void ClockSequence(); // // //

Expand Down
7 changes: 1 addition & 6 deletions Source/APU/FDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,7 @@ void CFDS::UpdateMixLevel(double v, bool UseSurveyMix)
// (m_SynthFDS: FdsAudio) used to generate output samples between [0..63] inclusive,
// but was changed to [0 .. 63*1152] inclusive to prevent quantization at low volumes.

if (UseSurveyMix)
m_SynthFDS.volume(v, 63 * 1152);
else
// The following mixing levels match nsfplay's FDS output,
// using 2A03 Pulse as a baseline.
m_SynthFDS.volume(v * 1.122f, 256 * 1152);
m_SynthFDS.volume(UseSurveyMix ? v : (v * 1.122f), UseSurveyMix ? (63 * 1152) : (256 * 1152));
}

/// Input:
Expand Down
27 changes: 11 additions & 16 deletions Source/APU/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void CMixer::SetChipLevel(chip_level_t Chip, float Level)

float CMixer::GetAttenuation(bool UseSurveyMix) const
{
float Attenuation = 1.0f;
float ATTENUATION_2A03 = 1.0f;

if (!UseSurveyMix) {
const float ATTENUATION_VRC6 = 0.80f;
Expand All @@ -161,22 +161,17 @@ float CMixer::GetAttenuation(bool UseSurveyMix) const
// Increase headroom if some expansion chips are enabled

if (m_iExternalChip & SNDCHIP_VRC6)
Attenuation *= ATTENUATION_VRC6;

ATTENUATION_2A03 *= ATTENUATION_VRC6;
if (m_iExternalChip & SNDCHIP_VRC7)
Attenuation *= ATTENUATION_VRC7;

ATTENUATION_2A03 *= ATTENUATION_VRC7;
if (m_iExternalChip & SNDCHIP_FDS)
Attenuation *= ATTENUATION_FDS;

ATTENUATION_2A03 *= ATTENUATION_FDS;
if (m_iExternalChip & SNDCHIP_MMC5)
Attenuation *= ATTENUATION_MMC5;

ATTENUATION_2A03 *= ATTENUATION_MMC5;
if (m_iExternalChip & SNDCHIP_N163)
Attenuation *= ATTENUATION_N163;

ATTENUATION_2A03 *= ATTENUATION_N163;
if (m_iExternalChip & SNDCHIP_S5B) // // // 050B
Attenuation *= ATTENUATION_S5B;
ATTENUATION_2A03 *= ATTENUATION_S5B;
}
else {
// attenuation scaling is exponential based on total chips used
Expand All @@ -188,10 +183,10 @@ float CMixer::GetAttenuation(bool UseSurveyMix) const
if (m_iExternalChip & SNDCHIP_N163) TotalChipsUsed++;
if (m_iExternalChip & SNDCHIP_S5B) TotalChipsUsed++;

Attenuation *= static_cast<float>(1.0 / (float)TotalChipsUsed);
ATTENUATION_2A03 *= static_cast<float>(1.0 / (float)TotalChipsUsed);
}

return Attenuation;
return ATTENUATION_2A03;
}

void CMixer::RecomputeEmuMixState()
Expand Down Expand Up @@ -229,8 +224,8 @@ void CMixer::RecomputeEmuMixState()

// Maybe the range argument, as well as the constant factor in the volume,
// should be supplied by the CSoundChip2 subclass rather than CMixer.
chip2A03.UpdateMixingAPU1(Volume * m_fLevelAPU1);
chip2A03.UpdateMixingAPU2(Volume * m_fLevelAPU2);
chip2A03.UpdateMixingAPU1(Volume * m_fLevelAPU1, UseSurveyMixing);
chip2A03.UpdateMixingAPU2(Volume * m_fLevelAPU2, UseSurveyMixing);
chipFDS.UpdateMixLevel(Volume * m_fLevelFDS, UseSurveyMixing);
chipN163.UpdateMixLevel(Volume * m_fLevelN163, UseSurveyMixing);

Expand Down
2 changes: 1 addition & 1 deletion Source/APU/VRC7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void CVRC7::UpdateMixLevel(double v, bool UseSurveyMix)
SetDirectVolume(UseSurveyMix ? v : (v * AMPLIFY));

// emu2413's waveform output ranges from -4095...4095
m_SynthVRC7.volume(v, 8191);
m_SynthVRC7.volume(v, UseSurveyMix ? 8191 : 10000);
}

void CVRC7::UpdatePatchSet(int PatchSelection, bool UseExternalOPLLChip, uint8_t* PatchSet)
Expand Down

0 comments on commit f1404a9

Please # to comment.