@BaggyCatEntertainment - 1 month ago
So bizarre again Charles to have a video made about my ancient music!!
But thank you for being so complimentary, it's very much appreciated.
Just to go full-nerd on how the multi-channel thing worked, the Z80 processor in the ZX Spectrum, similar to most processors, has 'registers,' which are basically like a set of chip-level variables you can use to do things like count up and down and do basic math calculations etc.
So the way I generated multiple channels was to assign three or four or five of these registers (depending on how many simultaneous notes I wanted) to different values, then I had a closed loop that just counted each register down to 0, at which point it would execute a 'click' sound - the pulse width of the click dictated the volume like Charles described.
The loop ran just about fast enough that these clicks went at a frequency high enough to make sound.
The sound loop would run for a certain number of cycles, then jump out in order to change the pitch of the notes, then continue with the loop again.
All the notes were contained in number arrays, which I just typed in manually.
The numbers related to the frequency of each note, in terms of how many times per loop the click would happen - the more frequent the higher the note. So it was all just a process of trial and error to find the different notes, which is why they're often out of tune!
Also if the loop contained higher notes - i.e. a higher frequency of clicks - the overall speed would slow, so I had to correct for it by increasing the note values.
The issue was keeping up the speed of the loop, so another thing I did was to use 'self-modifying' code - when the registers counted down to zero, I'd just set them back to a specific value (i.e. let a=40), because looking up a variable (i.e. let a=noteOneValue) would have slowed the loop down too much - then in the main loop I'd write over the bit of code in memory where it set the register to a number with the new values.
As regards the music, well all I can say is I grew up with a piano in the house and two older brothers with a love of prog!