Another optimization question - can I speed up this 32 bit multiply?

darryl:

One thing I don't want to do is use shift for volume, or try to squeeze everything into 16 volume levels so I only need to use a 16 bit number to hold the sample when I multiply it. That would result in too large of steps for the volume. I want to read a pot and have the volume change smoothly.

but if your reading a pot, via a 10bit ADC, then to set the volume you will only ever have 1024 range ( 0->1023 ) for values to go from min to max, so why not use a shift ? if you need the value to a larger size ?

I'm not sure what you mean.

I have a 12 bit sample. Let's say the value of it is 4095.
Now let's say I read my pot and the value of it is 512.
512/1024 = 0.5
So to get the value of my sample after adjusting by my volume, I go 4095 * 0.5, and I get 2047.

But floats are expensive. So how can I get rid of them?

Well, I can change the order of my operations. I can instead multiply 4095 by my ADC reading... 512, an integer... and THEN divide by 1024, which I can do by shifting.

But, since my sample is 12 bits, multiplying by a 10 bit number may cause the result to exceed 16 bits. So I have to multiply it into a 32 bit number. At least if I do it in C.
OR, I can decide to use only 8 bits of my ADC, do it in assembly, start from a 16 bit sample, multply that into a 24 but number, and then just discard the lowest 8 bits.