From owner-freebsd-multimedia@freebsd.org Fri Dec 20 18:43:31 2019 Return-Path: Delivered-To: freebsd-multimedia@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 675F51E0BCE for ; Fri, 20 Dec 2019 18:43:31 +0000 (UTC) (envelope-from marcelbonnet@gmail.com) Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47fd1G1jPhz4H4Z for ; Fri, 20 Dec 2019 18:43:29 +0000 (UTC) (envelope-from marcelbonnet@gmail.com) Received: by mail-ot1-x32b.google.com with SMTP id k14so12942521otn.4 for ; Fri, 20 Dec 2019 10:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=rOla9hmVuVMkCPukEnci0UJybSE9+RRFKyZX4pELxPo=; b=GAIXFBWfXcolhqISQIXJnGJpSFJFh4jQo7a5fhy/StIcRiIjmc0S/aa74x1DxBMe6X NKsxNmu0TwvgJEA6gts7wZTl6tonexwBkEIxhK2P5xzDxlDBcyKKs6C3FL1D3ZbnJgMh KRPp/sNRSC/EkVcikM/baAbKcDcUjcHQo0ClfSTbKYjxjDKpNsjebN+wra8XFi8c+azG Fpcvvo2Lxybs8EuFojUQtf2TBugrZE0/odaFXctnM/bWWpOxbjE+CbJE3xJlQQDSdsHn Dsb3s5+YVJLAxLdIHRiP9Hh4yQQVOXDEto8SoczA6R1YqaXyBffmPuSU+psOi7/WSbzK b2Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rOla9hmVuVMkCPukEnci0UJybSE9+RRFKyZX4pELxPo=; b=fb9GRPCKLnfbJ3pofiN/oRhfSwMMMPJcPUpsNMkQ2Y2kjceHUK24VQhmuZ0bSOFPgw t5R5B4hoL4NyyQDHRuVyQdnWDipZInPVUo4M8s5vy4KKkyqwNwv6IORRcJ8R9pOfV0KP r9/QLUGryhy/1qhgA7sNdMpzHhAmqjIcdyPvmjRR2EeUFXPEd+LM9vqkW33hby1y9Pzq vavx90rAduwsofIZaOLtOjMdzjR/V+BiJ6kK3ZDl/6vO5XKv4IkndtOhuZz9ayKmC4dC hR6BbCF5pPQcAH/RzR95HAKOwq3MYhfbYMgvDXZAo1TtC9kmPv3nxVSY0IWG/Nxte69Z ao2A== X-Gm-Message-State: APjAAAV3k0zeNmuxdB60mGME0V5EKFmfJdxIg7IVwJlU+FqsPhpD36eQ L1PFkZnm5mOwgO4CIlK0lvH5xsAw2c3i/tKLD5e57faB X-Google-Smtp-Source: APXvYqwjhz3mPE2yhHPi7R2sSijr2ezO7xa0e7KPKnuweYX+zc/ndWYSb5ztOBdJM+DTf3NrPwLvWyZFdBvUqWZtaAA= X-Received: by 2002:a9d:2482:: with SMTP id z2mr15768677ota.279.1576867408514; Fri, 20 Dec 2019 10:43:28 -0800 (PST) MIME-Version: 1.0 From: Marcel Bonnet Date: Fri, 20 Dec 2019 15:43:04 -0300 Message-ID: Subject: [off-topic] Applying gain to an audio sample To: FreeBSD multimedia X-Rspamd-Queue-Id: 47fd1G1jPhz4H4Z X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=GAIXFBWf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of marcelbonnet@gmail.com designates 2607:f8b0:4864:20::32b as permitted sender) smtp.mailfrom=marcelbonnet@gmail.com X-Spamd-Result: default: False [-1.30 / 15.00]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; HAS_ATTACHMENT(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; MIME_BASE64_TEXT(0.10)[]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FROM_EQ_ENVFROM(0.00)[]; IP_SCORE(0.00)[ip: (-8.05), ipnet: 2607:f8b0::/32(-2.18), asn: 15169(-1.89), country: US(-0.05)]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:~,4:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/mixed,multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-multimedia@freebsd.org]; MIME_BAD_ATTACHMENT(1.60)[c]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE_FREEMAIL(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[b.2.3.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Dec 2019 18:43:31 -0000 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