It is currently Wed Nov 22, 2017 4:24 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 98 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next
Author Message
PostPosted: Sun Jun 21, 2015 11:09 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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??

_________________
ANes


Top
 Profile  
 
PostPosted: Sun Jun 21, 2015 11:40 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6447
Location: UK (temporarily)
The best one to use is the one that you know how to implement :P

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.


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 12:25 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
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.

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. :)

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 7:20 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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).


I really suck about DSP. Any good advice/book/article/link to start with??

_________________
ANes


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 7:45 pm 
Offline
Formerly ~J-@D!~
User avatar

Joined: Sun Mar 12, 2006 12:36 am
Posts: 445
Location: Rive nord de Montréal
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).


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 8:07 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19239
Location: NE Indiana, USA (NTSC)
Anes wrote:
I really suck about DSP. Any good advice/book/article/link to start with??

Did you try Bores?


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 9:15 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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.

_________________
ANes


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 11:34 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Ok im totally lost, but i found a linear interpolation fn in wikipedia:

Code:
// Precise method which guarantees v = v1 when t = 1.
float lerp(float v0, float v1, float t) {
  return (1-t)*v0 + t*v1;
}


So i have 735 samples (NTSC) is it well to do a:
Code:
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;
   }
}


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.

_________________
ANes


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 12:22 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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:

Code:
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);
}


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).


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 12:46 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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).


Ok, im learning thanks.

You say a "window of time", that's my 735 samples.

Quote:
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


Could you be more verbose about "average them together"??

Sorry being so noob.

_________________
ANes


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 1:18 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 4:35 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1392
Anes wrote:
rainwarrior wrote:
take all the samples for a window of time in the input buffer, and average them together to make your output sample
You say a "window of time", that's my 735 samples.


No - your "window of time" is ~40.5844 samples (i.e. 1.79MHz divided by 44.1kHz).

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 5:21 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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??

_________________
ANes


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 9:13 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19239
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 9:29 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 98 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group