// call this for the first channel void GeneratePercussion(bool opl3Mode, Chip chip, short[] output, int pos) { Channel chan = this; //BassDrum int mod = (old[0] + old[1]) >> feedback; old[0] = old[1]; old[1] = Op(0).GetSample(mod); //When bassdrum is in AM mode first operator is ignored if ((chan.regC0 & 1) != 0) { mod = 0; } else { mod = old[0]; } short sample = Op(1).GetSample(mod); //Precalculate stuff used by other outputs int noiseBit = chip.ForwardNoise() & 0x1; int c2 = Op(2).ForwardWave(); int c5 = Op(5).ForwardWave(); int phaseBit = (((c2 & 0x88) ^ ((c2 << 5) & 0x80)) | ((c5 ^ (c5 << 2)) & 0x20)) != 0 ? 0x02 : 0x00; //Hi-Hat uint hhVol = Op(2).ForwardVolume(); if (!EnvSilent((int)hhVol)) { var hhIndex = ((phaseBit << 8) | (0x34 << (byte)(phaseBit ^ (noiseBit << 1)))); sample += Op(2).GetWave(hhIndex, hhVol); } //Snare Drum uint sdVol = Op(3).ForwardVolume(); if (!EnvSilent((int)sdVol)) { int sdIndex = (int)((0x100 + (c2 & 0x100)) ^ (noiseBit << 8)); sample += Op(3).GetWave(sdIndex, sdVol); } //Tom-tom sample += Op(4).GetSample(0); //Top-Cymbal uint tcVol = Op(5).ForwardVolume(); if (!EnvSilent((int)tcVol)) { var tcIndex = ((1 + phaseBit) << 8); sample += Op(5).GetWave(tcIndex, tcVol); } sample <<= 1; if (opl3Mode) { output[pos] += sample; output[pos + 1] += sample; } else { output[pos] += sample; } }
// call this for the first channel void GeneratePercussion(bool opl3Mode, Chip chip, int[] output, int pos) { Channel chan = this; //BassDrum int mod = (int)((old[0] + old[1])) >> feedback; old[0] = old[1]; old[1] = Op(0).GetSample(mod); //When bassdrum is in AM mode first operator is ignored if ((chan.regC0 & 1) != 0) { mod = 0; } else { mod = old[0]; } int sample = Op(1).GetSample(mod); //Precalculate stuff used by other outputs uint noiseBit = chip.ForwardNoise() & 0x1; int c2 = Op(2).ForwardWave(); int c5 = Op(5).ForwardWave(); int phaseBit = (int)((((c2 & 0x88) ^ ((c2 << 5) & 0x80)) | ((c5 ^ (c5 << 2)) & 0x20)) != 0 ? 0x02 : 0x00); //Hi-Hat uint hhVol = Op(2).ForwardVolume(); if (!EnvSilent((int)hhVol)) { var hhIndex = ((phaseBit << 8) | (0x34 << (byte)(phaseBit ^ (noiseBit << 1)))); sample += Op(2).GetWave(hhIndex, hhVol); } //Snare Drum uint sdVol = Op(3).ForwardVolume(); if (!EnvSilent((int)sdVol)) { int sdIndex = (int)((0x100 + (c2 & 0x100)) ^ (noiseBit << 8)); sample += Op(3).GetWave(sdIndex, sdVol); } //Tom-tom sample += Op(4).GetSample(0); //Top-Cymbal uint tcVol = Op(5).ForwardVolume(); if (!EnvSilent((int)tcVol)) { var tcIndex = ((1 + phaseBit) << 8); sample += Op(5).GetWave(tcIndex, tcVol); } sample <<= 1; if (opl3Mode) { output[pos] += sample; output[pos + 1] += sample; } else { output[pos] += sample; } }