Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faint humming (buzz) sound while running a game (HDMI RetroArch & RetroPie) #13

Closed
nanoant opened this issue Nov 3, 2017 · 14 comments
Closed

Comments

@nanoant
Copy link

nanoant commented Nov 3, 2017

I have recently managed to run Atari800 on my NVIDIA Shield TV with 2 PRs merged to libretro version libretro/libretro-atari800#9 libretro/libretro-atari800#10

Everything works great except rather faint humming (buzz) sound emitted by atari800 emulator when running. Sound goes via HDMI output, so it is not analog/hw problem, also no other emulators or Android apps exhibit this problem on my box.

I have also found another user having exactly same problem but in RetroPie, completely different hardware and platform, so I suppose it makes sense to blame atari800 emulator.

https://retropie.org.uk/forum/topic/6927/atari800-5200-emulation-faint-humming-sound-while-running-a-game

Is it some well known problem? Is there any workaround? (except rather ugly workaround removing the humming sound via equalizer or some DSP filter).

@knik0
Copy link
Member

knik0 commented Nov 3, 2017

I have a guess, normally when running, atai800 puts full range DC voltage on the audio output, it might cause a buzz in some amplifiers.

If you tested recent build of atari800 with -volume option, something like atari800 -volume 10 it could reduce the buzz.

@nanoant
Copy link
Author

nanoant commented Nov 5, 2017

Update

I think I know the reason, I have dumped atari800 generated sound into WAV and I found out that silence is not in fact a silence uint8 == 128 (signed zero), but 33 instead !!! (-75%), moreover it seems that the wave is not zero aligned also for non-silent parts but biased towards negative, see sshot below.

atari800wav

So altogether it looks like a bug, and I can expect that depending on the device, playing negative constant value instead zero for silence can produce so unpleasant (humming, buzz) effects.

@knik0
Copy link
Member

knik0 commented Nov 6, 2017

Ah, you just confirmed what I said earlier.
Apparently you have piss-poor audio amp in your hdmi receiver.

@nanoant
Copy link
Author

nanoant commented Nov 6, 2017

@knik0 Yeah that might be, it is just high-tier Samsung TV that I got as a present 😉 But I anyway I don't see why the amp is to blame if the audio signal is a mess, -75% constant DC for a silence is definitely not right.
Is physical Atari generating such a bizarre signal too?

@knik0
Copy link
Member

knik0 commented Nov 6, 2017

I guess it was done this way to maximize output volume.
AFAIK the real Atari was producing sound it a similar way. It is sometimes used to play digitized samples.
I guess it can be fixed after reducing sound volume, I mean output range 0.0 to 1.0 instead of -1.0 to 1.0

@joysfera
Copy link
Member

joysfera commented Nov 6, 2017

Sounds like we should make this change and make it configurable. Sound issues are the last thing we want in Atari800.

@nanoant
Copy link
Author

nanoant commented Nov 14, 2017

I think the source of weird 33 silence value is mkpokeysnd.c turning generate_sample() double into 8-bit value (let's skip 16-bit case for now):

buffer[0] = (UBYTE)floor((generate_sample(pokey_states) - MAX_SAMPLE / 2.0)
* (255.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);

It is easy to see the regardless of MAX_SAMPLE, feeding the formula above with zero gets us 33!

Now the question is what is the value range of generate_sample() - is it signed [-MAX_SAMPLE .. MAX_SAMPLE] or unsigned [0 .. MAX_SAMPLE]?

If it is unsigned, why generate_sample() does produce 0 for silence, not MAX_SAMPLE/2?

If it is signed then the formula above is incorrect, it should be instead:

buffer[0] = (UBYTE)floor(generate_sample(pokey_states)
* (128.0 / MAX_SAMPLE / 4 * M_PI * 0.95) + 128.0 + 0.5 + 0.5 * rand() / RAND_MAX - 0.25);

According to the "Master gain and DC offset calculation" description in the big comment block, it is more likely signed, talking about input range of [-60 .. 60] for resampler.

Thoughts?

@nanoant
Copy link
Author

nanoant commented Feb 2, 2018

Sorry for hammering in there, but is there any chance to get this fixed? This DC bias humming is really annoying.

@mikrosk
Copy link
Member

mikrosk commented Feb 2, 2018

I'm absolutely no expert in this area but I wouldn't be surprised if the formula isn't correct. For instance I had to fix similar signed/unsigned problem when specifying certain compilation flags: 4024d49

@joysfera
Copy link
Member

joysfera commented Feb 5, 2018

I'd like to get this issue fixed before releasing new Atari800 version. How can I help?
@nanoant have you tested your proposed formula by dumping the resulting WAV and looking at it?

@joysfera
Copy link
Member

joysfera commented Apr 21, 2018

I'm looking into this. The generated samples (before the above mentioned conversion) are not signed/unsigned but rather "digital" with logical 0 and 1. Silence is generated as precise 0 while simple sound (say Pokey Self test sound of single channel) generates levels - the low is around 0 and the high is around 38 with slight oscillations (so the low can go below zero slightly).
Full four channel music (Jet Set Willy) then oscillates between -16 and 113.

The above mentioned conversion by @nanoant is actually working exactly as on real Atari computer (I have checked output of Atari 130 XE with oscilloscope, it looks just like the WAV from the emulator). This is great for the emulator accuracy but I can imagine a modern TV set might mis-interpret the silence that is not at zero level. I may try shifting it up a bit.

joysfera added a commit that referenced this issue Apr 21, 2018
Fixes issue #13. The price for this is lower total volume.
@joysfera
Copy link
Member

Hopefully fixed in the 4.0.0 release. Thanks for reporting it.

@asiekierka
Copy link
Contributor

asiekierka commented Apr 27, 2018

I believe this should be a configuration option (on by default, as there is no perceptible difference beyond loudness, but configurable), especially as the real hardware does behave in this way, meaning patching it to act differently equates not trying to mimic real hardware as close as possible.

Is there any hope for it becoming such? Perhaps making the "-volume" parameter go from 0 to 200 (where 100-200 move the baseline down, where 200 matches real hardware) as opposed to 0 to 100?

@joysfera
Copy link
Member

I wouldn't make it configurable unless the current (v4.0.0) setup creates any issue.
Atari computers had a lot of hardware shortcomings that we don't emulate either - like say PAL signal on video output that is not exactly compatible with the norm (and some modern TV sets have issues with that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants