[off-topic] Applying gain to an audio sample

Marcel Bonnet marcelbonnet at gmail.com
Fri Dec 20 18:43:31 UTC 2019


Hi, fellows.

I was hesitating to make this question, but I felt motivated by the
Handbook [1] when it says "The mailing lists are the most direct way of
addressing questions or opening a technical discussion to a concentrated
FreeBSD audience" .

It's a newby question on audio programming. I have this simple OSS
application attached to this email to record and playback a file. I studded
the internals of audio/ecasound and audio/sox and wrote two identical apps
in C++ and C , and none of them correctly apply gain to the audio samples.
The one attached is in C. I used the same approach as  in sox src/vol.c [2]
to turn the volume down:

- read an audio sample as integer (stereo 16 bit LE)
- convert to float
- apply a gain, like: sample *= 0.3f
- convert to integer again

But the sound becomes distorted and noisy.

I would be glad with help and/or recommendation about Audio Programming
books, too.

If this e-mail is going too far from the objectives of the list, please
apologize and feel free to say so.

Thanks,

[1]
https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/eresources-mail.html
[2] https://sourceforge.net/p/sox/code/ci/master/tree/src/vol.c

-- 
Marcel Bonnet


More information about the freebsd-multimedia mailing list