DMC channel

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

The common mappers have a 512 KiB limit on the size of a program. At this rate, I can't fit more than two minutes of telephone quality sound.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

tepples wrote:but I can't fit more than 2 minutes into a 512 KiB (max mmc1/mmc3 size) file
Store the samples in CHR-ROM! :D Then you could go up to 768KB...
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

tokumaru wrote:
tepples wrote:but I can't fit more than 2 minutes into a 512 KiB (max mmc1/mmc3 size) file
Store the samples in CHR-ROM! :D Then you could go up to 768KB...
That'd be a bitch to do, even with a static display. Big Bird stored its shortest samples in unused parts of CHR, but I don't feel like tracing the code.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

I've been wanting to experiment with using $4011 for sound samples for a while. I understand basically all you have to do is at (carefully) timed intervals, load and store a value into $4011. That's easy enough.

However, I'm a total newb when it comes to the way sound works in general. So the actual data that is stored in there, I have no idea how it works. I don't know what the values actually represent, and I just thought I'd ask: what do they mean?

Secondly, what should I do to go about making a store-it-into-$4011-friendly sound sample from an audio file?

Thanks so much in advance.
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

Celius wrote: However, I'm a total newb when it comes to the way sound works in general. So the actual data that is stored in there, I have no idea how it works. I don't know what the values actually represent, and I just thought I'd ask: what do they mean?
Sound works in waves, length of the wave is the frequency. The timing that the sample changes with (your $4011 update rate) is the frequency (aka digital sample-rate). The values that you write to $4011 is the amplitude for each sample.
Secondly, what should I do to go about making a store-it-into-$4011-friendly sound sample from an audio file?
Save it in an 8-bit unsigned format. Since $4011 is 7-bit, you could either reduce the volume by half on the whole sample beforehand, or do an LSR on-the-fly as you play each sample.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Celius wrote:what do they mean?
The values are raw PCM data. Each value is a "photo" taken of a sound wave at a particular instant in time. With a series of values you can draw any sound wave you want, with 7 bits of precision.

WAV files are just like that, a series of "photos" of a sound wave taken at a certain frequency. You can easily convert information from WAV files into the raw values the NES expects, you just have to research the exact format of the numbers. You have to know if they are signed or not, that kind of thing. This is a place with a few documents about the WAV format.

You'll have to see the frequency at which you'll be able to write the values on the NES, and you'll probably have to use a sound editor to convert the source WAV file to that frequency. Or you could just try to achieve the same frequency used by the original WAV file.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Thanks for the replies, guys.

So you have to convert a WAV file to a raw format (assuming you have a WAV file)?

Also, I understand that pitch is determined by frequency, and that if you play the sample faster, the pitch will be higher. But I still don't know how pitch is determined within the sample. All the values are "amplitudes", you say. Does that just mean they're like Y values for a "pixelated" (quantized?) sound wave? And also, are the values signed or unsigned?

Sorry for all the questions. Thanks again, guys for helping me.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

The pitch is determined within a simple at which rate a waveform repeats. If you understand what a square wave is, how close to each other the edge are determines the frequency (or pitch). How height the wave is determine the amplitude (or volume).

WAV files can be made with more complex forms than square waves. With fourrier transform, everything can be decomposed into a sum of sine waves. The lowest freqency sine wave is the fundamental and determines the pitch of the sound. The higher frequency of sine waves are the harmonics and determine how the sound sounds. Note that some waves, such as white noise cannot be decomposed into sine waves because they are random, so this doesn't appy. That's why you don't hear any pitch when you hear white noise (or any other kind of "noise").
Useless, lumbering half-wits don't scare us.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Celius wrote:However, I'm a total newb when it comes to the way sound works in general.
Bores.com has a DSP tutorial that should help you understand.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Celius wrote:Does that just mean they're like Y values for a "pixelated" (quantized?) sound wave?
That's pretty much it. The frequency in which these Y coordinates are updated is... well, the frequency.

I second your question: The 7 bits the NES expects should represent a signed value?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Values written to $4011 are not signed. $40 is center,[1] $00 is bottom, and $7F is top.

[1] Almost. The DAC is in fact slightly nonlinear, though not nearly as much as on the Game Gear.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

So take these graphs of waves:

Code: Select all

|
|
| xx xx xx xx x
|xxxxxxxxxxxxxx
|xxxxxxxxxxxxxx
|--------------

|  x    x    x
| xxx  xxx  xxx
|xxxxxxxxxxxxxx
|xxxxxxxxxxxxxx
|xxxxxxxxxxxxxx
|--------------

All "x"s are 1 sample fetch wide, and the higher the number of x's stacked, the higher the number stored into $4011 is. Basically it's a bad graph. But the top one would make a higher, quieter sound, and the lower one would make a lower, louder sound, right?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Correct. The top one has a period (time between repeats) of 3 samples and an amplitude (half the distance between top and bottom) of 0.5. The bottom one has a period of 5 samples and an amplitude of 1.0.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Okay, I've got some samples working now by doing the lsr trick memblers mentioned. It was an 8-bit mono WAV file at 6 KHz. I'm not quite sure why it didn't work when I tried it last, but now it did.

I was hoping to make some use of this channel running at 60 Hz (hahaha). Yeah, probably not going to happen for anything but like a helicopter sound effect. It might be possible to play sounds clocked at really low speeds though (6000 Hz max if you plan on performing anything while playing samples, even if using an IRQ). For example, I wanted to have my character die in the game, and possibly let out a scream of some sort. Their body flies back, and the screen would scroll over a little while it plays the game over music. For that, I'd have to do a little game logic, and would probably want to play the sound with a scanline counter. And I would want to do that as little as possible, so the quality would have to be lowish...
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Celius wrote:I was hoping to make some use of this channel running at 60 Hz (hahaha). Yeah, probably not going to happen for anything but like a helicopter sound effect.
I just tried an S3M simulation of writing $7F, $3F, $1F, $00, at 60 Hz, and it made a sound that could be used as a passable kick drum.
For example, I wanted to have my character die in the game, and possibly let out a scream of some sort. Their body flies back
You could try hardware DPCM playback instead. Otherwise, OAM DMA will cause a 512-cycle hiccup in your sample playback.

One thing you can do to save space is convert your samples into 4-bit and pack two samples to the byte. Plenty of commercial NES games did this with linear PCM (e.g. $8A $43 $67 $D6 in wav -> $84 $6D in rom -> $40 $20 $30 $68 in $4011) for a modest improvement over hardware DPCM quality especially in the treble. In another topic, I explained a software ADPCM technique that brought still more improvement.
Post Reply