Hi folks,
I'm developing my NES emulator and I've reached the point of implementing the APU (CPU, PPU, controls, some main mappers are all done, so I can play many games already). The emulation is performed by a thread with a busy loop that sleeps roughly 186ns, leading to the PPU NTSC frequency (3x faster than the CPU). Apparently the timing is correct (emulated games run visually fine, but I didn't measured precisely the Clock speed).... anyways, regarding the APU I've fully implemented: Pulse Channels (PWM), Triangle and Noise channels... If I run simple tests, like some square (or triangle) waves with a fixed frequency, the sound looks really fine... but when I try to run complex games, like SMB, it looks like sound is not running on proper sample rate (see video in attachment).
I'm using SDL with an audio callback:
- Sample rate: 44100
- Audio type: AUDIO_U16 (unsigned 16 bits int)
- Buffer size: 2048 samples
In theory I should have 44100 samples per second (44100 Hz), while the frequency of the APU Clock is roughly 40x faster... so my audio callback function looks like this:
Am I following the right approach with this algorithm? Does anybody have any clue about the issue, i.e., why the sound looks running in a slower speed than the one expected?
Any help is really appreciated!
Cheers;
I'm developing my NES emulator and I've reached the point of implementing the APU (CPU, PPU, controls, some main mappers are all done, so I can play many games already). The emulation is performed by a thread with a busy loop that sleeps roughly 186ns, leading to the PPU NTSC frequency (3x faster than the CPU). Apparently the timing is correct (emulated games run visually fine, but I didn't measured precisely the Clock speed).... anyways, regarding the APU I've fully implemented: Pulse Channels (PWM), Triangle and Noise channels... If I run simple tests, like some square (or triangle) waves with a fixed frequency, the sound looks really fine... but when I try to run complex games, like SMB, it looks like sound is not running on proper sample rate (see video in attachment).
I'm using SDL with an audio callback:
- Sample rate: 44100
- Audio type: AUDIO_U16 (unsigned 16 bits int)
- Buffer size: 2048 samples
In theory I should have 44100 samples per second (44100 Hz), while the frequency of the APU Clock is roughly 40x faster... so my audio callback function looks like this:
Code:
audio_callback() { for (int i = 0; i < number_of_samples; i++) { for (int j = 0; j < 40; j++) { apu_clock(); } audio_buffer[i] = get_apu_output(); }}
Any help is really appreciated!
Cheers;
Statistics: Posted by renesp — Sun Jul 28, 2024 7:49 am — Replies 1 — Views 32