implement pa_cvolume_scale()

This commit is contained in:
Lennart Poettering 2009-01-27 00:47:07 +01:00
parent e52c5ea68a
commit 4e31e00b63
3 changed files with 26 additions and 1 deletions

View file

@ -113,6 +113,7 @@ pa_cvolume_get_balance;
pa_cvolume_init; pa_cvolume_init;
pa_cvolume_max; pa_cvolume_max;
pa_cvolume_remap; pa_cvolume_remap;
pa_cvolume_scale;
pa_cvolume_set; pa_cvolume_set;
pa_cvolume_set_balance; pa_cvolume_set_balance;
pa_cvolume_snprint; pa_cvolume_snprint;

View file

@ -500,3 +500,22 @@ pa_cvolume* pa_cvolume_set_balance(const pa_channel_map *map, pa_cvolume *v, flo
return v; return v;
} }
pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) {
unsigned c;
pa_volume_t t = 0;
pa_assert(c);
for (c = 0; c < v->channels; c++)
if (v->values[c] > t)
t = v->values[c];
if (t <= 0)
return pa_cvolume_set(v, v->channels, max);
for (c = 0; c < v->channels; c++)
v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) max) / (uint64_t) t);
return v;
}

View file

@ -244,9 +244,14 @@ float pa_cvolume_get_balance(const pa_channel_map *map, const pa_cvolume *v) PA_
* operation might not be reversable! Also, after this call * operation might not be reversable! Also, after this call
* pa_cvolume_get_balance() is not guaranteed to actually return the * pa_cvolume_get_balance() is not guaranteed to actually return the
* requested balance (e.g. when the input volume was zero anyway for * requested balance (e.g. when the input volume was zero anyway for
* all channels)- \since 0.9.15 */ * all channels) \since 0.9.15 */
pa_cvolume* pa_cvolume_set_balance(const pa_channel_map *map, pa_cvolume *v, float new_balance); pa_cvolume* pa_cvolume_set_balance(const pa_channel_map *map, pa_cvolume *v, float new_balance);
/** Scale the passed pa_cvolume structure so that the maximum volume
* of all channels equals max. The proportions between the channel
* volumes are kept. \since 0.9.15 */
pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max);
PA_C_DECL_END PA_C_DECL_END
#endif #endif