]> code.delx.au - pulseaudio/commitdiff
implement pa_cvolume_scale()
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Jan 2009 23:47:07 +0000 (00:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Jan 2009 23:47:07 +0000 (00:47 +0100)
src/map-file
src/pulse/volume.c
src/pulse/volume.h

index cb5c749dce6ec7755fda5d24ca7b51239852abf9..d6137590f659466b1914b8dfb625c528a16bad25 100644 (file)
@@ -113,6 +113,7 @@ pa_cvolume_get_balance;
 pa_cvolume_init;
 pa_cvolume_max;
 pa_cvolume_remap;
+pa_cvolume_scale;
 pa_cvolume_set;
 pa_cvolume_set_balance;
 pa_cvolume_snprint;
index 10a44dafadde871812937e300806f0e4ed1a87fa..2c97784585073bd67cedf03626cf5999b9c88a62 100644 (file)
@@ -500,3 +500,22 @@ pa_cvolume* pa_cvolume_set_balance(const pa_channel_map *map, pa_cvolume *v, flo
 
     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;
+}
index 38da5dfca3956615bcef4236808e30002b475433..c8b73f4a805c59bd60cd1b57a4e6fa7087b028d5 100644 (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
  * pa_cvolume_get_balance() is not guaranteed to actually return the
  * 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);
 
+/** 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
 
 #endif