I recently got the Sunsoft 5B board working in my emulator, and was playing Gimmick! to see what the sound is like, when I ran across a horrible noise. I fell into a spike pit, and my speakers crackled loudly. I realize this is because I am not mixing the new sound channel properly.
My questions is, what is the proper way of doing it? I came up with a couple ideas, which I'm sure are wrong.
One of them included finding the relationship between the 2A07's maximum output: (45 + 30 + 127) + (15 + 15) = 232, and the external component's maximum output: (15 + 15 + 15) = 45. Is this the proper way of doing it? Forcing more room into the post-mixed 2A07 sample and adding the SS5B sample?
Seems like there is a better way to go about this, and I couldn't find anything using the search (big surprise there). So I feel it would be nice to have this post for others to learn from!
EDIT: For now, this is my solution:
Code:
var output = (NesApuMixer.MixSamples(sqrSample, tndSample) * 128);
if (output > 0x80)
output = 0x80;
if (output < 0x00)
output = 0x00;
if (this.External != null)
{
output += this.External.RenderSample(sampleRate);
}
this.soundBuffer[wPos++ % this.soundBuffer.Length] = (int)output;
if (output > 0x80)
output = 0x80;
if (output < 0x00)
output = 0x00;
if (this.External != null)
{
output += this.External.RenderSample(sampleRate);
}
this.soundBuffer[wPos++ % this.soundBuffer.Length] = (int)output;
My questions is, what is the proper way of doing it? I came up with a couple ideas, which I'm sure are wrong.
One of them included finding the relationship between the 2A07's maximum output: (45 + 30 + 127) + (15 + 15) = 232, and the external component's maximum output: (15 + 15 + 15) = 45. Is this the proper way of doing it? Forcing more room into the post-mixed 2A07 sample and adding the SS5B sample?
Seems like there is a better way to go about this, and I couldn't find anything using the search (big surprise there). So I feel it would be nice to have this post for others to learn from!
EDIT: For now, this is my solution:
Code:
var output = (NesApuMixer.MixSamples(sqrSample, tndSample) * OutputMul);
if (this.External != null)
{
output += this.External.RenderSample(sampleRate);
output *= (OutputMul / (OutputMul + External.MaxOutput));
// (128 / (128 + 45)) for Sunsoft 5B
}
if (output > 0x80)
output = 0x80;
if (output < 0x00)
output = 0x00;
this.soundBuffer[wPos++ % this.soundBuffer.Length] = (int)output;
if (this.External != null)
{
output += this.External.RenderSample(sampleRate);
output *= (OutputMul / (OutputMul + External.MaxOutput));
// (128 / (128 + 45)) for Sunsoft 5B
}
if (output > 0x80)
output = 0x80;
if (output < 0x00)
output = 0x00;
this.soundBuffer[wPos++ % this.soundBuffer.Length] = (int)output;