···55/*****************************************************************************
66 * File name: src/drivers/sound/filter.c *
77 * Created: 2010-08-27 by Hampa Hug <hampa@hampa.ch> *
88- * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2010-2025 Hampa Hug <hampa@hampa.ch> *
99 *****************************************************************************/
10101111/*****************************************************************************
···1515 * *
1616 * This program is distributed in the hope that it will be useful, but *
1717 * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919 * Public License for more details. *
2020 *****************************************************************************/
2121···30303131#define SND_IIR_MUL 8192
32323333+3434+void snd_volume (uint16_t *dst, const uint16_t *src, unsigned long cnt, unsigned volume, int sign)
3535+{
3636+ unsigned long i;
3737+ long val, vol;
3838+ unsigned sig;
3939+4040+ sig = sign ? 0x8000 : 0x0000;
4141+ vol = (long) volume;
4242+4343+ for (i = 0; i < cnt; i++) {
4444+ val = (long) (src[i] ^ sig) - 32768;
4545+ val = (vol * val + 127) / 256 + 32768;
4646+4747+ if (val < 0) {
4848+ val = 0;
4949+ }
5050+ else if (val > 65535) {
5151+ val = 65535;
5252+ }
5353+5454+ dst[i] = (unsigned) val ^ sig;
5555+ }
5656+}
33573458void snd_iir2_init (sound_iir2_t *iir)
3559{
+12-2
src/drivers/sound/filter.h
···55/*****************************************************************************
66 * File name: src/drivers/sound/sound.h *
77 * Created: 2010-08-27 by Hampa Hug <hampa@hampa.ch> *
88- * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2010-2025 Hampa Hug <hampa@hampa.ch> *
99 *****************************************************************************/
10101111/*****************************************************************************
···1515 * *
1616 * This program is distributed in the hope that it will be useful, but *
1717 * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919 * Public License for more details. *
2020 *****************************************************************************/
2121···3737 long y[3];
3838} sound_iir2_t;
39394040+4141+/*!***************************************************************************
4242+ * @short Adjust the volume
4343+ * @param dst The destination buffer
4444+ * @param src The source buffer
4545+ * @param cnt The sample count
4646+ * @param volume The volume adjustment is (volume / 256)
4747+ * @param sign The sample signedness in both src and dst
4848+ *****************************************************************************/
4949+void snd_volume (uint16_t *dst, const uint16_t *src, unsigned long cnt, unsigned volume, int sign);
40504151/*!***************************************************************************
4252 * @short Initialize an IIR2 filter