"Peace Audio Synthesizer" Scriptable NES sound emulation

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
"Peace Audio Synthesizer" Scriptable NES sound emulation
by on (#108193)
Hello!!

I would like to introduce "Peace Synthesizer Framework"
It support NES/Famicom sound emulation with customizable Visualization and DSP


#Demo


Vampire Killer - Castlevania #NES Stereolization process in "Peace Audio Synthesizer"

http://www.youtube.com/watch?v=1YqyFx5VKf4



Thanks!!
-------------------------------------------------------------------
http://peacedeveloper.appspot.com/
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108223)
Please use something like blipbuf for audio synthesis if possible.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108257)
May i ask why blipbuf ?
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108259)
BLEP (band-limited step) resampling, the technique used by blip-buf, is a way to eliminate aliasing from a signal when downsampling from the 1.79 MHz CPU frequency to 44100 or 48000 or whatever target frequency. It works by decomposing a signal into a sum of Heaviside steps, low-pass filtering a single representative step, sampling that filtered step at various fractions of an output sample, and adding up all the steps. For example, a square wave at 250 Hz has 500 steps per second: 250 rises and 250 falls.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108267)
Why use something like blipbuf? Because otherwise the sound has a scratchy quality (due to aliasing) which pollutes the crystal-clear sound of the NES. This was evident in the recording you posted. I just wanted to bring it to your attention.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108270)
tepples wrote:
BLEP (band-limited step) resampling, the technique used by blip-buf, is a way to eliminate aliasing from a signal when downsampling from the 1.79 MHz CPU frequency to 44100 or 48000 or whatever target frequency. It works by decomposing a signal into a sum of Heaviside steps, low-pass filtering a single representative step, sampling that filtered step at various fractions of an output sample, and adding up all the steps. For example, a square wave at 250 Hz has 500 steps per second: 250 rises and 250 falls.


Thank you very much
This is something very useful
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108276)
blargg wrote:
Why use something like blipbuf? Because otherwise the sound has a scratchy quality (due to aliasing) which pollutes the crystal-clear sound of the NES. This was evident in the recording you posted. I just wanted to bring it to your attention.


Are there any proof of audible alias which generate by sampling in 44100 hz?
I see when visualize or analyse them I can found it easily.
However by hearing as for me it not much different.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108279)
The NES is actually generating audio at ~1.79MHz (that's megahertz, not kilohertz). Any other sample rate will be a resampled version of that.
If you use nearest-neighbor resampling, it sounds awful. Using linear interpolation doesn't sound too bad, but is still somewhat distorted. Bandlimited interpolation (what Blargg is doing) works best.
Blip-buffer also uses a clever programming trick to make the sound synthesis run really fast, it stores the wave as volume differences instead of volume levels, then converts back to volume levels before you play it.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108282)
peacedev wrote:
blargg wrote:
Why use something like blipbuf? Because otherwise the sound has a scratchy quality (due to aliasing) which pollutes the crystal-clear sound of the NES. This was evident in the recording you posted. I just wanted to bring it to your attention.


Are there any proof of audible alias which generate by sampling in 44100 hz?
I see when visualize or analyse them I can found it easily.
However by hearing as for me it not much different.

Try synthesizing (naively) a single square wave sweeping from 0 -> Nyquist (22050Hz) and you'll certainly hear it.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108286)
Yeah, I think it sounds awful when an emu has aliasing in its sound !

Fortunately it seems most NES emus solved this issue, but most GB/GBC/GBA emus does not. Even VBA which is the most popular GB/GBC/GBA have aliasing in it's sound. Result : All games which uses the game boy channels sounds bad. Even GBS players does have aliasing. :(
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108287)
thefox wrote:
peacedev wrote:
blargg wrote:
Why use something like blipbuf? Because otherwise the sound has a scratchy quality (due to aliasing) which pollutes the crystal-clear sound of the NES. This was evident in the recording you posted. I just wanted to bring it to your attention.


Are there any proof of audible alias which generate by sampling in 44100 hz?
I see when visualize or analyse them I can found it easily.
However by hearing as for me it not much different.

Try synthesizing (naively) a single square wave sweeping from 0 -> Nyquist (22050Hz) and you'll certainly hear it.



Now I notice it, This may cause my sound distortion as well. Thanks a lot.
Will post lowpass/band pass filter help ? instead of bandlimiting
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108299)
Bregalad wrote:
Fortunately it seems most NES emus solved this issue, but most GB/GBC/GBA emus does not. Even VBA which is the most popular GB/GBC/GBA have aliasing in it's sound.

The NES output path has natural antialiasing, with a low-pass filter in the RF box. GBA and DS, on the other hand, use a PWM DAC at around 32.8 kHz that itself introduces aliasing. GBA emulators and GSF players just treat it as if it were a 44 or 48 kHz DAC. The GBA uses a higher sampling frequency (262 kHz) in GBC mode, and emulators and GBS players should in theory be sampling at that rate and using BLEP downsampling to hit 44/48 kHz.

peacedev: Band-pass (or low-pass) and band-limiting mean pretty much the same thing. BLEP is just an efficient technique to implement a combined low-pass filter and decimation for square-like waves such as the output of second- and third-generation consoles' APU.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108300)
tepples wrote:
Bregalad wrote:
Fortunately it seems most NES emus solved this issue, but most GB/GBC/GBA emus does not. Even VBA which is the most popular GB/GBC/GBA have aliasing in it's sound.

The NES output path has natural antialiasing, with a low-pass filter in the RF box. GBA and DS, on the other hand, use a PWM DAC at around 32.8 kHz that itself introduces aliasing. GBA emulators and GSF players just treat it as if it were a 44 or 48 kHz DAC. The GBA uses a higher sampling frequency (262 kHz) in GBC mode, and emulators and GBS players should in theory be sampling at that rate and using BLEP downsampling to hit 44/48 kHz.

peacedev: Band-pass (or low-pass) and band-limiting mean pretty much the same thing. BLEP is just an efficient technique to implement a combined low-pass filter and decimation for square-like waves such as the output of second- and third-generation consoles' APU.



Thank you very much.
You are very cool person :)
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108302)
Quote:
GBA and DS, on the other hand, use a PWM DAC at around 32.8 kHz that itself introduces aliasing.

Does this apply to GB sound too ? I tought only the Direct Sound channels were affected by this.

At least I once made a test using the multiple available frequencies for the GBA PWM, and it turned out that while this affected strongly the Direct Sound channels (in a way that remains completely unemulated by the way), I remember it did not affect the GB soud in an audible way.
This was with my DS though - it's hard to record sound directly from the GBA SP now that my adapter has broken down.

Basically those were the results :
32 kHz PWM - 9 bits = horrible sound with lot of aliasing
64 kHz PWM - 8 bits = okay sound
128 kHz PWM - 7 bits = mediocre when the sound is quiet because of quantization
256 kHz PWM - 6 bits = Horrible sound because of quantization.

Link : http://dl.dropbox.com/u/23465629/GBA_junk/gba_test_samples.7z
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108305)
blargg wrote:
Why use something like blipbuf? Because otherwise the sound has a scratchy quality (due to aliasing) which pollutes the crystal-clear sound of the NES. This was evident in the recording you posted. I just wanted to bring it to your attention.

Is there a simple test-case for this (i.e., some game music that highlights the scratchy quality)? The Solstice intro, for example, is a good test-case for filtering out too-high frequencies.

I'm emulating the sound channels at 1.79MHz, low-pass filtering with a 512-tap FIR filter, and downsampling by 37 to get ~48kHz output. I suppose I haven't compared with a critical ear, but I don't notice any particularly scratchy differences between this method and the blipbuf method that I currently previously used.

(Note that I'm not trying to say that my method is better; it's certainly not from a CPU utilization perspective. I don't understand the blipbuf method well enough to re-implement it, and my goal was to build something sans copy-paste code/libraries).

edit: typo
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108306)
James wrote:
I'm emulating the sound channels at 1.79MHz, low-pass filtering with a 512-tap FIR filter, and downsampling by 37 to get ~48kHz output. I suppose I haven't compared with a critical ear, but I don't notice any particularly scratchy differences between this method and the blipbuf method that I currently used.

Your method is fine, there's no audible aliasing when doing that. It's basically the same thing that the real NES is doing.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108317)
Blipbuf is basically a space-for-time optimization; by memoizing the result of all the lowpassed edges, you can just natively generate audio at the sample rate, rather than needing to generate all 1.8MS/s and lowpass it.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108331)
peacedev, bandlimited synthesis is key here. This is just emulating at the NES rate, lowpass filtering with cutoff below half the output sampling rate (Nyquist frequency), then decimating. James does this literally (going by his description), and blipbuf turns the algorithm inside-out and does the same thing with a fraction of the computing power. You have to do the lowpass before decimating (downsampling); yoiu can't just do it on the output, because aliasing has already corrupted the output with spurious frequencies all throughout the audible band.

Maybe someone could write an aliasing test that plays a clean frequency sweep up beyond audible.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108344)
Now with luck, I am able to integrate bandlimited to wave form generation.

Here is the result.
https://dl.dropbox.com/u/30815442/downl ... 08-0_3.mp3
and
https://dl.dropbox.com/u/30815442/downl ... -solid.mp3

May I ask for your opinion ?
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108361)
It's hard to tell with the material you're using. Can you do a simple mono frequency sweep from 100 Hz to 30000 Hz, lasting say 20 seconds? If you have a program to show the frequency spectrum, aliasing is really easy to spot (I've moved to Linux and am not familiar yet with one to do this). Try that with the square, and with the triangle (separately). I'm also curious as to how you've implemented bandlimiting.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108363)
blargg wrote:
It's hard to tell with the material you're using.

What's obvious though, is that there's some other problem in your emulation not related to aliasing. The music sounds choppy (almost seems like timing is off, but could be just wrong note lengths or something playing with my ears).
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108369)
Yeah, that's distracting when listening to familiar material like the beginning Castlevania. I take it that this thing is scripted at the command-line level, thus timing will necessarily be pretty jittery.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108372)
blargg wrote:
If you have a program to show the frequency spectrum, aliasing is really easy to spot (I've moved to Linux and am not familiar yet with one to do this).
Audacity is cross-platform and works nicely for this. (Click on the name of the track in the upper-left corner of the waveform, and select "spectrogram")
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108378)
blargg wrote:
It's hard to tell with the material you're using. Can you do a simple mono frequency sweep from 100 Hz to 30000 Hz, lasting say 20 seconds? If you have a program to show the frequency spectrum, aliasing is really easy to spot (I've moved to Linux and am not familiar yet with one to do this). Try that with the square, and with the triangle (separately). I'm also curious as to how you've implemented bandlimiting.




Using Impulse training method with my own tweaks.
I already run tests in native square wave and alias was gone well.
I can see now wave shape was altered.

Like you said, In general (not by testing freq sweep) the alias thing is hard to detect by human ear.
I wonder if it really worth to use bandlimitting in typical conditions.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108379)
thefox wrote:
blargg wrote:
It's hard to tell with the material you're using.

What's obvious though, is that there's some other problem in your emulation not related to aliasing. The music sounds choppy (almost seems like timing is off, but could be just wrong note lengths or something playing with my ears).



It is realtime parsing data. It cause latency some time.
I will improve this later with compile time. Thanks for notify.
Re: "Peace Audio Synthesizer" Scriptable NES sound emulatio
by on (#108481)
After Optimization !!!!


https://dl.dropbox.com/u/30815442/downl ... imized.mp3


Now I am very happy with the result after tuneup. Thank you very much for all comment !!!!!



:lol: :lol: :lol: :lol: