How did old NES games use the various channels?

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

Moderator: Moderators

Post Reply
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

How did old NES games use the various channels?

Post by DRW »

I'm working on the Nerdy Nights NES sound tutorial and I've learned how various streams may share the sound channels.
For example, the music uses all channels, but when a sound effect is playing, that channel skips playing its music track and plays the sound effect instead. Then it resumes playing the music.

Now my question: How did the "small", arcade-like NES games around 1985/1986 do this? Did many of them also use all four channels for the music, skipping the music streams when sound effects were played?
Or did they declare right from the beginning that music only plays on Square 1, Square 2 and Triangle while sound effects play only on Noise?
I'm asking because my own game shall mimic an old highscore/arcade-like game from around 1986.

So, let's take, for example "Super Mario Bros.", "Kung Fu" and "Ice Climber": Which of the described methods did they use? Channel sharing or playing music only on three streams and sounds on the last one?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: How did old NES games use the various channels?

Post by DRW »

Another question: Is there a place where I can see some statistical data of the music of various games? I'm especially interested in the size of the soundtracks. For example: How many bytes in the ROM does the standard melody of "Super Mario Bros." occupy and what methods were used to compress it?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: How did old NES games use the various channels?

Post by dougeff »

Looking at SMB, it uses all 4 channels to play most of the songs. Some sound effects also share Square 1, some share square 2, some share the noise channel. It loads the sound effect into the sound register when a sound effect is triggered, with a timer that counts down. When the timer is 0, the music resumes for that channel. It does this while continuing the song on the other channels. Songs are broken into segments. Each segment looks about 80 bytes, some songs have 1 segment (time is running out song). Some songs have 4 or so segments.

I don't know every NES game, but (i think) generally the music data is uncompressed... but frequently use clever ways to reduce length (like reusing data for multiple songs).
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How did old NES games use the various channels?

Post by rainwarrior »

DRW wrote:Another question: Is there a place where I can see some statistical data of the music of various games? I'm especially interested in the size of the soundtracks. For example: How many bytes in the ROM does the standard melody of "Super Mario Bros." occupy and what methods were used to compress it?
If you find NSF rips, a lot of them are reduced to roughly just the music code and data. At worst it's an upper bound on the total amount of music stuff in the game, at best it's really close to containing only the music stuff (depends on how concerned the ripper was with removing unused data, and how it was organized in the ROM).

As far as knowing how the data is formed, that's really something you'd have to do a lot of reverse engineering to learn. Most music engines seem to work by having some kind of set of "instrument" data defining how to play a note (e.g. volume envelope, duty settings, etc.) and then a set of "notes" for each channel as the music data. Generally a note will be a byte, possibly followed by another byte saying how long to wait until the next note, and then other bytes can signify other things as needed (change of instrument, change of volume, repetition of block, etc.)

The most common "compression" technique, other than reducing empty space between notes to a single value (i.e. basically a form of RLE), is repetition. Organizing the music into short patterns that can be repeated and reused, and some data structure that lets the composer do the repetition.

With the popularity of Famitracker, a lot of people base their music around standard tracker ideas of "pattern" and "order", which can accomplish the repetition task in a limited way. When I disassembled Startropics' music code, I discovered that it had a rather simple system allowing 256 bytes of data per channel in a song, and it simply had control bytes to jump back and forth in the data, or repeat a section a set number of times, etc. I documented that format in the disassembly if you want to take a peek at how it was done in that game.

If you search RHDN for music hacks, you might find some documentation on the music data used in other NES games.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: How did old NES games use the various channels?

Post by DRW »

Thanks for the information.

How exactly do you choose "instruments"? Are these the four duty cycles in the square waves or is there something else to be done? Or are different notes also the different instruments?

Another question: Are there any (licensed) NES games where the music was exclusively on the first three channels while the sound effects were only on the fourth channel? Or was this never done?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How did old NES games use the various channels?

Post by tokumaru »

Instruments define how the notes will sound. Normally they're simply a set of duty/volume/etc parameters that get applied to the note every frame. The frequency can also be manipulated, using the note's frequency as reference, for other kinds of effects (arpeggios, slides and the like). Instrument changes are normally triggered by commands in the song data.

There are more compact sound formats that use a single byte to specify both the note and its length. This reduces the number of notes and lengths you can use, but you can use commands to select different octaves or length tables.

I don't think any games did what you're describing with the channels. Noise is often used for drums, which would definitely be missed if absent from the songs. At the same time, the type of sound generated by the noise channel is not suitable for all kinds of special effects. The game would sound very dull.
lazigamer
Posts: 23
Joined: Mon Oct 10, 2011 9:05 am

Re: How did old NES games use the various channels?

Post by lazigamer »

I'm fairly sure Final Fantasy doesn't use the noise channel in any of its songs. The sound effects use the noise channel and one of the square channels when necessary. Final Fantasy 2 might be the same way now that I think about it.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: How did old NES games use the various channels?

Post by DRW »

O.k., since the method of using three channels for the music and one for the sound doesn't seem to be common, in this case, I won't use it.

The reason why I ask all this is because when I do my sound engine, I'll try to do it as simple as possible while the sounds still sound good and not monotonous.

For example, I was playing with the idea that the volume and duty cycle cannot be changed during a song. This way, I don't have to include such a function in my sound engine and I don't have to check for a "volume changed" flag. Unless of course the music sounds crappy this way.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How did old NES games use the various channels?

Post by tokumaru »

DRW wrote:O.k., since the method of using three channels for the music and one for the sound doesn't seem to be common
Please, don't take my word for it, I haven't studied this in depth. I just think that the noise by itself won't make nice sound effects.
lazigamer
Posts: 23
Joined: Mon Oct 10, 2011 9:05 am

Re: How did old NES games use the various channels?

Post by lazigamer »

The reason why I ask all this is because when I do my sound engine, I'll try to do it as simple as possible while the sounds still sound good and not monotonous.
In a good sounding music engine there is usually a way to control the volume and pitch of a note over the duration of it being played. If you listen closely to many NES songs you'll find that the volume of a note will gradually drop as it plays, sometimes faster (a staccato effect), sometimes slower (a more melodic effect) depending on the effect desired. To make it simple in your engine, allow the selection of an initial volume and a decay rate (that could be done in a single byte). That alone will make for a pretty decent sounding music engine. Additionally, allowing the pitch of a note to change as its played gives you more effects like the sweep up and down (that Megaman uses often) and a gradual oscillation of the pitch (a vibrato effect). These can be implemented as a list of signed values that are gone through to add to the current pitch to achieve the effect. The duty cycle should be allowed to be changed too, at least on an instrument by instrument basis.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: How did old NES games use the various channels?

Post by DRW »

I guess I will ask my composer what kind of stuff he intends to do and then I'll add these features to the engine as needed.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How did old NES games use the various channels?

Post by tepples »

DRW wrote:Now my question: How did the "small", arcade-like NES games around 1985/1986 do this? Did many of them also use all four channels for the music, skipping the music streams when sound effects were played?
Or did they declare right from the beginning that music only plays on Square 1, Square 2 and Triangle while sound effects play only on Noise?
Very old games (1983-1984) would dedicate triangle to music and put sound effects on other channels. This is typical of Donkey Kong, Ice Climber, Lode Runner, and Bomberman. Balloon Fight had multi-channel sound effects, but if I remember correctly it couldn't play sound effects and music at once. But by mid-1985, Nintendo had the whole interruption thing figured out and used it in Super Mario Bros.

You mentioned compression. The closest thing to RLE compression in music is fitting a note's pitch and its duration into one byte, as I do in my own music engine.

Code: Select all

76543210
|||||+++- Duration: offset into table 1, 2, 3, 4, 6, 8, 12, 16
+++++---- 0-24: Offset in semitones from phrase's base note
          25: Tie. Add to previous note's length
          26: Rest. Key off previous note
This leaves values $D8 and up for effect triggers, such as instrument changes, transpose (move the pattern's base note up or down), arpeggio, legato (whether new notes restart the envelope or not), grace note (delays shorter than a row), and end of phrase.

If you want to see what can fit into 3 kilobytes, play the NSF I made of the soundtrack of my first few NROM games.

Do you want to see me polish up my music engine for a release and add the manual that I've been working on?
DRW wrote:Another question: Are there any (licensed) NES games where the music was exclusively on the first three channels while the sound effects were only on the fourth channel? Or was this never done?
Let me guess: You say "licensed" to exclude Crystal Mines and Exodus, which put music on the pulse channels and sound effects on triangle and noise.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: How did old NES games use the various channels?

Post by DRW »

tepples wrote:Very old games (1983-1984) would dedicate triangle to music and put sound effects on other channels.
I'll keep this in mind for my "A Nightmare on Elm Street" game. Which will have nothing to do with the "A Nightmare on Elm Street" NES game, by the way. Mine would be a non-scrolling arcade-like highscore game as if it was from 1984/1985. And it would be based specifically on the first movie. But the current game is more like 1985/1986. Complexity-wise, it could be compared with "Kung Fu".
tepples wrote:If you want to see what can fit into 3 kilobytes, play the NSF I made of the soundtrack of my first few NROM games.
Did you try to do this:
Super Mario All-Stars: SMB1/SMB3 Underground
?
tepples wrote:Do you want to see me polish up my music engine for a release and add the manual that I've been working on?
If you want to, you can do so. But I myself do not plan to include any third party code into my game. I want to write my stuff myself.
O.k., I take help with specific questions and I go through tutorials, but in the end, I'll type in all of the code myself and don't just include pre-made code.
tepples wrote:Let me guess: You say "licensed" to exclude Crystal Mines and Exodus, which put music on the pulse channels and sound effects on triangle and noise.
I didn't think specifically of those games, but yeah, I wanted to exclude all those crappy non-licensed stuff since I only wanted to know how it was done with the "real" games.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How did old NES games use the various channels?

Post by tepples »

DRW wrote:
tepples wrote:If you want to see what can fit into 3 kilobytes, play the NSF I made of the soundtrack of my first few NROM games.
Did you try to do this:
Super Mario All-Stars: SMB1/SMB3 Underground
?
That and the NES version. Mostly I wanted to demonstrate that triangle+noise drums could compete with sampled drums.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: How did old NES games use the various channels?

Post by DRW »

Oh, right. I didn't think of SMB3 and that these drum sounds appeared there first.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Post Reply