Date: Fri, 20 Dec 2019 15:43:04 -0300 From: Marcel Bonnet <marcelbonnet@gmail.com> To: FreeBSD multimedia <freebsd-multimedia@freebsd.org> Subject: [off-topic] Applying gain to an audio sample Message-ID: <CAPe0dB=BGyeLX3Xue=nNpHqRn8s-4xAO_T4Asmv-DUGk8uu2Jg@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPe0dB=BGyeLX3Xue=nNpHqRn8s-4xAO_T4Asmv-DUGk8uu2Jg>