ValleyBell / libvgm

A more modular rewrite of most components from VGMPlay. will include sub-libraries for audio output, sound emulation and VGM playback
irc://irc.digibase.ca/#vgmrips
136 stars 33 forks source link

DC offset in audio #102

Closed westonlast closed 1 year ago

westonlast commented 1 year ago

In both https://www.foobar2000.org/components/view/foo_gep and https://ux.getuploader.com/foobar2000/download/213 there is a DC offset in the produced audio. Both of those are based on libvgm.

Sample files: https://smd.joshw.info/p/Phantasy%20Star%20II%20%5bPhantasy%20Star%20II%20-%20Kaerazaru%20Toki%20no%20Owari%20ni%5d%20(1989-03-21)(Sega%20Development%20Division%20%233)(Sega)%5bSMD%5d.7z

This DC offset makes my DAC mute its output.

ValleyBell commented 1 year ago

No, they are not based on libvgm.
They are based on VGMPlay 0.40.9, which is the version just before libvgm was created.

VGMPlay 0.50 and later are libvgm-based. Please check whether or not the issue happens with VGMPlay 0.51.0. Please also tell me what sound cores are used for emulating the YM2612 and SEGA VDP PSG.

EDIT: And: please mention example songs where the issue happens. Else I may pick the 2 or 3 songs from the pack that don't suffer from issues.

westonlast commented 1 year ago

I highly doubt the issue is related to only certain tracks. It's a core output level issue; most likely YM2612 core has a constant bias. I was using the "nuked" core, but who knows, it might not even be core-related.

ValleyBell commented 1 year ago

I will not debug your "doubts".

You can reopen the issue if the problem persists with an up-to-date VGMPlay. So far the bug report is invalid, as VGMPlay 0.40.9 is about 4 years old and with YM2612 cores received numerous updates since then.

Also, if I ask you to give specific information and examples, you should give me that information if you want me to take a serious look at the issue. You will not get away by making speculations.

djtuBIG-MaliceX commented 1 year ago

Also foo_gep and foo_input_vgm are hugely out of date - neither of which have not been (and for foo_gep, will not be) receiving any updates up until now, nor supported by libvgm.

westonlast commented 1 year ago

No reason to be an asshole about it. You're lucky I'm reporting anything at all. My invalid bug report is hardly an inconvenience to your lifestyle. Learn how to treat people well.

So you don't get a DC offset in VGMPlay? You probably haven't tested whether it does yet. I will when I find some time.

DeltaRazero commented 1 year ago

Pretty sure posting "it doesn't work how I want it to work" and subsequently not providing the information the developer needs certainly seems lile an inconvienance; it's wasting someone's already limited time on seriously wanting to fix actual problems. Learn how to treat developers well.

westonlast commented 1 year ago

image

Raw WAV log: image

Normalized: image

Seems to be a general problem, although maybe more prevalent with certain operators; normalized: image

ValleyBell commented 1 year ago

I finally found time to look at this.
Also: Congratulations - with all the information in the issue now, it is finally a good bug report!

I'm afraid that this is actually a bug of the game's DAC driver. Here is the waveform of the DAC channel: 08 - Restoration DAC The DAC driver has its "null" at value 0x40 (hex, equals -50% for unsigned 8-bit PCM). Notice how the DAC snaps to the real null-sample when it changes panning to "L only" or "R only".

Now, there are few things I'd like to mention:

  1. I don't consider the DC offset a libvgm bug. libvgm provides the final output of the YM2612's digital stage. And in that regard, the DC offset is 100% correct. (Also, the pops when muting/unmuting certain speakers happen ingame as well - you just don't notice them as much with all the music around it.)
  2. There would be a workaround for the D.C. offset, which is applying a high-pass filter. There may be an option for this eventually, but not right now.
    here is how the DAC channel looks with a 50 Hz highpass filter applied: 08 - Restoration DAC Highpass 50 Hz
  3. Audacity's "normalization" feature is not the best way to analyse DC offsets IMO.
    It seems to just calculate an average of all samples in the whole song and take the arithmetic middle as the "center". Temporary positive and negative spikes can affect this and cause a DC after the "correction".
    Just look how it butchers the hardware recording of a sine wave from one of my MIDI modules, which has definitely no DC offset due to the analog audio transfer between MIDI module and audio interface: MIDI_Sine
westonlast commented 1 year ago

Thanks @ValleyBell for looking into this. Sucks that this game is buggy in this way! I wonder how many other commercial games have similar audio bugs...

Yes I agree the player is reproducing the audio accurately. The one true fix would be to patch the game itself. I'm a little surprised no one else has noticed this bug in Phantasy Star II. My expensive DAC/Amp might just be shit.

In general I don't want to apply a highpass filter, because I'd like full reproduction of all low frequencies.

Again thank you for the analysis.