Hi guys,
I am writing an emulator for learning purposes and have completed it with the exception of sound emulation. I am not writing a NES emulator yet but the console I am emulating sound is very very similar so im hoping you guys can give me a hand.
I have no knowledge of how sound emulation is intended to work and no knowledge of sound programming in general which is why im finding this very difficult. It is not so much the technical side Im having trouble with but how the compontents work together to produce sound.
Anyway I am going to emulate the two square waves first but need help understanding the logic behind how these work. This is my understanding, if you could fill in the blanks or correct any mistakes I have (there will be plenty) then that'd be great.
1. The programmerable timer is an 11 bit down counter which combines two sound registers together to get its value. This counts down at a set frequency which I update after every opcode emulation by the amount of cycles that opcode takes. When this reaches 0 then it reloads itself by combining the two registers again. Everything ok up to this point? Im also unsure what happens if the two sound registers which create the programmable timer are written to before the current timer has reached 0, does it start the count down process again or does it only change when the timer reaches 0 and reloads?
2. The duty cycle is a way of changing the output of the wave from positive to negative. Depending on the duty cycle wave this can give different ratios of positive to negative. If it is set to 50% then there will be the same amount of positive outputs as negative etc. This gives a value to count down whenever the programmable timer reaches 0. So using the 50% as an example it will count down from 4 to 0 (which means the programmable timer has reloaded 4 times) and at this point it changes its polarity and counts down from 4 again. This ok so far?
3. The length counter is a way of turning off the channel when the length counter reaches 0. Once again does the length counter decrement in value every time the programmable timer reaches 0? The length counter only takes affect if it is enabled.
4. Combining the programmable timer with the duty cycle generator will give a value of +1 or -1 this then gets multipled by the volume and added to the playback buffer. The volume is controlled by a volume envelope which starts at a set volume and gets increased or decreased by a value of 1 for a set amount of steps. Is this correct and at which point does the volume change its value, is it again tied into the programmable timer reaching 0?
I am aware that I have probably made a lot of mistakes so any help would be greatly appreciated.
Thanks
I am writing an emulator for learning purposes and have completed it with the exception of sound emulation. I am not writing a NES emulator yet but the console I am emulating sound is very very similar so im hoping you guys can give me a hand.
I have no knowledge of how sound emulation is intended to work and no knowledge of sound programming in general which is why im finding this very difficult. It is not so much the technical side Im having trouble with but how the compontents work together to produce sound.
Anyway I am going to emulate the two square waves first but need help understanding the logic behind how these work. This is my understanding, if you could fill in the blanks or correct any mistakes I have (there will be plenty) then that'd be great.
1. The programmerable timer is an 11 bit down counter which combines two sound registers together to get its value. This counts down at a set frequency which I update after every opcode emulation by the amount of cycles that opcode takes. When this reaches 0 then it reloads itself by combining the two registers again. Everything ok up to this point? Im also unsure what happens if the two sound registers which create the programmable timer are written to before the current timer has reached 0, does it start the count down process again or does it only change when the timer reaches 0 and reloads?
2. The duty cycle is a way of changing the output of the wave from positive to negative. Depending on the duty cycle wave this can give different ratios of positive to negative. If it is set to 50% then there will be the same amount of positive outputs as negative etc. This gives a value to count down whenever the programmable timer reaches 0. So using the 50% as an example it will count down from 4 to 0 (which means the programmable timer has reloaded 4 times) and at this point it changes its polarity and counts down from 4 again. This ok so far?
3. The length counter is a way of turning off the channel when the length counter reaches 0. Once again does the length counter decrement in value every time the programmable timer reaches 0? The length counter only takes affect if it is enabled.
4. Combining the programmable timer with the duty cycle generator will give a value of +1 or -1 this then gets multipled by the volume and added to the playback buffer. The volume is controlled by a volume envelope which starts at a set volume and gets increased or decreased by a value of 1 for a set amount of steps. Is this correct and at which point does the volume change its value, is it again tied into the programmable timer reaching 0?
I am aware that I have probably made a lot of mistakes so any help would be greatly appreciated.
Thanks