DMC unsigned samples?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 568
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: DMC unsigned samples?

Post 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.
((λ (x) (x x)) (λ (x) (x x)))
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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.
Attachments
Battletoads_wav.zip
(246.09 KiB) Downloaded 154 times
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DMC unsigned samples?

Post 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?
Attachments
battletoads_whine.png
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DMC unsigned samples?

Post 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.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: DMC unsigned samples?

Post 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 4018 times
Why is this here?

It is not DMC. It is a bug somewhere in your emulator.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: DMC unsigned samples?

Post by lidnariq »

Given prior guesses: try bypassing your resampler? (Just dump the 1.8MHz audio file to disk)
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: DMC unsigned samples?

Post 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.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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.
Attachments
nes_raw.zip
(90.83 KiB) Downloaded 148 times
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: DMC unsigned samples?

Post by lidnariq »

Yup, it's your resampler.

The raw 1.8MHz sample rate output here is perfectly clean.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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?
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: DMC unsigned samples?

Post by lidnariq »

Top: 1.8MHz, perfectly clean.
Bottom: 48kHz, bonus noise.
Attachments
compare-sample-rates.png
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: DMC unsigned samples?

Post 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.
Post Reply