I'm currently using libsndfile in combination with PortAudio V19 to read audio data from a file and play it back. (Please note I am doing this on a Raspberry Pi running Raspbian.) The problem I'm encountering is that I need to dynamically control the playback volume in real time for each audio sample played in this way. I've attempted to use system calls to manipulate the global playback volume via alsamixer, which would be an acceptable solution in my use case, but the latency is too high for this to work.
What I'm seeking is one of two things:
A library which can handle modifying audio volume in real time, either by acting on the raw audio data retrieved by libsndfile, or by setting the global playback volume with minimal latency (sub-millisecond). The library must be free (gratis) and usable on Raspbian; licensing is not a concern.
The mathematical transformations that need to be applied to the audio data retrieved by libsndfile, in order to modify the volume level of the data, preferably where the target volume is in the range [0.0f, 1.0f], with 0.0f being silent and 1.0f being the original volume from the file.
I've tried to look all over for useful (free) material on this subject and have failed to locate anything that helps. Any assistance is greatly appreciated!