···55/*****************************************************************************
66 * File name: src/drivers/sound/sound.c *
77 * Created: 2009-10-17 by Hampa Hug <hampa@hampa.ch> *
88- * Copyright: (C) 2009-2017 Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2009-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···198198 }
199199}
200200201201-202201const uint16_t *snd_filter (sound_drv_t *sdrv, const uint16_t *buf, unsigned cnt)
203202{
204203 unsigned i;
205204 unsigned long scnt;
206205 uint16_t *sbuf;
207206208208- if (sdrv->lowpass_freq == 0) {
209209- return (buf);
210210- }
211211-212207 scnt = (unsigned long) sdrv->channels * (unsigned long) cnt;
213208214214- sbuf = snd_get_sbuf (sdrv, scnt);
215215-216216- if (sbuf == NULL) {
209209+ if ((sbuf = snd_get_sbuf (sdrv, scnt)) == NULL) {
217210 return (NULL);
218211 }
219212220220- for (i = 0; i < sdrv->channels; i++) {
221221- snd_iir2_filter (
222222- &sdrv->lowpass_iir2[i], sbuf + i, buf + i,
223223- cnt, sdrv->channels, sdrv->sample_sign
224224- );
213213+ if (sdrv->lowpass_freq != 0) {
214214+ for (i = 0; i < sdrv->channels; i++) {
215215+ snd_iir2_filter (
216216+ &sdrv->lowpass_iir2[i], sbuf + i, buf + i,
217217+ cnt, sdrv->channels, sdrv->sample_sign
218218+ );
219219+ }
220220+221221+ buf = sbuf;
225222 }
226223227227- return (sbuf);
224224+ if (sdrv->volume != 256) {
225225+ snd_volume (sbuf, buf, scnt, sdrv->volume, sdrv->sample_sign);
226226+ buf = sbuf;
227227+ }
228228+229229+ return (buf);
228230}
229231230232int snd_write (sound_drv_t *sdrv, const uint16_t *buf, unsigned cnt)
···320322 return (0);
321323}
322324325325+void snd_set_volume (sound_drv_t *sdrv, unsigned val)
326326+{
327327+ sdrv->volume = (val <= 65535) ? val : 65535;
328328+}
329329+323330static
324331sound_drv_t *snd_open_sdrv (sound_drv_t *sdrv, const char *name)
325332{
333333+ unsigned long val;
334334+326335 if (sdrv == NULL) {
327336 return (NULL);
328337 }
···331340 snd_close (sdrv);
332341 return (NULL);
333342 }
343343+344344+ val = drv_get_option_uint (name, "volume", 100);
345345+346346+ snd_set_volume (sdrv, (256 * val + 50) / 100);
334347335348 sdrv->wav_filter = drv_get_option_bool (name, "wavfilter", 1);
336349
+6-2
src/drivers/sound/sound.h
···55/*****************************************************************************
66 * File name: src/drivers/sound/sound.h *
77 * Created: 2009-10-17 by Hampa Hug <hampa@hampa.ch> *
88- * Copyright: (C) 2009-2017 Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2009-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···4444 unsigned channels;
4545 unsigned long sample_rate;
4646 int sample_sign;
4747+4848+ unsigned volume;
47494850 unsigned long lowpass_freq;
4951 sound_iir2_t lowpass_iir2[SND_CHN_MAX];
···138140int snd_set_params (sound_drv_t *sdrv, unsigned chn, unsigned long srate, int sign);
139141140142int snd_set_opts (sound_drv_t *sdrv, unsigned opts, int val);
143143+144144+void snd_set_volume (sound_drv_t *sdrv, unsigned val);
141145142146143147sound_drv_t *snd_open (const char *name);