It is currently Sun Nov 19, 2017 12:04 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 98 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 7  Next
Author Message
PostPosted: Tue Jun 23, 2015 10:32 am 
Offline
User avatar

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


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 10:38 am 
Offline
User avatar

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

Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 11:16 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6442
Location: UK (temporarily)
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.

Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 11:59 am 
Offline

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


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 12:10 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6442
Location: UK (temporarily)
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.


Top
 Profile  
 
PostPosted: Tue Jun 23, 2015 3:49 pm 
Offline
User avatar

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


Top
 Profile  
 
PostPosted: Sun Jun 28, 2015 3:13 am 
Offline
User avatar

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


Top
 Profile  
 
PostPosted: Sun Jun 28, 2015 8:09 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Can (if it possible) somebody guide me how to use Blargg's blip buf:
As Blargg says:

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


Top
 Profile  
 
PostPosted: Sun Jun 28, 2015 9:40 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19227
Location: NE Indiana, USA (NTSC)
Anes wrote:
- Is The imput clock rate: 1.73~mhz NES clocks??

Yes.

Quote:
- Output clock rate: is it 44100?

Usually either that or 48000.

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


Top
 Profile  
 
PostPosted: Sun Jun 28, 2015 10:12 am 
Offline
User avatar

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


Top
 Profile  
 
PostPosted: Sun Jun 28, 2015 12:08 pm 
Offline
User avatar

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


Top
 Profile  
 
PostPosted: Mon Jun 29, 2015 5:32 pm 
Offline
User avatar

Joined: Wed Feb 13, 2008 9:10 am
Posts: 582
Location: Estonia, Rapla city (50 and 60Hz compatible :P)
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).

_________________
http://www.tmeeco.eu


Top
 Profile  
 
PostPosted: Tue Jun 30, 2015 9:01 am 
Offline
User avatar

Joined: Sat Jan 22, 2005 8:51 am
Posts: 427
Location: Chicago, IL
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


Top
 Profile  
 
PostPosted: Tue Jun 30, 2015 7:40 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 729
Location: New York, NY
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).


Top
 Profile  
 
PostPosted: Tue Jun 30, 2015 7:47 pm 
Offline

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

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 98 posts ]  Go to page Previous  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