DMC unsigned samples?
Moderator: Moderators
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.
Tell me if something's obviously wrong, please.
- Attachments
-
- Metroid_wav.zip
- (60.49 KiB) Downloaded 138 times
Re: DMC unsigned samples?
Nothing's obviously wrong. No additional noise content is present, transitions look roughly consistent with a slightly overdamped interpolator.
Re: DMC unsigned samples?
OK, I'm adding an highpass filtering, but one thing is bugging me. With code seems better to explain...
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...!?
Code: Select all
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!
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...!?
Re: DMC unsigned samples?
There's so many different little things...
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.
There's no need to multiply by 256 yet, you may as well skip that for now.output_L += (value - previous_sample) << 8;
previous_sample = value;
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.
I think it's very likely that this varying num_of_updates is the source of the noise you had with the original resampler.unsigned short *wavebuffer = (output_L / num_of_updates) ^ 0x8000;
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.
Well, any suggestion? I don't know how to resample & apply the highpass filtering. That's the problem.
If I take out the << 8, how's made the decay >> 7 ???lidnariq wrote:There's so many different little things...There's no need to multiply by 256 yet, you may as well skip that for now.output_L += (value - previous_sample) << 8;
previous_sample = value;
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.
Well, any suggestion? I don't know how to resample & apply the highpass filtering. That's the problem.
Re: DMC unsigned samples?
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.Zepper wrote:output_L -= output_L >> 7;
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) ?Well, any suggestion?
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. I can't simply take it out.
Last edited by Zepper on Thu Jul 14, 2016 6:55 pm, edited 1 time in total.
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?
and the code fragment that you posted?
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.
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 130 times
Re: DMC unsigned samples?
Just added high pass from wikipedia... but without your drop of magic, it wouldn't be working.
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.
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 138 times
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.
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.
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 -
- like 127/128 or 63/64 or 31/32 -
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.
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.