Sound Question

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Sound Question
by on (#2319)
This isn't an emulation question, but I ask it here, because people only seem to be active here. But, I'm not sure about how to do sound stuff. I can make a note, but I can't make it change or anything. I know you have to do something in 4017, but what? can someone give me an example of a sound code that has changing notes and rythyms? thank you... :)

by on (#2322)
this really should go in nesdev for the sake or keeping the forums organized -- pretty much everyone here browses both nesdev and nesemdev so it's not like we'll miss it.

Anyway, music generation code is just different notes played over a period of time.

For example if you want to make a "Ta-da" type sound, you could do it with something like the following:

- Start to play a note
- Wait 20 or so frames
- Stop the note
- Wait 2 or so frames
- Start the note up again
- Wait 120 or so frames
- Stop the note


A game could run its music engine by keeping track of which channel is playing what note -- as well as the length of the note. Every frame, a routine would be JSRed to, which a counter for each playing channel would decrease. When that counter hits zero, the game could pull the next note to play from its note list, play the new note, and reset it's counter to represent the desired length of the note.

Any example code I could write would be very lengthy and drawn-out -- so I won't do it. Too much work for a forum paste.


edit:

also, $4017 affects APU frame IRQs and the APU frame sequencer -- this changes the timing for sound sub-systems like the Sweep Unit, Decay Counter, and other areas. It isn't really vital to play sound.

Take a detailed look at $4015, and $4000-$400F --- those are the registers to know for sound playback. $4010-$4013 as well -- but that's for the DMC (operates quite differently from the other channels)

by on (#2326)
Uh... time for a moderator, Disch? ;)

by on (#2327)
do these forums even have moderators? I guess memblers... =P