mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-09 09:19:09 +02:00
Offset default volume instead of overriding
This makes the default volume set to the user's --volume setting, while still allowing for the user to change the volume later on with keyboard shortcuts in speakup.
This commit is contained in:
parent
7ca1843dec
commit
134dfd1836
2 changed files with 22 additions and 20 deletions
15
src/cli.c
15
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;
|
||||
|
|
|
|||
27
src/espeak.c
27
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue