APU Emulation

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
APU Emulation
by on (#1573)
As disch told me im emulating the APU and taking te output every 41 opcodes cycles aprox. Every time i take the out put i fill an array of byte representing the wave (PCM), then when buffer reach 2048 i play it (direct sound). But as disch told me its a poor sound quality. Any suggestions to make the playback better?

by on (#1574)
Step 1: Try a box filter. Take the output of every APU cycle during each sample period (40-41 samples[1]) and average them before writing them to the buffer. This will improve the quality of your emulator's noise and high-pitched tones.

There is a step 2 that results in further improvement, but to understand it, you'll need to have the experience from step 1 as well as a background in digital signal processing.

[1] To get proper pitch, you'll need to alternate between 40 and 41 samples.

by on (#1575)
what do you mean with "average"?

by on (#1576)
You sum the volumes over a specific amount of cycles and then divide the result by the amount of cycles. Like so:

Code:
amp = 0;

for (i = 0; i < cycles; i ++)
{

amp += get_channel_volume_at_cycle (i);

}

sample = amp / cycles;


The resulting sample is then written to the sound buffer, so that it can be output by your audio card.

by on (#1577)
thanks hyde