It is currently Fri Dec 15, 2017 12:58 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Sat Jul 09, 2016 5:30 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
Let me start with square waves. This is the best music to test so far. ;)
Tell me if something's obviously wrong, please.


Attachments:
Metroid_wav.zip [60.49 KiB]
Downloaded 40 times
Top
 Profile  
 
PostPosted: Sat Jul 09, 2016 7:10 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6529
Location: Seattle
Nothing's obviously wrong. No additional noise content is present, transitions look roughly consistent with a slightly overdamped interpolator.


Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 2:54 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
OK, I'm adding an highpass filtering, but one thing is bugging me. With code seems better to explain...
Code:
int output_L; //L = left channel, or mono.
int previous_sample;

//at every APU clock
int value = pulse_1_volume + pulse_2_volume + ...

output_L += (value - previous_sample) << 8;
previous_sample = value;
num_of_updates++;

//on resample (PC sample generation, after appox. 37 APU updates)

//decay
output_L -= output_L >> 7;
unsigned short *wavebuffer = (output_L / num_of_updates) ^ 0x8000;  //here's my question!

The sound output isn't fine - it's not "crystal and clear", but... a bit noisy.
I had perfected the unsigned samples - no errors (listen the previous file), but on highpass, it's not fine.

What I'm doing wrong after all...!? :shock: :shock: :shock:


Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 3:23 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6529
Location: Seattle
There's so many different little things...
Quote:
output_L += (value - previous_sample) << 8;
previous_sample = value;
There's no need to multiply by 256 yet, you may as well skip that for now.
This is an extremely high frequency FIR high-pass filter, with a corner frequency at one sixth of the sample rate. Since the sample rate here is 1.8MHz, any audio that comes out is going to be awfully quiet... probably why you added the <<8.

Quote:
unsigned short *wavebuffer = (output_L / num_of_updates) ^ 0x8000;
I think it's very likely that this varying num_of_updates is the source of the noise you had with the original resampler.


Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 4:34 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
Someone (ages ago) told me to do that for DMC/RAW PCM samples. So, I'm using that method for the APU output.

lidnariq wrote:
There's so many different little things...
Quote:
output_L += (value - previous_sample) << 8;
previous_sample = value;
There's no need to multiply by 256 yet, you may as well skip that for now.
This is an extremely high frequency FIR high-pass filter, with a corner frequency at one sixth of the sample rate. Since the sample rate here is 1.8MHz, any audio that comes out is going to be awfully quiet... probably why you added the <<8.

If I take out the << 8, how's made the decay >> 7 ???

Well, any suggestion? I don't know how to resample & apply the highpass filtering. That's the problem. :cry:


Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 5:05 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6529
Location: Seattle
Zepper wrote:
output_L -= output_L >> 7;
That line is equivalent to output_L = outputL*127/128; It's not actually related, unless you see signs of clipping or are losing audio quality by accidentally discarding bits off the little end.

Quote:
Well, any suggestion?
Ok, so you have a no-obvious noise resampled version without the highpass. What changed between that version and the one you just posted? Just the (value-previous_sample) ?


Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 5:14 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
I'm confused. What "versions" do you mean? The resample method is just summing all the generated samples and divide by the number of samples.
Plus, the "<< 8" is for 16-bit samples. :roll: I can't simply take it out.


Last edited by Zepper on Thu Jul 14, 2016 6:55 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 5:19 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6529
Location: Seattle
What is the difference in the source code that you made between the one that made the audio in this post

and the code fragment that you posted?


Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 5:30 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
I recorded 3 wav files.
One using RockNES 5.24 signed samples.
The other two uses 5.25 - unsigned samples (perfect) and with the highpass filter (noisy).

For unsigned samples? No filtering, just output_L += pulse_1 + pulse_2 +..., then *wavebuffer = output_L / num_of_samples.


Attachments:
rnes_wav.zip [69.44 KiB]
Downloaded 34 times
Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 7:31 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
Just added high pass from wikipedia... but without your drop of magic, it wouldn't be working. :lol: :lol: :lol:

y(i) := a * (y(i-1) + x(i) - x(i-1))

y(i) is the new sample
y(i-1) is the previous sample

x(i) is the input sample
x(i-1) is the previous input sample

a is your magic, or sample*127/128; otherwise, for some reason, I was only getting unsigned samples. Care to explain? ;) Just compare the files.


Attachments:
rnes_highpass.zip [1.63 MiB]
Downloaded 50 times
Top
 Profile  
 
PostPosted: Thu Jul 14, 2016 8:01 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6529
Location: Seattle
You elided enough of the code that it was hard to tell exactly what was going on.

It looked like the output -= output>>7 was happening on isolated samples after the sample rate change; in that case it's just a simple volume adjustment.

If that volume adjustment happens BEFORE the filtering is applied, then it will change the exact frequencies that are filtered.

If you used a simple first-order output-delay like this:
y[n] = a·(y[n-1] + x[n] - x[n-1]) →algebra→
y[n] = a·y[n-1] + k·(x[n]-x[n-1]) →Z transform→
Y = a·Yz¯¹ + a(X-Xz¯¹) →algebra→
Y(1-az¯¹) = a(1-z¯¹)X →algebra→
"transfer function" = Y/X = a(1-z¯¹)/(1-az¯¹)
fraction on the right is 0 when z is 1.
fraction on the right is infinite when z is 1/k.
If a is 127/128, this corresponds to a corner frequency of .000724597 times the sample rate, or 1300Hz at 1.8MHz, and 35Hz at 48kHz.


Top
 Profile  
 
PostPosted: Fri Jul 15, 2016 6:14 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
One last thing. Anything about sample*k-1/k, with k a number power of 2? There's no audible differences as far as I can tell you - the waveform slightly changes.

- like 127/128 or 63/64 or 31/32 -


Top
 Profile  
 
PostPosted: Fri Jul 15, 2016 10:26 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6529
Location: Seattle
The corner frequency of this highpass is very approximately samplerate÷k÷10, so you're not going to get a very noticeable difference in the range of factors you've listed here.


Top
 Profile  
 
PostPosted: Fri Jul 15, 2016 11:46 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
Fine. Since I wasn't lucky with the low pass option (couldn't get signed samples), I'll keep this high pass filtering. Amazing and much more cleaner (and crystal) sound output.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 8 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