It is currently Sat Nov 18, 2017 11:02 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Thu Oct 22, 2015 12:50 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
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?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Thu Oct 22, 2015 3:18 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
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?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Thu Oct 22, 2015 4:14 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1823
Location: DIGDUG
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


Top
 Profile  
 
PostPosted: Thu Oct 22, 2015 11:26 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5822
Location: Canada
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 12:42 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
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?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 1:27 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10112
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 1:37 am 
Offline

Joined: Mon Oct 10, 2011 9:05 am
Posts: 22
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 1:55 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
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.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 2:19 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10112
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 3:34 am 
Offline

Joined: Mon Oct 10, 2011 9:05 am
Posts: 22
Quote:
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 3:56 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
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.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 5:11 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19225
Location: NE Indiana, USA (NTSC)
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:
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 2:39 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
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.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 4:01 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19225
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
PostPosted: Fri Oct 23, 2015 4:07 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1454
Oh, right. I didn't think of SMB3 and that these drum sounds appeared there first.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group