swan: Fix noise emulation
This commit is contained in:
parent
14bdbd852e
commit
c4561b15a5
|
@ -127,7 +127,6 @@ void swan_sound_out(swan_sound_t *snd, uint16_t port, uint8_t value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swan_sound_subtick(swan_sound_t *snd, uint32_t cycles) {
|
static void swan_sound_subtick(swan_sound_t *snd, uint32_t cycles) {
|
||||||
// TODO: Do period counters update when a channel is inactive?
|
|
||||||
for (int ch = 0; ch < 4; ch++) {
|
for (int ch = 0; ch < 4; ch++) {
|
||||||
if (snd->ch_ctrl & (1 << ch)) {
|
if (snd->ch_ctrl & (1 << ch)) {
|
||||||
snd->period_counter[ch] += cycles;
|
snd->period_counter[ch] += cycles;
|
||||||
|
@ -135,6 +134,12 @@ static void swan_sound_subtick(swan_sound_t *snd, uint32_t cycles) {
|
||||||
while (snd->period_counter[ch] >= step) {
|
while (snd->period_counter[ch] >= step) {
|
||||||
snd->sample_index[ch] = (snd->sample_index[ch] + 1) & 0x1F;
|
snd->sample_index[ch] = (snd->sample_index[ch] + 1) & 0x1F;
|
||||||
snd->period_counter[ch] -= step;
|
snd->period_counter[ch] -= step;
|
||||||
|
|
||||||
|
// Update noise counter
|
||||||
|
if (ch == 3 && (snd->ch_ctrl & SND_CH4_NOISE) && (snd->noise_ctrl & SND_NOISE_ENABLE)) {
|
||||||
|
uint8_t lfsr_new = (1 ^ (snd->noise_lfsr >> 7) ^ (snd->noise_lfsr >> lfsr_tap_bits[snd->noise_ctrl & 7])) & 0x1;
|
||||||
|
snd->noise_lfsr = (snd->noise_lfsr << 1) | lfsr_new;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,12 +183,6 @@ void swan_sound_tick(swan_sound_t *snd) {
|
||||||
// Update counters
|
// Update counters
|
||||||
swan_sound_subtick(snd, 128);
|
swan_sound_subtick(snd, 128);
|
||||||
|
|
||||||
// Update noise counter
|
|
||||||
if (snd->noise_ctrl & SND_NOISE_ENABLE) {
|
|
||||||
uint8_t lfsr_new = (1 ^ (snd->noise_lfsr >> 7) ^ (snd->noise_lfsr >> lfsr_tap_bits[snd->noise_ctrl & 7])) & 0x1;
|
|
||||||
snd->noise_lfsr = (snd->noise_lfsr << 1) | lfsr_new;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate synthesizer channels
|
// Calculate synthesizer channels
|
||||||
if (!(snd->test_flags & SND_TEST_HOLD_CH)) {
|
if (!(snd->test_flags & SND_TEST_HOLD_CH)) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
|
Loading…
Reference in a new issue