#include <stdio.h>
#include <string.h>
+#include <math.h>
#include <pulse/i18n.h>
a->channels = (uint8_t) channels;
for (i = 0; i < a->channels; i++)
- a->values[i] = v;
+ /* Clamp in case there is stale data that exceeds the current
+ * PA_VOLUME_MAX */
+ a->values[i] = PA_CLAMP_VOLUME(v);
return a;
}
/* cbrt((a/PA_VOLUME_NORM)^3*(b/PA_VOLUME_NORM)^3)*PA_VOLUME_NORM = a*b/PA_VOLUME_NORM */
- return (pa_volume_t) (((uint64_t) a * (uint64_t) b + (uint64_t) PA_VOLUME_NORM / 2ULL) / (uint64_t) PA_VOLUME_NORM);
+ return (pa_volume_t) PA_CLAMP_VOLUME((((uint64_t) a * (uint64_t) b + (uint64_t) PA_VOLUME_NORM / 2ULL) / (uint64_t) PA_VOLUME_NORM));
}
pa_volume_t pa_sw_volume_divide(pa_volume_t a, pa_volume_t b) {
* same volume value! That's why we need the lround() below!
*/
- return (pa_volume_t) lround(cbrt(v) * PA_VOLUME_NORM);
+ return (pa_volume_t) PA_CLAMP_VOLUME((uint64_t) lround(cbrt(v) * PA_VOLUME_NORM));
}
double pa_sw_volume_to_linear(pa_volume_t v) {
}
f = pa_sw_volume_to_dB(v);
- pa_snprintf(s, l, "%0.2f dB",
- isinf(f) < 0 || f <= PA_DECIBEL_MININFTY ? -INFINITY : f);
+ pa_snprintf(s, l, "%0.2f dB", isinf(f) < 0 || f <= PA_DECIBEL_MININFTY ? -INFINITY : f);
return s;
}
m = PA_MAX(left, right);
if (new_balance <= 0) {
- nright = (new_balance + 1.0f) * m;
+ nright = (new_balance + 1.0f) * m;
nleft = m;
- } else {
+ } else {
nleft = (1.0f - new_balance) * m;
nright = m;
}
if (left == 0)
v->values[c] = nleft;
else
- v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nleft) / (uint64_t) left);
+ v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) nleft) / (uint64_t) left);
} else if (on_right(map->map[c])) {
if (right == 0)
v->values[c] = nright;
else
- v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nright) / (uint64_t) right);
+ v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) nright) / (uint64_t) right);
}
}
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);
+ v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) max) / (uint64_t) t);
return v;
}
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);
+ v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) max) / (uint64_t) t);
return v;
}
m = PA_MAX(front, rear);
if (new_fade <= 0) {
- nfront = (new_fade + 1.0f) * m;
+ nfront = (new_fade + 1.0f) * m;
nrear = m;
- } else {
+ } else {
nrear = (1.0f - new_fade) * m;
nfront = m;
}
if (front == 0)
v->values[c] = nfront;
else
- v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nfront) / (uint64_t) front);
+ v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) nfront) / (uint64_t) front);
} else if (on_rear(map->map[c])) {
if (rear == 0)
v->values[c] = nrear;
else
- v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nrear) / (uint64_t) rear);
+ v->values[c] = (pa_volume_t) PA_CLAMP_VOLUME(((uint64_t) v->values[c] * (uint64_t) nrear) / (uint64_t) rear);
}
}