The problem is I'm not sure how to combine the output of one operator (which is 14 bits) to modulate the phase input (10 bits) of another operator as required by the YM2612 "Alogorithms".
Do I need to perform any shifts/manipulation on the 14 bit output before adding it to the 10 bit phase input? I've tried everything under the sun, but I can't get anything to work - I keep getting wierd hissing/distortion sound as soon as I try to combine operators.
Can anyone explain the math on how to do this in the "perfect" device code taken from the mentioned thread (see below).
//attenuationBitCount = 10
//phaseBitCount = 10
//operatorOutBitCount = 14
//phase = the output from the phase generator
//attenuation = the output from the envelope generator
//???????????????????????
// how do you modulate the 10 bit "phase" input by another operators 14 bit output?
// Something like this is not working for me:
// phase += otherOperatorOutput; // Modulate
// phase &= ( ( 1 << 10 ) -1 ); // Wrap
//???????????????????????
//Calculate the sine value
double phaseNormalized = ((double)phase / ((1 << phaseBitCount) - 1))
double sinResult = sin(phaseNormalized * M_PI * 2);
//Convert the attenuation to a linear representation of power
double attenuationIndividualBitWeighting = 48.0 / (1 << attenuationBitCount);
double attenuationInBels = (((double)attenuation * attenuationIndividualBitWeighting) / 10.0);
double powerLinear = pow(10.0, -attenuationInBels);
//Attenuate the result
double resultNormalized = sinResult * powerLinear;
//Calculate the 14-bit operator output
unsigned int maxOperatorOutput = ((1 << (operatorOutBitCount - 1)) - 1);
int result = (int)(resultNormalized * maxOperatorOutput);
I'm currently in the process of performing tests on the LFO. I have performed tests on self-feedback, but I want to go back and re-test a few things. I'll post info on these areas when I'm confident the information is correct. I think it's more important I get my updated notes on the envelope generator out first however, since incorrect emulation of the envelope generator is still causing problems in some games.