static int audio_output_volume_adjust ( int  n  )  [static]

Adjust the audio output by a certain percentage and return the new value.

Definition at line 214 of file audio_output_alsa.c.

00215 {
00216         int delta;
00217         long min, max;
00218         long right, left;
00219 
00220         if (mixhnd == NULL)
00221                 return (-1);
00222 
00223         /* Allow other applications to change mixer */
00224         snd_mixer_handle_events(mixhnd);
00225 
00226         /* Obtain volume range boundaries */
00227         if (snd_mixer_selem_get_playback_volume_range(elem, &min, &max) != 0)
00228                 return (-1);
00229         if (min >= max)
00230                 return (-1);
00231 
00232         /* Convert delta from percent to steps */
00233         delta = (n * (max - min)) / 100;
00234         if (delta == 0)
00235                 delta = n > 0 ? 1 : -1;
00236 
00237         /* Obtain current volume */
00238         if (snd_mixer_selem_get_playback_volume(elem,
00239             SND_MIXER_SCHN_FRONT_LEFT, &left) != 0)
00240                 return (-1);
00241         if (snd_mixer_selem_get_playback_volume(elem,
00242             SND_MIXER_SCHN_FRONT_RIGHT, &right) != 0)
00243                 return (-1);
00244 
00245         left = left + delta;
00246         left = CLAMP(left, min, max);
00247         right = right + delta;
00248         right = CLAMP(right, min, max);
00249 
00250         /* Set new volume */
00251         if (snd_mixer_selem_set_playback_volume(elem,
00252             SND_MIXER_SCHN_FRONT_LEFT, left) != 0)
00253                 return (-1);
00254         if (snd_mixer_selem_set_playback_volume(elem,
00255             SND_MIXER_SCHN_FRONT_RIGHT, right) != 0)
00256                 return (-1);
00257 
00258         /* Convert volume back to a percentage */
00259         return (((left + right) / 2 - min) * 100) / (max - min);
00260 }

Here is the caller graph for this function:

 All Data Structures Files Functions Variables Defines
Generated on Mon Mar 15 04:45:05 2010 for herrie by  doxygen 1.6.3