nesdev.com
http://forums.nesdev.com/

DMC unsigned samples?
http://forums.nesdev.com/viewtopic.php?f=3&t=14455
Page 3 of 3

Author:  Zepper [ Sat Jul 09, 2016 5:30 pm ]
Post subject:  Re: DMC unsigned samples?

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 37 times

Author:  lidnariq [ Sat Jul 09, 2016 7:10 pm ]
Post subject:  Re: DMC unsigned samples?

Nothing's obviously wrong. No additional noise content is present, transitions look roughly consistent with a slightly overdamped interpolator.

Author:  Zepper [ Thu Jul 14, 2016 2:54 pm ]
Post subject:  Re: DMC unsigned samples?

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:

Author:  lidnariq [ Thu Jul 14, 2016 3:23 pm ]
Post subject:  Re: DMC unsigned samples?

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.

Author:  Zepper [ Thu Jul 14, 2016 4:34 pm ]
Post subject:  Re: DMC unsigned samples?

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:

Author:  lidnariq [ Thu Jul 14, 2016 5:05 pm ]
Post subject:  Re: DMC unsigned samples?

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

Author:  Zepper [ Thu Jul 14, 2016 5:14 pm ]
Post subject:  Re: DMC unsigned samples?

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.

Author:  lidnariq [ Thu Jul 14, 2016 5:19 pm ]
Post subject:  Re: DMC unsigned samples?

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?

Author:  Zepper [ Thu Jul 14, 2016 5:30 pm ]
Post subject:  Re: DMC unsigned samples?

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 32 times

Author:  Zepper [ Thu Jul 14, 2016 7:31 pm ]
Post subject:  Re: DMC unsigned samples?

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 45 times

Author:  lidnariq [ Thu Jul 14, 2016 8:01 pm ]
Post subject:  Re: DMC unsigned samples?

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.

Author:  Zepper [ Fri Jul 15, 2016 6:14 am ]
Post subject:  Re: DMC unsigned samples?

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 -

Author:  lidnariq [ Fri Jul 15, 2016 10:26 am ]
Post subject:  Re: DMC unsigned samples?

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.

Author:  Zepper [ Fri Jul 15, 2016 11:46 am ]
Post subject:  Re: DMC unsigned samples?

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.

Page 3 of 3 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/