M5Unified icon indicating copy to clipboard operation
M5Unified copied to clipboard

channel default volume is unusual

Open belm0 opened this issue 3 years ago • 5 comments

I was surprised that the channel default volume is 64. In audio designs, usually channel volume is attenuation only. So I'd expect the default to be the maximum (255).

Otherwise, the master volume doesn't really mean the "maximum volume", and some channels may have a volume equivalent to a master volume of 1024...

https://github.com/m5stack/M5Unified/blob/42717f09c24e5af3f8edeef097c2755fdc36b571/src/utility/Speaker_Class.hpp#L234

belm0 avatar Jul 17 '22 12:07 belm0

@belm0 Thank you for your important input. I apologize for any inconvenience caused by my ignorance of standard audio designs thinking. I will review the volume settings in the next version and set the default channel volume to 255.

By the way, the volume value is calculated internally as a square ( volume ^ 2 ) . In other words, the output varies quadratically. Both master volume and channel volume. Do you have any opinions or generalizations about this process?

lovyan03 avatar Jul 17 '22 12:07 lovyan03

By the way, the volume value is calculated internally as a square ( volume ^ 2 )

I was going to say something about this requiring a 64-bit intermediate value for each sample unless some optimizations are done, but then I realized that the code is using a float buffer. I'm a little surprised because float is not very fast on ESP32, so I guess this is a luxury sound library 😉

belm0 avatar Jul 17 '22 14:07 belm0

@belm0 Oh.. yes, I was reluctant to use floats, but I couldn't think of a better way. In fact, I've been racking my brains because I later realized that the float operation is even slower in ESP32C3…😨

lovyan03 avatar Jul 17 '22 15:07 lovyan03

I have no doubt that multi-channel, 16-bit sound can be handled well within fixed-point, 32-bit operations. (The PlayStation or early consoles and sound cards had no floating point hardware, etc.)

To start, 32-bit dynamic range is really not needed for volume.

belm0 avatar Jul 18 '22 00:07 belm0

This ticket can be closed as resolved. Suggesting to create a new ticket if there is a reason to keep track of looking into the use of integers instead of floats (as discussed a bit in comments to this ticket).

mdxs avatar Apr 17 '24 14:04 mdxs