volume, mixer: removed the "relative" parameter

Since the "volume" command has been removed, nobody uses relative
volumes anymore.
This commit is contained in:
Max Kellermann 2009-07-06 21:51:24 +02:00
parent 206392ad1a
commit 90472526e0
5 changed files with 26 additions and 41 deletions

View File

@ -1061,7 +1061,7 @@ handle_setvol(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_int(client, &level, argv[1], need_integer)) if (!check_int(client, &level, argv[1], need_integer))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
success = volume_level_change(level, 0); success = volume_level_change(level);
if (!success) { if (!success) {
command_error(client, ACK_ERROR_SYSTEM, command_error(client, ACK_ERROR_SYSTEM,
"problems setting volume"); "problems setting volume");

View File

@ -70,7 +70,7 @@ mixer_all_get_volume(void)
} }
static bool static bool
output_mixer_set_volume(unsigned i, int volume, bool relative) output_mixer_set_volume(unsigned i, int volume)
{ {
struct audio_output *output; struct audio_output *output;
struct mixer *mixer; struct mixer *mixer;
@ -85,14 +85,6 @@ output_mixer_set_volume(unsigned i, int volume, bool relative)
if (mixer == NULL) if (mixer == NULL)
return false; return false;
if (relative) {
int prev = mixer_get_volume(mixer);
if (prev < 0)
return false;
volume += prev;
}
if (volume > 100) if (volume > 100)
volume = 100; volume = 100;
else if (volume < 0) else if (volume < 0)
@ -102,13 +94,13 @@ output_mixer_set_volume(unsigned i, int volume, bool relative)
} }
bool bool
mixer_all_set_volume(int volume, bool relative) mixer_all_set_volume(int volume)
{ {
bool success = false; bool success = false;
unsigned count = audio_output_count(); unsigned count = audio_output_count();
for (unsigned i = 0; i < count; i++) for (unsigned i = 0; i < count; i++)
success = output_mixer_set_volume(i, volume, relative) success = output_mixer_set_volume(i, volume)
|| success; || success;
return success; return success;

View File

@ -37,11 +37,10 @@ mixer_all_get_volume(void);
/** /**
* Sets the volume on all available mixers. * Sets the volume on all available mixers.
* *
* @param volume the volume (range 0..100 or -100..100 if #relative) * @param volume the volume (range 0..100)
* @param relative if true, then the #volume is added to the current value
* @return true on success, false on failure * @return true on success, false on failure
*/ */
bool bool
mixer_all_set_volume(int volume, bool relative); mixer_all_set_volume(int volume);
#endif #endif

View File

@ -117,51 +117,45 @@ int volume_level_get(void)
return -1; return -1;
} }
static bool software_volume_change(int change, bool rel) static bool software_volume_change(int volume)
{ {
int new = change; if (volume > 100)
volume = 100;
else if (volume < 0)
volume = 0;
if (rel) volume_software_set = volume;
new += volume_software_set;
if (new > 100) if (volume >= 100)
new = 100; volume = PCM_VOLUME_1;
else if (new < 0) else if (volume <= 0)
new = 0; volume = 0;
volume_software_set = new;
/*new = 100.0*(exp(new/50.0)-1)/(M_E*M_E-1)+0.5; */
if (new >= 100)
new = PCM_VOLUME_1;
else if (new <= 0)
new = 0;
else else
new = pcm_float_to_volume((exp(new / 25.0) - 1) / volume = pcm_float_to_volume((exp(volume / 25.0) - 1) /
(54.5981500331F - 1)); (54.5981500331F - 1));
setPlayerSoftwareVolume(new); setPlayerSoftwareVolume(volume);
return true; return true;
} }
static bool hardware_volume_change(int change, bool rel) static bool hardware_volume_change(int volume)
{ {
/* reset the cache */ /* reset the cache */
last_hardware_volume = -1; last_hardware_volume = -1;
return mixer_all_set_volume(change, rel); return mixer_all_set_volume(volume);
} }
bool volume_level_change(int change, bool rel) bool volume_level_change(int volume)
{ {
idle_add(IDLE_MIXER); idle_add(IDLE_MIXER);
switch (volume_mixer_type) { switch (volume_mixer_type) {
case MIXER_TYPE_HARDWARE: case MIXER_TYPE_HARDWARE:
return hardware_volume_change(change, rel); return hardware_volume_change(volume);
case MIXER_TYPE_SOFTWARE: case MIXER_TYPE_SOFTWARE:
return software_volume_change(change, rel); return software_volume_change(volume);
default: default:
return true; return true;
} }
@ -182,7 +176,7 @@ void read_sw_volume_state(FILE *fp)
g_strchomp(buf); g_strchomp(buf);
sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10); sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10);
if (G_LIKELY(!*end)) if (G_LIKELY(!*end))
software_volume_change(sv, 0); software_volume_change(sv);
else else
g_warning("Can't parse software volume: %s\n", buf); g_warning("Can't parse software volume: %s\n", buf);
return; return;

View File

@ -29,7 +29,7 @@ void volume_finish(void);
int volume_level_get(void); int volume_level_get(void);
bool volume_level_change(int change, bool rel); bool volume_level_change(int volume);
void read_sw_volume_state(FILE *fp); void read_sw_volume_state(FILE *fp);