Sound Question

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Sound Question

Post by Celius » Mon Jun 06, 2005 6:01 pm

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... :)

User avatar
Disch
Posts: 1849
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch » Mon Jun 06, 2005 6:35 pm

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)
Last edited by Disch on Mon Jun 06, 2005 6:42 pm, edited 1 time in total.

User avatar
Zepper
Formerly Fx3
Posts: 3190
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Post by Zepper » Mon Jun 06, 2005 6:40 pm

Uh... time for a moderator, Disch? ;)

User avatar
Disch
Posts: 1849
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch » Mon Jun 06, 2005 6:43 pm

do these forums even have moderators? I guess memblers... =P

Post Reply