Why do DPCM samples have a ROM size limit?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Why do DPCM samples have a ROM size limit?
by on (#112665)
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?
by on (#112666)
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?
by on (#112668)
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?
by on (#112669)
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?
by on (#112670)
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?
by on (#112671)
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?
by on (#112672)
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?
by on (#112675)
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?
by on (#112678)
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?
by on (#112680)
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?
by on (#112747)
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?
by on (#112922)
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?
by on (#112959)
That would be a bug in Pocketnes, thanks for the report.
Re: Why do DPCM samples have a ROM size limit?
by on (#112983)
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?
by on (#112994)
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.
Re: Why do DPCM samples have a ROM size limit?
by on (#112999)
Dwedit wrote:
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.


Where would you post updates of PocketNES when you do? PocketHeaven seems to be down again.
Re: Why do DPCM samples have a ROM size limit?
by on (#113002)
I might do a complete overhaul of pocketnes.org, if my FTP access still works. And mirror it on my site too.
Re: Why do DPCM samples have a ROM size limit?
by on (#113004)
Dwedit wrote:
I might do a complete overhaul of pocketnes.org, if my FTP access still works. And mirror it on my site too.

That's great! Would love to have that site updated to reflect the new PocketNES versions.