GB Audio: Optimize channel 4

This commit is contained in:
Vicki Pfau 2022-06-02 23:26:15 -07:00
parent c19457aa4b
commit 46b59268d3
1 changed files with 16 additions and 5 deletions

View File

@ -568,13 +568,24 @@ void GBAudioRun(struct GBAudio* audio, int32_t timestamp, int channels) {
int32_t last = 0;
int32_t diff = timestamp - audio->ch4.lastEvent;
int samples = 0;
int positiveSamples = 0;
int lsb;
int coeff = 0x60;
if (!audio->ch4.power) {
coeff <<= 8;
}
for (; last + cycles <= diff; last += cycles) {
int lsb = audio->ch4.lfsr & 1;
audio->ch4.sample = lsb * audio->ch4.envelope.currentVolume;
++audio->ch4.nSamples;
audio->ch4.samples += audio->ch4.sample;
lsb = audio->ch4.lfsr & 1;
audio->ch4.lfsr >>= 1;
audio->ch4.lfsr ^= (lsb * 0x60) << (audio->ch4.power ? 0 : 8);
audio->ch4.lfsr ^= lsb * coeff;
++samples;
positiveSamples += lsb;
}
if (samples) {
audio->ch4.sample = lsb * audio->ch4.envelope.currentVolume;
audio->ch4.nSamples += samples;
audio->ch4.samples += positiveSamples * audio->ch4.envelope.currentVolume;
}
audio->ch4.lastEvent += last;