I haven't really done anything with music yet, apart from the first two or three Nerdy Nights music tutorials. So I wanted to ask:
Assuming that I have a soundtrack, i.e. it is known what notes are put into what APU channel for what amount of time: How complex is the actual code for this?
I was under the impression that you simply read the values from a constant array and then put them into the port addresses. A simple loop that reads the APU value and the number of frames this sound is supposed to be on. And then you set the value to the APU port, start the counter and when the counter is 0, you set the next music value. And this you do with all three channels.
Pseudo code:
But I've read several times that people write their own sound drivers etc. So, is this really that complicated? Do I have to implement an elaborated music function if I want to do music with a game?
Assuming that I have a soundtrack, i.e. it is known what notes are put into what APU channel for what amount of time: How complex is the actual code for this?
I was under the impression that you simply read the values from a constant array and then put them into the port addresses. A simple loop that reads the APU value and the number of frames this sound is supposed to be on. And then you set the value to the APU port, start the counter and when the counter is 0, you set the next music value. And this you do with all three channels.
Pseudo code:
Code:
OncePerFrame:
if StopMusic
WriteToApu(SquareWavePort1, 0)
WriteToApu(SquareWavePort2, 0)
Timer = 0
ArrayIndex = 0
else if Timer = 0
MusicData1 = ReadNextArrayValue
MusicData2 = ReadNextArrayValue
Timer = ReadNextArrayValue
if ArrayIndex = ArraySize
ArrayIndex = 0
WriteToApu(SquareWavePort1, MusicData1)
WriteToApu(SquareWavePort1, MusicData2)
else
Timer = Timer - 1
if StopMusic
WriteToApu(SquareWavePort1, 0)
WriteToApu(SquareWavePort2, 0)
Timer = 0
ArrayIndex = 0
else if Timer = 0
MusicData1 = ReadNextArrayValue
MusicData2 = ReadNextArrayValue
Timer = ReadNextArrayValue
if ArrayIndex = ArraySize
ArrayIndex = 0
WriteToApu(SquareWavePort1, MusicData1)
WriteToApu(SquareWavePort1, MusicData2)
else
Timer = Timer - 1
But I've read several times that people write their own sound drivers etc. So, is this really that complicated? Do I have to implement an elaborated music function if I want to do music with a game?