So as simply as making snd[t].volume range from 0 to 255 instead of 100 will be faster? sounds useful.
I think once I have this game out of the way, I should separate the sound stuff out into a separate example, currently it is capable of playing a sample at any (?) speed or volume, possibly multiple sounds at once, it might be helpful for other people.
This is why so many programmers are obsessed with powers of two.
Working with powers of two is almost always faster because mathetmatical operations can be replaced with bitwise operations (sometimes called bithacks/bithax).
To clarify why this is, pow(2, 1) == 2, pow(2, 2) == 4, pow(2, 3) == 8 (where pow is expotentiation, or ‘to the power of’).
Or to put it another way, shifting right divides by 2, so shifting right a second time divides by 2 again, and dividing by 2 twice is the same as dividing by 4.
I.e. ((x >> 1) >> 1) == (x >> 2) == ((x / 2) / 2) == (x / 4)
As for why shifting works as division and multiplication by a power of two, you need to understand binary to see why.
This was always something that annoyed me with AVR chips.
Not having a barrel shifter is criminal.
Actually, the compiler doesn’t always perform that optimisation.
(I still haven’t got round to fixing the issue yet, it’s somewhere on my ever growing todo list.)
You need to come to terms with the idea that the absolute value is meaningless. Only the velocity matters. When you make your first transistor amp and you read -200V peak from your 3.3V circuit, then you’re getting the feeling you need your head checked. The world, alas, is not digital