nukeykt / Nuked-SC55

Roland SC-55 series emulation
Other
383 stars 40 forks source link

Weird ringing in sound #19

Open pachuco opened 6 months ago

pachuco commented 6 months ago

I do not have an actual SC55 to confirm this, but there is a strange high pitched ringing in the sound, as if interpolation is borked.

I've attached two files in this zip. The one with _hp suffix is filtered in audio editor to isolate the perceived flaw. The other one is plain recording.

ringadingadingdong.zip

Platform is xp sp3 x86.

pachuco commented 6 months ago

the_stink_files.zip

nukeykt commented 6 months ago

Perhaps XP has crappy audio resampling, sc-55mkII outputs non standard 66207hz audio

pachuco commented 6 months ago

Oh, that makes sense then. Maybe I should shove an inline resampler at the output. I've had positive experiences before with snes gaussian on the OPL3, but maybe sinc would be better fit.

datajake1999 commented 6 months ago

If I ever get around to writing a VST based on Nuked SC-55, I plan on integrating the Blargg resampler library, which I forked at https://github.com/datajake1999/blargg_resampler. It is a decent resampler that uses sinc interpolation.

johnnovak commented 6 months ago

We've been using the Speex resampler (libspeex) in DOSBox Staging with very good results at quality setting 5. That setting is basically transparent on normal musical material for most normal people (except on specially prepared material when A/B-ing it in studio headphones, but even then the difference is extremely hard to spot).

It's very fast, even on low-end hardware like the Raspberry Pi 3, so my recommendation.

https://speex.org/docs/manual/speex-manual/node7.html#SECTION00760000000000000000

Gerwin2k commented 5 months ago

I am having similar trouble, but more so. Much more ringing/distortion in Windows 7 x64 official builds. Exactly the same with my Windows XP x86 builds (same on two entirely different systems). Only my Linux x64 build sound good, which kinda proves that the code and ROMs are not borked. CPU usage is not even that much; Below 50% of one core.

I made .wav files with the same 66207Hz and 64000Hz sample rates, which play fine in different sound players. Still investigating... Maybe SDL2 specific.

pachuco commented 5 months ago

You are at mercy of OS/driver's interpolation.

On my X86 XP, different results from default audio driver and Virtual Audio Cable. VAC does linear interpolation, I think, while default audio(SB Audigy LE) does nearest.

Gerwin2k commented 5 months ago

Both systems I mentioned use a Realtek audio chipset. I could maybe switch to the AMD graphics HDMI audio for testing. I would like to test more systems at the office, but I don't want to install loopmidi on these for just a quick test.

Earlier I looked up details on Windows XP sound resampling, and it suggested that this OS switches to the actual sample rate when the hardware supports it, and when no other sound is playing.

johnnovak commented 5 months ago

As me and some others mentioned, the answer is a built-in resampler. SpeexDSP is great, fast, and easy to use. It is the resampler that PulseAudio uses on Linux, from memory.

Btw, my Realtek driver on Win10 deals with the unorthodox rate just fine, no issues.

Gerwin2k commented 5 months ago

It would be interesting to test with an embedded resampler. Though I also have some evidence it is actually something else:

But because I am seemingly one of the very few with this problem, I suppose I have to be investigate myself or be patient.

pachuco commented 5 months ago

@johnnovak

I've tried shoving in a resampler but I can't seem to not mess up the thin balance between the audio thread and the work thread. What's the sicrit?

johnnovak commented 5 months ago

@johnnovak

I've tried shoving in a resampler but I can't seem to not mess up the thin balance between the audio thread and the work thread. What's the sicrit?

Haven't looked at the code, but most likely the way the threading is done is not great to begin with, then the extra overhead from the resampler might push it over the limit.

Make sure to use an efficient resampler. We use Speex all over the place in DOSBox Staging and there's threading involved etc. In our case, there's a render thread that gets MIDI messages and fills the buffer at whatever native rates, then the mixer and resampler is in another thread. That's what you want; don't overload the rendering thread even more.

Gerwin2k commented 5 months ago

I am finally listening to some reasonably good audio output. This made the difference: //static const int audio_page_size = 512; static const int audio_page_size = 2048;