swan: Support higher frequency rates at the emulation core level

This commit is contained in:
Adrian Siekierka 2025-03-11 19:09:57 +01:00 committed by tildearrow
parent 99c022cd82
commit 652f3662af
3 changed files with 13 additions and 7 deletions

View file

@ -126,7 +126,7 @@ 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) {
void swan_sound_tick(swan_sound_t *snd, uint32_t cycles) {
for (int ch = 0; ch < 4; ch++) {
if (snd->ch_ctrl & (1 << ch)) {
snd->period_counter[ch] += cycles;
@ -179,10 +179,7 @@ static void voice_render_channel2(swan_sound_t *snd) {
}
// See https://ws.nesdev.org/wiki/Sound
void swan_sound_tick(swan_sound_t *snd) {
// Update counters
swan_sound_subtick(snd, 128);
void swan_sound_sample(swan_sound_t *snd) {
// Calculate synthesizer channels
if (!(snd->test_flags & SND_TEST_HOLD_CH)) {
for (int i = 0; i < 4; i++) {

View file

@ -83,7 +83,15 @@ extern "C" {
void swan_sound_init(swan_sound_t *snd, bool headphones);
uint8_t swan_sound_in(swan_sound_t *snd, uint16_t port);
void swan_sound_out(swan_sound_t *snd, uint16_t port, uint8_t value);
void swan_sound_tick(swan_sound_t *snd);
// The audio chip is typically clocked at 3072000 Hz, with a sample
// generated once every 128 cycles, for an audio frequency of 24000 Hz.
// To emit a sample in such a configuration, one should run:
//
// swan_sound_tick(&snd, 128);
// swan_sound_sample(&snd);
void swan_sound_tick(swan_sound_t *snd, uint32_t cycles);
void swan_sound_sample(swan_sound_t *snd);
#ifdef __cplusplus
}

View file

@ -96,7 +96,8 @@ void DivPlatformSwan::acquire(short** buf, size_t len) {
writes.pop();
}
swan_sound_tick(&ws);
swan_sound_tick(&ws, chipClock / rate);
swan_sound_sample(&ws);
// Update individual channel buffers
for (int i = 0; i < 4; i++) {