I don’t know the reason but a bit of math gives a reason.
First, a note: how a sound generator responds to a CC value is entirely up to the manufacturer or developer of the generator. What I found about CC7 is that the 40*log(CC7/127)40*log(CC7/127)
formula is a suggestion. Also, this is not gain, it’s “volume”. What does volume mean in this context? Whatever the manufacturer or developer of the sound generator wants it to mean.
One good reason to use a factor of 40 instead of 20 or 10 is that the possible output values of that function range from -84 to 0 (ignoring the input value of zero for the moment). With a factor of 20, the output only ranges from -42 to 0, and for a factor of 10 it’s only 21 to 0.
Of course the relationship inside the sound generator between the output value of the function and the gain (or attenuation) of the output amp can be made in any way. Also the characteristics of the amplifier are up in the air. That said, if the output of the function is used to set dB of attenuation, then a range of 84 dB is much more useful than 42 or less.
A factor could be chosen such that the output is -127 to 0, but in dB that is actually an overly broad range for output amp attenuation.
Why are we ignoring the input value of 0? Because the mathematical log of 0 is -infinity, which obviously will have to be handled specially in some way in and computer system applying this scaling function.
One way to handle it is to change the function to 40*log(CC7+1/128)40*log((CC7+1)/128)
, which outputs -84 to 0. Another way is to insert an if CC7=0CC7==0
statement that catches the invalid input and can just set the output to 0. Other solutions exist.