Sound 4 (Noise): Highest frequencies?

Discussion of programming and development for the original Game Boy and Game Boy Color.
Posts: 9659
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Sound 4 (Noise): Highest frequencies?

Post by lidnariq » Tue Sep 08, 2020 12:25 pm

To make those higher-pitched noises sound correct, you'll have to generate the audio differently for them.

The DMG's noise channel itself generates audio at 524288 Hz; you could also do that, and then lowpass and downsample it to for your soundcard.

If you were more comfortable with audio, you could do some math and precalculate the audio for these higher pitches, or you could just convert them to an attenuation factor and a corner frequency and use a generic white noise source. But as is ... the laziest option, by far, is to just replace "problematic" s and r with a different value that sounds more similar to the original despite the aliasing.

Posts: 6
Joined: Mon Sep 07, 2020 12:05 pm

Re: Sound 4 (Noise): Highest frequencies?

Post by Wolfattackx » Tue Sep 08, 2020 12:55 pm

How to downsample that. Like I don't know the maths to do that wiki does't help that much

Posts: 38
Joined: Thu Sep 03, 2020 12:56 am

Re: Sound 4 (Noise): Highest frequencies?

Post by none » Tue Sep 08, 2020 3:25 pm

That depends on the quality you want to get.

You can have good downsampling with quadratic interpolation.

It is easiest to do the interpolation / low pass filter / downsampling at the same time.

Some pseude code...

Code: Select all

for each position, sample in target buffer
   sample = fir_lowpass_filter(source_buffer, scale_sample_position)
where target_buffer has the downsampled frequency (eg. 44100 Hz), and source_buffer has the frequency you render the signal at (e. g. 524288 * 2 Hz).

scale_sample_position would be

Code: Select all

source_position = target_position * source_frequency / target_frequency
The sampling rate of the source buffer needs to be at least double the frequency of the source signal because of aliasing.

You would need to make sure that the interpolation (if you use any) happens when the filter samples from the source signal (meaning you need sub sample accuracy for the source position).

Also, the filter needs to be lowpass to a low enough frequency (in this case 22050 Hz) so that aliasing does not occur (or at least reduce amplitude above that range very much).

The math for building the filters is more complicated, and you would need to choose a filter that is good for this purpose. ... ebCode.txt

This contains code for making a few different FIR lowpass filters. Maybe one of those helps.

Post Reply