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.

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...!? 
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; There's no need to multiply by 256 yet, you may as well skip that for now.previous_sample = value; This is an extremely high frequency FIR highpass 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; There's no need to multiply by 256 yet, you may as well skip that for now.previous_sample = value; This is an extremely high frequency FIR highpass 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. 
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 noobvious noise resampled version without the highpass. What changed between that version and the one you just posted? Just the (valueprevious_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. 
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.

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. y(i) := a * (y(i1) + x(i)  x(i1)) y(i) is the new sample y(i1) is the previous sample x(i) is the input sample x(i1) 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.

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 firstorder outputdelay like this: y[n] = a·(y[n1] + x[n]  x[n1]) →algebra→ y[n] = a·y[n1] + k·(x[n]x[n1]) →Z transform→ Y = a·Yz¯¹ + a(XXz¯¹) →algebra→ Y(1az¯¹) = a(1z¯¹)X →algebra→ "transfer function" = Y/X = a(1z¯¹)/(1az¯¹) 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*k1/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/ 