-
Notifications
You must be signed in to change notification settings - Fork 37
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
Fixes for broken Lowpass Filter #25
base: master
Are you sure you want to change the base?
Conversation
add simpler better sounding IIR lowpass
|
Here is a sound comparison of Bubble Bobble with the old and new lowpass filters. I think it should make clear the issue I am describing regarding distortion: |
|
The broken freebsd build appears to be a pre-existing condition and not related to my PR. |
|
I made a recording of my 1040STF and the 4 filter options for comparison: Each contains 16 seconds of audio, 2 excerpts from Bubble Bobble, the start of the tune at boot, and the introduction jingle that starts when you press the "1" or "2" key to begin the game. I would recommend listening to them side by side, or line them up in an audio-editor and switch between them to compare. There are 5 recordings:
Commentary:
The comments in the code indicate some theoretical basis of circuit modelling for the LPF_STF and PWM filters, but I think in practice at least the LPF_STF one does do not sound anything at all like the machine they are intended to emulate. I can't offer direct commentary on the PWM version because I do not have an STE or Falcon to record, but since its filter implementation is a direct modification of LPF_STF (disabling the filter for half of its input phase), I suspect it may suffer from the same problem of introducing uncharacteristic amounts of distortion. Unfortunately I do not have a theoretical model to substitute at this time, I am only offering a simpler model of a standard RC lowpass filter, derived from the existing LPF_STF filter but removing the part that causes distortion by operating on the two phases asymmetrically. However, theory or not, ultimately the theory is no good if it leads us to the wrong sound. I would love to see a re-evaluation of the circuitry, and to test a new model against reference hardware recordings, but for now I want to suggest the new filter as a default, as I think it does sound much closer in the STF case, and otherwise is a more pleasant sound. . Some additional recordings of Falcon and STE were provided by Anders Eriksson on the mailing list: |
…he configuration options.
|
@npomarede : Could you please have a look when you've got some spare time? Thanks! |
|
Current status: I still feel the changes above are complete and worthwhile as-is, but after some disccusion from the mailing list, I wished to do some further hardware recording tests and comparisons to help justify the change. The complaint was that the old method had a theoretical basis, attempting to model a function of the YM's current output, whereas my intended replacement is instead a simple lowpass filter, based only on empirical observations of recorded hardware output. Some clarification was given as to where the theory for the existing filters came from: My belief is this theory about the asymmetrical output is incorrect, or at least over-emphasizing its effect, leading to the very distorted sound of the current implementation. My plan is to write a test program that can be run on hardware that should demonstrate the theoretical asymmetry in a way that can be measured easily from an audio recording. This would help evaluate whether, and by how much, the old method may be divergent from the real hardware, and could possibly lead to a better theoretical understanding of how to model the output in a way that more closely matches it. |
|
Thanks for looking into, hopefully this will help to understand the nature of the filter (but it might not be possible to change filters before Hatari 2.5 is released) |

I had created an atari-forum thread to mention this issue but I just noticed that Hatari has a github mirror, so I've decided to present it as a pull request here.
This PR addresses two issues.
Issue 1: Lowpass Filter Samplerate
When the sound emulation was updated to work with an internal 250 kHz buffer, the lowpass filters which were designed with coefficients for audio-output samplerate frequencies were not updated and are now operating at a much higher frequency.
The result is that the lowpass filter is effectively disabled, by having a cutoff that's about 5x too high, above the range of hearing. There is a lot of undesirable high frequency noise/aliasing in Hatari's current audio output.
The fix for this is straightforward. In
sound.cI moved the application of the lowpass filters intoYM2149_NextSample_250, which is where Hatari downsamples the 250 kHz into the audio output samplerate. The filters now function as they did before here.Issue 2: Lowpass Filter Quality
The second problem is that the existing
LowPassFilterandPWMaliasPassFilter(current default) both produces an extremely distorted sound due to the nature of their implementation.The comments attached to them indicate that they may have some theoretical basis in modelling an asymmetrical push-pull amplifier circuit in the ST. However, the resulting sound is extremely harsh and distorted. I have compared Hatari's output against many recordings of real ST hardware (my own and others) and I do not feel that it accurately matches any of them. It is much more distorted.
There may exist real hardware that does sound this distorted, but in my experience this sound is not representative, and furthermore it is unpleasant and drastically reduces the quality of the audio in Hatari.
Provide a new default lowpass filter
IIRLowPassFilterwhich gives a simpler symmetrical IIR, applying the same cutoff frequency as one of the two phases ofPWMaliasPassFilterwithout the discontinuity of switching between two different phases. The result is a normal, clean sounding, standard lowpass filter effect.Add
YmLpfandYmHpfto the configuration set, so that users can select which of the existing Lowpass or Highpass filters should be used. We are already selecting them in software, but it was never exposed to the user. This allows anyone who prefers a past behaviour to select it instead of the default in their configuration files.YmLpfsettings:0 = YM2149_LPF_FILTER_NONE- Reproduces the current behaviour of a disabled lowpass.1 = YM2149_LPF_FILTER_LPF_STF- An older LPF used before PWM became the default?2 = YM2149_LPF_FILTER_PWM- The current default.3 = YM2149_LPF_FILTER_IIR- The new default, a clean lowpass filter.YmHpfsettings:0 = YM2149_HPF_FILTER_NONE- Disable the highpass.1 = YM2149_HPF_FILTER_IIR- The default.The existing highpass filter was not affected by the samplerate problem, as it was already being applied at the audio samplerate.