DPCM Loop Mode Frequency Calculation

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
User avatar
TylerBarnes
Posts: 17
Joined: Tue Mar 19, 2019 12:41 pm

DPCM Loop Mode Frequency Calculation

Post by TylerBarnes »

Hello,

Working on a particular problem regarding the loop mode of the DPCM channel. There are a couple thing I would like clarification on, and input on.

Since moving from ppMCK/MML to messing around in FamiTracker, I have recently realized that the DPCM channel actually has a mode to loop .dmc samples. Naturally, I want to use this for continuous tones, in the most accurate way possible, using the fewest bytes and fewest unique .dmc files.

I have had a fine time reading up on the APU, the DPCM rates 0-15, and how to calculate output frequency for a given byte size. My questions arise when it comes to the format of .dmc samples, as well as a general question on if I'm reinventing the wheel or not. If someone has done similar or equivalent work I would like to read about this.

Regarding the format of DPCM files. I have read the wiki and think I understand some things but I'm not 100%. The wiki seems to suggest that for every positive bit in the .dmc the output level is increased by 2 units, and for every bit equal to zero it decreased by 2 volume units. So a full wave period, from zero to full volume, then back to zero again, would take the max volume number of bits long. So given the max volume of 100, it takes 50 bits to reach the top peak, and 50 bits to reach the bottom peak considering that each bit alters the value by 2 units. Is this correct?

The next aspect of this is bit order. When manually constructing files for this, if I think from left to right and start inputting bits, am I right in thinking that the NES is actually going to read the bits from least significant to most? Meaning if I'm creating a bit stream manually, I need to quantize into bytes and the reverse the bit order of each byte?

I am going to be working on how to generate these sorts of files and patterns, but obviously need to know how they operate in order to do so.

Thanks for any input and/or resources you have.

If you are still note sure of what I'm attempting or just curious on my progress so far, I have coded this in javascript to help me search for the most accurate frequency approximations using the fewest unique samples, and fewest bytes possible. However the generation of .dmc files is my next hurdle.

https://playcode.io/502163 // Click 'play' on Results View for variable input; Clicking 'Generate' renders results in console.

Again, Thanks
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: DPCM Loop Mode Frequency Calculation

Post by lidnariq »

I know it's not the least bit satisfying to use someone else's work instead of doing it yourself, but I've generated a comprehensive set of every possible triangle-wave-on-DPCM: viewtopic.php?p=154032#p154032
User avatar
TylerBarnes
Posts: 17
Joined: Tue Mar 19, 2019 12:41 pm

Re: DPCM Loop Mode Frequency Calculation

Post by TylerBarnes »

lidnariq wrote: Fri Feb 21, 2020 1:18 am I know it's not the least bit satisfying to use someone else's work instead of doing it yourself, but I've generated a comprehensive set of every possible triangle-wave-on-DPCM: viewtopic.php?p=154032#p154032
Thanks, that looks great. I see your goal in making that set was not quite the goal I am after but gives good insight.

My goal is to make a limited set focused on a target volume, and close enough to target frequencies to help with a low byte count.

Looks like Dougeff answered my question in that linked thread on page 2. Least significant bit first.

I have altered my code and added the generation of DPCM data(same link above leads to updated code). Generation still a bit primitive though. Not really generating triangles, rather squares at longer wave periods. Now just to test if it is all close enough to what I wanted. (EDIT: checked them so far.... haha, needs work.)
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: DPCM Loop Mode Frequency Calculation

Post by lidnariq »

TylerBarnes wrote: Fri Feb 21, 2020 11:11 pm My goal is to make a limited set focused on a target volume, and close enough to target frequencies to help with a low byte count.
Be careful/deliberate here. With DPCM, volume is the same as harmonic distortion. Trying to represent something too loud generates slew rate distortion, and the naive approach to represent quieter things produces high quiet inharmonic overtones. (More sophisticated techniques will generate hiss, which is a good baseline, but sometimes designing in specific harmonic distortion sounds better)

So it may be preferable to make a set of samples that vary a little more in volume to decrease the amount by which they differ harmonically.

The DPCM channel also affects the volume of the triangle and noise channels. Something I'd intended to do, but evidently haven't gotten around to, was to take advantage of how the DPCM channel clips during decoding to combine my triangle pack with volume control over the triangle channel.

By which I mean: the bitstream 110000 will eventually end up being [2 4 2 0 0 0] on the DPCM DAC, and will also move the triangle channel volume to "loudest". The bitstream 001111 will eventually end up being [124 122 124 126 126 126] on the DPCM DAC, which will sound the same (because we can't directly hear phase) but will move the triangle channel to "quietest".
User avatar
TylerBarnes
Posts: 17
Joined: Tue Mar 19, 2019 12:41 pm

Re: DPCM Loop Mode Frequency Calculation

Post by TylerBarnes »

Ended up getting it to a spot that has rendered me a usable set that I'm decently happy with. Posting fami files, dmc files, and code here for prosperity. Feel free to use the files for your own tracks.

Default set ranges from notes D1-C3
Consumes 698 bytes total
Contains 10 unique .dmc files
With pitches being 99.85% accurate overall.
Attachments
DPCM_Note_Channel.zip
Pitched DPCM instrument; Code and Files
(12.59 KiB) Downloaded 234 times
Post Reply