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

Configure Feed

Select the types of activity you want to include in your feed.

sound: Support volume adjustment in sound drivers

+35 -18
+29 -16
src/drivers/sound/sound.c
··· 5 5 /***************************************************************************** 6 6 * File name: src/drivers/sound/sound.c * 7 7 * Created: 2009-10-17 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2009-2017 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2009-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 ··· 198 198 } 199 199 } 200 200 201 - 202 201 const uint16_t *snd_filter (sound_drv_t *sdrv, const uint16_t *buf, unsigned cnt) 203 202 { 204 203 unsigned i; 205 204 unsigned long scnt; 206 205 uint16_t *sbuf; 207 206 208 - if (sdrv->lowpass_freq == 0) { 209 - return (buf); 210 - } 211 - 212 207 scnt = (unsigned long) sdrv->channels * (unsigned long) cnt; 213 208 214 - sbuf = snd_get_sbuf (sdrv, scnt); 215 - 216 - if (sbuf == NULL) { 209 + if ((sbuf = snd_get_sbuf (sdrv, scnt)) == NULL) { 217 210 return (NULL); 218 211 } 219 212 220 - for (i = 0; i < sdrv->channels; i++) { 221 - snd_iir2_filter ( 222 - &sdrv->lowpass_iir2[i], sbuf + i, buf + i, 223 - cnt, sdrv->channels, sdrv->sample_sign 224 - ); 213 + if (sdrv->lowpass_freq != 0) { 214 + for (i = 0; i < sdrv->channels; i++) { 215 + snd_iir2_filter ( 216 + &sdrv->lowpass_iir2[i], sbuf + i, buf + i, 217 + cnt, sdrv->channels, sdrv->sample_sign 218 + ); 219 + } 220 + 221 + buf = sbuf; 225 222 } 226 223 227 - return (sbuf); 224 + if (sdrv->volume != 256) { 225 + snd_volume (sbuf, buf, scnt, sdrv->volume, sdrv->sample_sign); 226 + buf = sbuf; 227 + } 228 + 229 + return (buf); 228 230 } 229 231 230 232 int snd_write (sound_drv_t *sdrv, const uint16_t *buf, unsigned cnt) ··· 320 322 return (0); 321 323 } 322 324 325 + void snd_set_volume (sound_drv_t *sdrv, unsigned val) 326 + { 327 + sdrv->volume = (val <= 65535) ? val : 65535; 328 + } 329 + 323 330 static 324 331 sound_drv_t *snd_open_sdrv (sound_drv_t *sdrv, const char *name) 325 332 { 333 + unsigned long val; 334 + 326 335 if (sdrv == NULL) { 327 336 return (NULL); 328 337 } ··· 331 340 snd_close (sdrv); 332 341 return (NULL); 333 342 } 343 + 344 + val = drv_get_option_uint (name, "volume", 100); 345 + 346 + snd_set_volume (sdrv, (256 * val + 50) / 100); 334 347 335 348 sdrv->wav_filter = drv_get_option_bool (name, "wavfilter", 1); 336 349
+6 -2
src/drivers/sound/sound.h
··· 5 5 /***************************************************************************** 6 6 * File name: src/drivers/sound/sound.h * 7 7 * Created: 2009-10-17 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2009-2017 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2009-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 ··· 44 44 unsigned channels; 45 45 unsigned long sample_rate; 46 46 int sample_sign; 47 + 48 + unsigned volume; 47 49 48 50 unsigned long lowpass_freq; 49 51 sound_iir2_t lowpass_iir2[SND_CHN_MAX]; ··· 138 140 int snd_set_params (sound_drv_t *sdrv, unsigned chn, unsigned long srate, int sign); 139 141 140 142 int snd_set_opts (sound_drv_t *sdrv, unsigned opts, int val); 143 + 144 + void snd_set_volume (sound_drv_t *sdrv, unsigned val); 141 145 142 146 143 147 sound_drv_t *snd_open (const char *name);