Some advice of DSP here...

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: Some advice of DSP here...

Post by Anes »

rainwarrior wrote: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.
Im reading and reading from wikipedia and some things are unclear to me, for something quick, can't you post the code for this FIR filter?? Taking into acount my sample array is 41 samples.

thnks in advance.
ANes
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Some advice of DSP here...

Post by rainwarrior »

http://ptolemy.eecs.berkeley.edu/eecs20 ... ation.html

Edit: sorry, this is just an example of a FIR filter without resampling, but the basic technique is the same. Multiply an array of input samples with the array of weights (FIR filter) and sum them up to produce an output sample.
Last edited by rainwarrior on Tue Jun 23, 2015 2:56 pm, edited 1 time in total.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Some advice of DSP here...

Post by lidnariq »

Anything with full rejection in the stop band (e.g. Butterworth, Chebychev type 1) would work fine as an IIR resampling filter... Actually, anything where the stop-band is quiet enough such that aliasing from subsequent decimation wouldn't be audible would be fine too.

The real relative disadvantage comes from the ability to make FIR filters polyphase calculate only one phase of a decimating polyphase FIR filter, such that you can reduce the calculation load by the amount you're decimating the output.
Last edited by lidnariq on Tue Jun 23, 2015 12:11 pm, edited 1 time in total.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Some advice of DSP here...

Post by tepples »

rainwarrior wrote:Is there a practical IIR for resampling?
Any low-pass IIR will do it. Clock in N samples and read only the output for the last one. The drawback is that you won't get linear phase, meaning some frequencies will be delayed slightly more than others.
lidnariq wrote:The real relative disadvantage comes from the ability to make FIR filters polyphase
I thought IIRs could be polyphase too. If that's not possible, I'd like to see a citation so I can fix the encyclopedia article.
lidnariq wrote:where you can reduce the calculation load by the amount you're decimating the output.
The blip-buffer technique likewise reduces calculation load.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Some advice of DSP here...

Post by lidnariq »

tepples wrote:I thought IIRs could be polyphase too. If that's not possible…
That was inaccurate terminology on my part. It's the ability to skip calculating some of the phases when decimating that makes the computational difference, which is only true when you have a set of poles at all of the roots that are a factor of the decimation ratio.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Some advice of DSP here...

Post by rainwarrior »

Looking back at the original post, if the goal is to improve the quality of your NES audio in a simple way, I might suggest what I did for the PC/Mac version of my Lizard game:

Generate audio at 4x the target samplerate (e.g. 192000 Hz), and downsample to the target samplerate just by averaging every 4 samples. It's very simple to implement, and 4x oversampling is enough to keep the quality pretty good, I think.

The one exception is the noise generator. The high frequency noise still sounds poor and un-NES-like without some additonal oversampling. I put an additional simple oversampling within the noise generation (i.e. to generate the noise output, I count up how many CPU clocks the noise is 1 vs 0 for this sample, then divide by number of clocks).


It's not as good as a more ideal filter, but it might be good enough for what you want. (You can listen to the PC build of Lizard to hear what it sounds like.) It's simple to implement, and relatively efficient.
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: Some advice of DSP here...

Post by Anes »

The thing is that i suck at maths. When i find something on wikipedia it's full of formulas and such things that i don't understand. My math are high shool level.
Anyway i found a code of a guy implmenting a low pass filter and now sounds better, not "too much better" but better.

I preciate your help, but until i don't study well DSP and math im pretty screwed up.
ANes
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: Some advice of DSP here...

Post by Anes »

Can (if it possible) somebody guide me how to use Blargg's blip buf:
As Blargg says:

Code: Select all

The emulator merely sets the input clock rate and output sample rate, adds waveforms by specifying the clock times where their amplitude changes, then reads the resulting output samples.
- Is The imput clock rate: 1.73~mhz NES clocks??
- Output clock rate: is it 44100?
- clock times: what is this?
- where their amplitude changes: again, what is this??

I preciate such help.
ANes
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Some advice of DSP here...

Post by tepples »

Anes wrote:- Is The imput clock rate: 1.73~mhz NES clocks??
Yes.
- Output clock rate: is it 44100?
Usually either that or 48000.
- clock times: what is this?
- where their amplitude changes: again, what is this??
Number of CPU cycles since frame start, or since power-on, I'm not sure.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Some advice of DSP here...

Post by rainwarrior »

I'd recommend 48000 as the default.

44100 Hz was the CD standard, and for a long time this (and simple divisions of it) was the standard samplerate for sound cards. It remains widely used for music media like MP3.

More recently, 48000 Hz has become the standard for most audio hardware. Gaming consoles, sound cards, blu-ray, etc. It's the most common native samplerate now.

A lot of sound cards support both. Some old sound cards don't support 48000, and some new sound cards don't support 44100. Often this is hidden from the user with a simple resampling at some layer of the software (operating system or elsewhere), but you can hear the conversion by testing high frequency signals for audible aliasing. You get the best sound at the card's native rate, so I'd recommend 48000 if you can't make it an option.
User avatar
Anes
Posts: 702
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Re: Some advice of DSP here...

Post by Anes »

Ok im going to use 48000... but i simply give up about sound processing to sound better, i think i need more knowladge than i have.

Anyway thanks.
ANes
User avatar
TmEE
Posts: 960
Joined: Wed Feb 13, 2008 9:10 am
Location: Norway (50 and 60Hz compatible :P)
Contact:

Re: Some advice of DSP here...

Post by TmEE »

Sound cards are using 48KHz and its multiples since the introduction of AC97. 44.1 is resampled in software on cheap stuff or by hardware on less cheap stuff. Win Vista+ resample all stuff in software to whatever rate the sound card runs at (48KHz or a multiple).
User avatar
James
Posts: 431
Joined: Sat Jan 22, 2005 8:51 am
Location: Chicago, IL
Contact:

Re: Some advice of DSP here...

Post by James »

rainwarrior wrote:Is there a practical IIR for resampling? (I've seen the analog equivalent in ADCs, but not in a digital resampler.)
I use an IIR-based resampler in nemulator. I generate an audio sample every 3rd CPU cycle (~596600Hz), then filter it with a 16th order IIR lowpass (equivalent to ~512th order FIR). I then interpolate (3rd order b-spline) between samples for arbitrary sample rate conversion.

The IIR filter is implemented with SSE instructions and computes biquad sections in parallel. It's fast and cache-friendly.
get nemulator
http://nemulator.com
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Some advice of DSP here...

Post by zeroone »

James wrote:
rainwarrior wrote:Is there a practical IIR for resampling? (I've seen the analog equivalent in ADCs, but not in a digital resampler.)
I use an IIR-based resampler in nemulator. I generate an audio sample every 3rd CPU cycle (~596600Hz), then filter it with a 16th order IIR lowpass (equivalent to ~512th order FIR). I then interpolate (3rd order b-spline) between samples for arbitrary sample rate conversion.

The IIR filter is implemented with SSE instructions and computes biquad sections in parallel. It's fast and cache-friendly.
Why every 3rd CPU cycle?

Also, is the b-spline step necessary? Once the high frequencies are filtered away, shouldn't you just be able to sub-sample the data (i.e. just throw away samples).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Some advice of DSP here...

Post by tepples »

zeroone wrote:Why every 3rd CPU cycle?
Probably someone's idea of the best compromise between speed and accuracy. I would have done every 2 CPU cycles, as the majority of the APU changes its output every other cycle, and the one channel that does allow odd periods (triangle) only changes it by a comparatively small amount.
Also, is the b-spline step necessary? Once the high frequencies are filtered away, shouldn't you just be able to sub-sample the data (i.e. just throw away samples).
That'd be fine if 48 kHz divided evenly into the 315/176 MHz clock rate of the CPU. But it doesn't. There are 37.2869 CPU cycles for each output sample. So you end up having to interpolate when you decimate, inferring output samples that lie between the samples of the filter's output. You can use nearest-neighbor resampling, choosing (say) one output sample every 37, 37, 38, 37, 37, 37, 38, ... input samples, but it adds a bit of jitter. Linear interpolation shouldn't pose a problem though with this much margin.
Post Reply