Some advice of DSP here...
Moderator: Moderators
Some advice of DSP here...
As we know the NES generate sound at CPU cc freq, so if i have 44100 in my hardware i take it every 40.5~ so clocks.
I have been searching the web for info of sound filters, wich lead me to a bounch of DSP info wich i don't understand very well.
My question is: wich filter is the best for the best sound??
I have been searching the web for info of sound filters, wich lead me to a bounch of DSP info wich i don't understand very well.
My question is: wich filter is the best for the best sound??
ANes
Re: Some advice of DSP here...
The best one to use is the one that you know how to implement
The simplest and wrongest way to generate audio is to just natively calculate everything at the target rate. This will produce ... passable, if lackluster, results. Pitches will be right, but there will be audible aliasing, and the higher frequencies on the noise channel will be wrong.
The simplest and not-wrong way is to generate the audio at the NES's native 1.79MHz, and use a sharp lowpass starting at ≈10kHz (such as a very long FIR filter, or some IIR filter like an elliptic, Chebychev, or Butterworth).
Slightly more complex is to generate the audio at the NES's native 1.79, and use a "decimating FIR lowpass filter".
Even more complex is do something like blargg's blip_buffer, which precalculates things such that it can natively generate audio at the target rate. Going into how it works is out of scope, for now.
The simplest and wrongest way to generate audio is to just natively calculate everything at the target rate. This will produce ... passable, if lackluster, results. Pitches will be right, but there will be audible aliasing, and the higher frequencies on the noise channel will be wrong.
The simplest and not-wrong way is to generate the audio at the NES's native 1.79MHz, and use a sharp lowpass starting at ≈10kHz (such as a very long FIR filter, or some IIR filter like an elliptic, Chebychev, or Butterworth).
Slightly more complex is to generate the audio at the NES's native 1.79, and use a "decimating FIR lowpass filter".
Even more complex is do something like blargg's blip_buffer, which precalculates things such that it can natively generate audio at the target rate. Going into how it works is out of scope, for now.
Re: Some advice of DSP here...
Of course you don't have to understand how it works to be able to use it. Even if you're writing an emulator, you don't have to implement absolutely everything yourself.lidnariq wrote:Even more complex is do something like blargg's blip_buffer, which precalculates things such that it can natively generate audio at the target rate. Going into how it works is out of scope, for now.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Re: Some advice of DSP here...
I really suck about DSP. Any good advice/book/article/link to start with??lidnariq wrote:The simplest and not-wrong way is to generate the audio at the NES's native 1.79MHz, and use a sharp lowpass starting at ≈10kHz (such as a very long FIR filter, or some IIR filter like an elliptic, Chebychev, or Butterworth).
ANes
- Jarhmander
- Formerly ~J-@D!~
- Posts: 569
- Joined: Sun Mar 12, 2006 12:36 am
- Location: Rive nord de Montréal
Re: Some advice of DSP here...
In fact, it all goes with the definition of "added value". Is there an added value to implement the audio resampling yourself? If you're genuinely interrested in DSP, then go ahead, you'll learn something. You have a neat and clever idea to test out? Go for it, maybe you'll find novel ways to do proper audio with good speed/accuracy. Otherwise, if you just want to get good audio from your emulator and spend time in things you think is more worth your time, then don't waste it uselessly and use a library that does it already (blip_buffer for instance).
((λ (x) (x x)) (λ (x) (x x)))
Re: Some advice of DSP here...
Good source Tepples but i think i will use blip_buffer C code.
Now the problem is that i don't know even how to use the code. I took a look to the "demos" but it's greek for me.
What such a noob i am.
Any help?? at least a starting point.
Now the problem is that i don't know even how to use the code. I took a look to the "demos" but it's greek for me.
What such a noob i am.
Any help?? at least a starting point.
ANes
Re: Some advice of DSP here...
Ok im totally lost, but i found a linear interpolation fn in wikipedia:
So i have 735 samples (NTSC) is it well to do a:
I have the 735 buffer filled, and a "dest" buffer wich is then passed to directsound (of course there is an unsigned 16 bit conversion).
The sound plays, i think i don't hear any "better" sound and the worst is that there are some glitches.
Code: Select all
// Precise method which guarantees v = v1 when t = 1.
float lerp(float v0, float v1, float t) {
return (1-t)*v0 + t*v1;
}
Code: Select all
void linearinterpolation(float * src, int len, float * dest, int f)
{
int i;
float sample;
for (i = 0; i < len - 1; i++)
{
sample = lerp(src[i], src[i+1], f);
dest[i] = sample;
}
}
The sound plays, i think i don't hear any "better" sound and the worst is that there are some glitches.
ANes
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Some advice of DSP here...
What you're doing does not look like useful code. What is "f" supposed to do?
In audio, linear interpolation means that you are converting a buffer of one length into a buffer of another length (or alternatively, one speed/samplerate to another). It should look more like:
This isn't really optimal code, and it probably isn't even what you want to be doing, but I'm just trying to give an idea of what linear interpolation for resampling is. This technique is really only for upsampling, not downsampling.
If downsampling, you want something like a box filter. Basically take all the samples for a window of time in the input buffer, and average them together to make your output sample that represents that block of time (the samples at the beginning and end of the window will have reduced weight, since the window will probably begin and end partway through the sample).
In audio, linear interpolation means that you are converting a buffer of one length into a buffer of another length (or alternatively, one speed/samplerate to another). It should look more like:
Code: Select all
for (i = 0; i < len_out; ++i)
{
// convert output position to input position
float pos_in = float(i) * float(len_in) / float(len_out);
// calculate blend value for linear interpolation
float alpha = pos_in - floorf(pos_in);
// find the two samples to interpolate
int p0 = int(pos_in);
int p1 = p0 + 1;
dest[i] = lerp(src[p0], src[p1], alpha);
}
If downsampling, you want something like a box filter. Basically take all the samples for a window of time in the input buffer, and average them together to make your output sample that represents that block of time (the samples at the beginning and end of the window will have reduced weight, since the window will probably begin and end partway through the sample).
Re: Some advice of DSP here...
Ok, im learning thanks.rainwarrior wrote:If downsampling, you want something like a box filter. Basically take all the samples for a window of time in the input buffer, and average them together to make your output sample that represents that block of time (the samples at the beginning and end of the window will have reduced weight, since the window will probably begin and end partway through the sample).
You say a "window of time", that's my 735 samples.
Could you be more verbose about "average them together"??Basically take all the samples for a window of time in the input buffer, and average them together to make your output sample that represents that block of time
Sorry being so noob.
ANes
Re: Some advice of DSP here...
The thing is that I CAN avarage 735 samples, so the sum of S0 + S1, +Sn divided by 735 leaves me with only one sample??
ANes
Re: Some advice of DSP here...
No - your "window of time" is ~40.5844 samples (i.e. 1.79MHz divided by 44.1kHz).Anes wrote:You say a "window of time", that's my 735 samples.rainwarrior wrote:take all the samples for a window of time in the input buffer, and average them together to make your output sample
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
P.S. If you don't get this note, let me know and I'll write you another.
Re: Some advice of DSP here...
So im doing it well becouse im averageting 40.5~ so clocks and then i divide the average var by that number.
The emu doesn't sounds bad, but compared to fceux or others is poor....
What does this emulators do to sound that way?? Is there any code/lib??
The emu doesn't sounds bad, but compared to fceux or others is poor....
What does this emulators do to sound that way?? Is there any code/lib??
ANes
Re: Some advice of DSP here...
Emulators might use a simple FIR lowpass like a box filter, or some sort of big FIR, or some IIR, or the simplified version of blip buffer.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Some advice of DSP here...
A box filter is a FIR filter, just a really simple one. Generically, a FIR filter is a window where each sample in the window gets a specific weight. You multiply each sample in the window by that weight, and add them together to get your result. In the box filter, every sample has the same weight.
Is there a practical IIR for resampling? (I've seen the analog equivalent in ADCs, but not in a digital resampler.)
The blip buffer also uses FIRs, but the process is inverted. Instead of generating the high-samplerate signal and then downsampling, it synthesizes the result at the target samplerate by replacing discrete steps with FIRs.
Is there a practical IIR for resampling? (I've seen the analog equivalent in ADCs, but not in a digital resampler.)
The blip buffer also uses FIRs, but the process is inverted. Instead of generating the high-samplerate signal and then downsampling, it synthesizes the result at the target samplerate by replacing discrete steps with FIRs.