diff --git a/src/cli.c b/src/cli.c index 8f8b471..634c208 100644 --- a/src/cli.c +++ b/src/cli.c @@ -37,7 +37,9 @@ extern int alsaVolume; /* default volume */ extern int defaultVolume; -extern int volumeSet; +extern int volumeOffset; +extern int alsaVolumeOffset; +extern int volumeMultiplier; /* command line options */ const char *shortOptions = "P:V:adhv"; const struct option longOptions[] = { @@ -101,13 +103,14 @@ void process_cli(int argc, char **argv) show_version(); break; case 'x': - volumeSet = 1; - defaultVolume = atoi(optarg); - if (defaultVolume < 1 || defaultVolume > 150) { + alsaVolumeOffset = volumeOffset = atoi(optarg); + if (volumeOffset < 1 || volumeOffset > 150) { fprintf(stderr, "WARNING: Volume must be between 1 and 150\n"); - volumeSet = 0; + volumeOffset = 0; } - break; + alsaVolumeOffset -= (defaultVolume + 1) * 50 / 10 + 50; + volumeOffset -= (defaultVolume + 1) * volumeMultiplier; + break; case -1: case 0: break; diff --git a/src/espeak.c b/src/espeak.c index aeaac74..151c31a 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -33,7 +33,8 @@ const int defaultPitch = 5; const int defaultRange = 5; const int defaultRate = 2; int defaultVolume = 5; -int volumeSet = 0; +int volumeOffset = 0; +int alsaVolumeOffset = 0; char *defaultVoice = NULL; int alsaVolume = 0; @@ -203,11 +204,10 @@ static void set_alsa_volume(int vol) * volume (80%), and make higher values increase ALSA volume, up to * 100%. */ - int volume = (vol + 1) * 50 / 10 + 50; - /*lock the volume to the user-set volume if specified*/ - if(volumeSet){ - volume = defaultVolume; - } + int volume = (vol + 1) * 50 / 10 + 50 + alsaVolumeOffset; + + if(volume < 0) + volume = 0; for (e = snd_mixer_first_elem(m); e; e = snd_mixer_elem_next(e)) { if (snd_mixer_elem_get_type(e) != SND_MIXER_ELEM_SIMPLE) @@ -250,20 +250,19 @@ static void set_alsa_volume(int vol) static espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj) { espeak_ERROR rc; - + int espeakVolume; if (adj == ADJ_DEC) vol = -vol; if (adj != ADJ_SET) vol += s->volume; - /*lock the volume to the user-set volume if specified*/ - if (volumeSet) { - rc = espeak_SetParameter(espeakVOLUME, defaultVolume, 0); - } - else { - rc = espeak_SetParameter(espeakVOLUME, (vol + 1) * volumeMultiplier, 0); - } + espeakVolume = (vol + 1) * volumeMultiplier + volumeOffset; + if(espeakVolume < 0) + espeakVolume = 0; + + rc = espeak_SetParameter(espeakVOLUME, espeakVolume, 0); + if (rc == EE_OK) { s->volume = vol; if (alsaVolume)