Page 1 of 2

Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 10:08 am
by CKY-2K/Clay Man
Why do DPCMs have a storage size limit when full PCMs don't?
What is the exact limit size of DPCM data you can store?

I've notice Famitracker has an "expanded" size limit, but when I export to NSF, the songs freak out when it calls up a DPCM past the "limit".

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 10:14 am
by Shiru
DPCM is played by the hardware, so the size is limited by the hardware design. It is 16384 bytes (could be a bit more, not practically usable). If you want more, you'd have to bankswitch the top 16K, selecting needed bank for a sample, and solve all related problems (keeping vectors and other stuff in place). You can't automatically switch the bank during play, though.

PCM does not have limitations, as it is played purely by software.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 10:47 am
by CKY-2K/Clay Man
Shiru wrote:DPCM is played by the hardware, so the size is limited by the hardware design. It is 16384 bytes (could be a bit more, not practically usable). If you want more, you'd have to bankswitch the top 16K, selecting needed bank for a sample, and solve all related problems (keeping vectors and other stuff in place). You can't automatically switch the bank during play, though.

PCM does not have limitations, as it is played purely by software.
Does it include the entire ROM or just the DPCM data? I only used 9k bytes and it still freaked out. I narrowed it down to 1 song and it stopped freaking out.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 10:49 am
by thefox
Shiru wrote:DPCM is played by the hardware, so the size is limited by the hardware design. It is 16384 bytes (could be a bit more, not practically usable). If you want more, you'd have to bankswitch the top 16K, selecting needed bank for a sample, and solve all related problems (keeping vectors and other stuff in place). You can't automatically switch the bank during play, though.
You must mean 4081 bytes, the limitation set by the APU DMC register $4013. Of course DMC samples can also be chained by starting the next part of the sample when the DMC IRQ hits. The IRQ handling can also employ bank switching, effectively removing all size limitations.

If FamiTracker has support for some kind of expanded size limit and it doesn't work, there's probably a bug in its NSF player code (or "not implemented", or whatever).

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 11:04 am
by Shiru
I meant total amount of DPCM data that could be used in a program without extra effort, like IRQ and bankswitching. One sample is smaller, yes, up to 4081 bytes.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 11:08 am
by CKY-2K/Clay Man
Shiru wrote:I meant total amount of DPCM data that could be used in a program without extra effort, like IRQ and bankswitching. One sample is smaller, yes, up to 4081 bytes.
This. I'm talking about all the data, not just a single sample.

Famitracker used to have an obvious limit, but I checked out a recent version and it's expanded to allow 256k of DPCM data. It works on Famitracker obviously, but when I exported it started to freak out during playback of the DPCM samples that are past the limit allowed.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 11:14 am
by thefox
CKY-2K/Clay Man wrote:
Shiru wrote:I meant total amount of DPCM data that could be used in a program without extra effort, like IRQ and bankswitching. One sample is smaller, yes, up to 4081 bytes.
This. I'm talking about all the data, not just a single sample.
Well, in that case it depends on the mapper that is used. With simple mappers the limitation is 16KB or less like Shiru said, with more complex mappers the limitation is the maximum size of data that said mapper can handle. For the "complex" mappers (ones that can map into $C000-$FFFF region of memory) the PCM size limitation is not any bigger than the DPCM limitation!

For the NSF mapper, the upper limit for any data (including DPCM and PCM samples), is 1 megabyte.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 11:49 am
by rainwarrior
If a Famitracker export fails, please report the bug on its forum.

Some games, like Gimmick! use an 8k region at C000-DFFF dedicated to samples. It has two 8k banks, I believe, and whenever a sample is played the correct bank for that sample gets swapped in.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 12:59 pm
by tepples
NSF itself is theoretically limited to 1 MiB, but the NSF player on the PowerPak can use only 256 KiB. The limit of total sample size in an NES ROM using MMC3, FME-7, etc. is limited by the number of PRG ROM address output pins on the mapper.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 02, 2013 1:35 pm
by CKY-2K/Clay Man
rainwarrior wrote:If a Famitracker export fails, please report the bug on its forum.
I believe it's related to this bug
http://famitracker.com/forum/posts.php?id=4396

Re: Why do DPCM samples have a ROM size limit?

Posted: Tue Jun 04, 2013 1:33 pm
by Dwedit
MMC3 can bankswitch the second-last 8k, so you can have unlimited samples (limited only by total ROM size).

Re: Why do DPCM samples have a ROM size limit?

Posted: Fri Jun 07, 2013 2:07 pm
by CKY-2K/Clay Man
Dwedit wrote:MMC3 can bankswitch the second-last 8k, so you can have unlimited samples (limited only by total ROM size).
Is that why some of the samples are missing on PocketNES on SMB3 (ex: samples in world 2 theme)? I thought it was because it might have been using raw PCM but it was a Delta PCM.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sat Jun 08, 2013 1:19 pm
by Dwedit
That would be a bug in Pocketnes, thanks for the report.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sat Jun 08, 2013 5:40 pm
by CKY-2K/Clay Man
Dwedit wrote:That would be a bug in Pocketnes, thanks for the report.
lol
It's been there for the longest time, really. It does it with the last samples of world 1 too, but I think it's the same samples used in the desert theme anyways.

Re: Why do DPCM samples have a ROM size limit?

Posted: Sun Jun 09, 2013 8:13 am
by Dwedit
11 lines of code changed and the bug is fixed now. It was calculating the sample's address too early, now it doesn't look up the address until it actually starts fetching samples.