Quantcast
Channel: nesdev.org
Viewing all articles
Browse latest Browse all 746

Emulator Sound is Distorted and Can't Figure Out Why

$
0
0
Hello! I've been quietly lurking NESDev for quite some time developing my emulator for fun. I've gotten pretty far but sound has been a big struggle. I have managed to implement every sound channel successfully, the only problem is my audio is severely distorted. Some things sound OK but everything has some distortion somewhere. I do not know why this happens or what kind of distortion this is, if someone could take a listen and point me in the right direction I would be really appreciative :beer:

I have attached my top 3 soundtrack picks as to where it is most prominent. (also please be careful these files are loud, I haven't played with volume too much sorry)
And what it should sound like:

https://www.youtube.com/watch?v=JY23DZxEBV0

(two other good examples)
https://www.youtube.com/watch?v=uyMKWJ5e1kg
https://www.youtube.com/watch?v=-JGkPieR6nk

This is my first time programming with sound so I really don't know what to make of this, I'll give a quick rundown on how I generate sound.

First I have followed this guide: https://www.nesdev.org/apu_ref.txt and have successfully implemented each channel and the corresponding DAC output function which outputs a float between 0 and 1.0.

Then I take 1 sample for every apu step and every 41 samples I average them all out as suggested by Disch in this thread: viewtopic.php?t=4011

I then send this sample out to an SDL audio buffer of size 800 samples. Initially I sent the float value of 0.0-1.0 directly to the SDL engine using AUDIO_F32SYS type, but I also tried AUDIO_U16SYS (by converting the sample as such: uint16_t sample = ~0; sample *= float_value). There was no audible difference from my perspective.

I also double up on samples once every 64 samples or so in order to reduce sample loss but I haven't heard any difference in the distortion either way.

Is my audio clipping? Is averaging every 41 samples causing too much aliasing which is causing this distortion? Any insight or answers to my questions would be super helpful!

Statistics: Posted by NowhereToGo — Sun Apr 28, 2024 7:16 am — Replies 5 — Views 295



Viewing all articles
Browse latest Browse all 746

Trending Articles