fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation

sound: Add a volume adjustment filter function

+38 -4
+26 -2
src/drivers/sound/filter.c
··· 5 5 /***************************************************************************** 6 6 * File name: src/drivers/sound/filter.c * 7 7 * Created: 2010-08-27 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2010-2025 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 15 15 * * 16 16 * This program is distributed in the hope that it will be useful, but * 17 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 19 * Public License for more details. * 20 20 *****************************************************************************/ 21 21 ··· 30 30 31 31 #define SND_IIR_MUL 8192 32 32 33 + 34 + void snd_volume (uint16_t *dst, const uint16_t *src, unsigned long cnt, unsigned volume, int sign) 35 + { 36 + unsigned long i; 37 + long val, vol; 38 + unsigned sig; 39 + 40 + sig = sign ? 0x8000 : 0x0000; 41 + vol = (long) volume; 42 + 43 + for (i = 0; i < cnt; i++) { 44 + val = (long) (src[i] ^ sig) - 32768; 45 + val = (vol * val + 127) / 256 + 32768; 46 + 47 + if (val < 0) { 48 + val = 0; 49 + } 50 + else if (val > 65535) { 51 + val = 65535; 52 + } 53 + 54 + dst[i] = (unsigned) val ^ sig; 55 + } 56 + } 33 57 34 58 void snd_iir2_init (sound_iir2_t *iir) 35 59 {
+12 -2
src/drivers/sound/filter.h
··· 5 5 /***************************************************************************** 6 6 * File name: src/drivers/sound/sound.h * 7 7 * Created: 2010-08-27 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2010-2025 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 15 15 * * 16 16 * This program is distributed in the hope that it will be useful, but * 17 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 19 * Public License for more details. * 20 20 *****************************************************************************/ 21 21 ··· 37 37 long y[3]; 38 38 } sound_iir2_t; 39 39 40 + 41 + /*!*************************************************************************** 42 + * @short Adjust the volume 43 + * @param dst The destination buffer 44 + * @param src The source buffer 45 + * @param cnt The sample count 46 + * @param volume The volume adjustment is (volume / 256) 47 + * @param sign The sample signedness in both src and dst 48 + *****************************************************************************/ 49 + void snd_volume (uint16_t *dst, const uint16_t *src, unsigned long cnt, unsigned volume, int sign); 40 50 41 51 /*!*************************************************************************** 42 52 * @short Initialize an IIR2 filter