Page 2 of 3

Re: DMC unsigned samples?

Posted: Mon Jun 27, 2016 9:54 pm
by Jarhmander
The noise can come from an incorrect window function selected for the interpolation. I don't recommend using any window function that both ends are not zero (e.g. Hamming), I had a problem similar to yours in a toy resampler I made, a DC bias made some noise, and the noise would get bigger if the bias was increased.

Re: DMC unsigned samples?

Posted: Thu Jul 07, 2016 2:48 pm
by Zepper
Found the problem. The output volume was coming directly from $4011 writes! Instead, it should come from channel update. In raw mode ($4011 samples only, no DPCM unit), the frequency reload should be 1 (cycle), instead of taking the first entry from the DMC frequencies table, or 0x1AC (NTSC).

It worked like a charm. Just listen the file.

Re: DMC unsigned samples?

Posted: Thu Jul 07, 2016 2:54 pm
by rainwarrior
Zepper wrote:It worked like a charm. Just listen the file.
The high frequency whine is still there. Look at the silent section at the start of this recording; why isn't it actually silent?

Re: DMC unsigned samples?

Posted: Thu Jul 07, 2016 7:20 pm
by Zepper
Because the value written to $4011 is never zero. In unsigned samples mode, the value written to $4011 is the volume level output to dac. In short words, there isn't any kind of sample filtering. If you don't believe me, just log the values written to $4011.

Re: DMC unsigned samples?

Posted: Thu Jul 07, 2016 7:48 pm
by rainwarrior
I'm not asking why it's not 0, I'm asking why it's not flat (flat = silent). There is a high frequency whine there instead of silence, which you asked about in the very first post in this thread.

This doesn't have anything to do with $4011, it's a problem with your sound generation in general. Maybe with downsampling, as has been suggested, or maybe something else.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 3:57 am
by Zepper
Battletoads uses $4011 for raw dmc, so how's unrelated?
On channel update, I do (value&$7F) << 8. The value is never zero.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 10:43 am
by lidnariq
Look at your file. Look at the very beginning, before DMC is playing.
Battletoads (U) 000.png
Battletoads (U) 000.png (3.75 KiB) Viewed 4026 times
Why is this here?

It is not DMC. It is a bug somewhere in your emulator.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 12:58 pm
by Zepper
I use GoldWave to view the waveform... and yeah, I know of this problem. But I have no clue what's up. :?

As I showed up... it's the $4011 value & $7F << 8 (16-bit sample). The value written is never zero.

I have two methods of resampling, but both sum (+) the current sample to an adder. One counts the N number of added samples and divide the adder by N; another do the same, but instead of using a division by N, I shift right the adder. Better results are with adder >> 5.

This is my resample value based on the NES master clock:

Code: Select all

* The exact sample rate of the NES audio DAC itself is 39375000/22 Hz = 1.7898 MHz.

resample:
(39375000 / 22) / 48000Hz (PC rate) =
= 39375000 / 48000*22 (both x22) =
= 393750 / 480*22 (both DIV 100) = 
= 393750 / 10560 =
= 39375 / 1056 (both DIV 10) = ~37 samples per sync.
both DIV 3 => **13125 / 352**
In each apu update:

Code: Select all

decay_master = 13125;
decay_value = 352;

decay_master -= decay_value;
if(decay_master <= 0)
//calculate the sample and send it to the wavebuffer.
APU source code may be avaliable if you're willing for it.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 1:11 pm
by lidnariq
Given prior guesses: try bypassing your resampler? (Just dump the 1.8MHz audio file to disk)

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 1:32 pm
by koitsu
I wouldn't be surprised if this turned out to be "some weird Allegro thing", somehow. I believe the version of Allegro being used here is 4.4, while 5.2 is the latest (edit: 5.2 appears to be latest, but I did find some prebuilt binaries that are labelled 5.3.0...). Not sure what type of audio layer is being used (DirectX/DirectSound I'd guess). The changelog for 5.0.0 to 5.0.1 has an entry that says "Play silence where needed in DirectSound driver", which made me chuckle.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 2:27 pm
by Zepper
lidnariq wrote:Given prior guesses: try bypassing your resampler? (Just dump the 1.8MHz audio file to disk)
Fine. :beer:
Here's the raw dump, 16-bit sample, low byte first.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 4:45 pm
by lidnariq
Yup, it's your resampler.

The raw 1.8MHz sample rate output here is perfectly clean.

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 5:32 pm
by Zepper
lidnariq wrote:Yup, it's your resampler.

The raw 1.8MHz sample rate output here is perfectly clean.
I didn't get it. :? :? How so? What's exactly the difference between the waves?
Care to take screenshots of the waveforms for comparison, plz?

Re: DMC unsigned samples?

Posted: Fri Jul 08, 2016 6:09 pm
by lidnariq
Top: 1.8MHz, perfectly clean.
Bottom: 48kHz, bonus noise.

Re: DMC unsigned samples?

Posted: Sat Jul 09, 2016 5:21 am
by Zepper
Hmm... I see. And I have to apologize for the language barrier.
Yes. I though we were talking about the DMC waveform not being centered and without silence when it should be.
Like...

Code: Select all

       |-------|    |-------|
       |       |    |       |
       |       |____|       |____ (silence, 
       |                        but not zero)
       |
       | attack
_______

begin
(silence = 0)
There's a noise in the waveform, yeah, I had seen it.