#include <config.h>
#endif
-
#include <pulsecore/macro.h>
#include <pulsecore/g711.h>
-#include <pulsecore/core-util.h>
+#include <pulsecore/endianmacros.h>
#include "sample-util.h"
-#include "endianmacros.h"
-static void
-pa_volume_u8_c (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_u8_c(uint8_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
for (channel = 0; length; length--) {
- int32_t t, hi, lo;
-
- hi = volumes[channel] >> 16;
- lo = volumes[channel] & 0xFFFF;
+ int32_t t = pa_mult_s16_volume(*samples - 0x80, volumes[channel]);
- t = (int32_t) *samples - 0x80;
- t = ((t * lo) >> 16) + (t * hi);
t = PA_CLAMP_UNLIKELY(t, -0x80, 0x7F);
*samples++ = (uint8_t) (t + 0x80);
}
}
-static void
-pa_volume_alaw_c (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_alaw_c(uint8_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
for (channel = 0; length; length--) {
- int32_t t, hi, lo;
+ int32_t t = pa_mult_s16_volume(st_alaw2linear16(*samples), volumes[channel]);
- hi = volumes[channel] >> 16;
- lo = volumes[channel] & 0xFFFF;
-
- t = (int32_t) st_alaw2linear16(*samples);
- t = ((t * lo) >> 16) + (t * hi);
t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
*samples++ = (uint8_t) st_13linear2alaw((int16_t) t >> 3);
}
}
-static void
-pa_volume_ulaw_c (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_ulaw_c(uint8_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
for (channel = 0; length; length--) {
- int32_t t, hi, lo;
-
- hi = volumes[channel] >> 16;
- lo = volumes[channel] & 0xFFFF;
+ int32_t t = pa_mult_s16_volume(st_ulaw2linear16(*samples), volumes[channel]);
- t = (int32_t) st_ulaw2linear16(*samples);
- t = ((t * lo) >> 16) + (t * hi);
t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
*samples++ = (uint8_t) st_14linear2ulaw((int16_t) t >> 2);
}
}
-static void
-pa_volume_s16ne_c (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s16ne_c(int16_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (int16_t);
+ length /= sizeof(int16_t);
for (channel = 0; length; length--) {
- int32_t t, hi, lo;
+ int32_t t = pa_mult_s16_volume(*samples, volumes[channel]);
- /* Multiplying the 32bit volume factor with the 16bit
- * sample might result in an 48bit value. We want to
- * do without 64 bit integers and hence do the
- * multiplication independantly for the HI and LO part
- * of the volume. */
-
- hi = volumes[channel] >> 16;
- lo = volumes[channel] & 0xFFFF;
-
- t = (int32_t)(*samples);
- t = ((t * lo) >> 16) + (t * hi);
t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
*samples++ = (int16_t) t;
}
}
-static void
-pa_volume_s16re_c (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s16re_c(int16_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (int16_t);
+ length /= sizeof(int16_t);
for (channel = 0; length; length--) {
- int32_t t, hi, lo;
-
- hi = volumes[channel] >> 16;
- lo = volumes[channel] & 0xFFFF;
+ int32_t t = pa_mult_s16_volume(PA_INT16_SWAP(*samples), volumes[channel]);
- t = (int32_t) PA_INT16_SWAP(*samples);
- t = ((t * lo) >> 16) + (t * hi);
t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
*samples++ = PA_INT16_SWAP((int16_t) t);
}
}
-static void
-pa_volume_float32ne_c (float *samples, float *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_float32ne_c(float *samples, const float *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (float);
+ length /= sizeof(float);
for (channel = 0; length; length--) {
*samples++ *= volumes[channel];
}
}
-static void
-pa_volume_float32re_c (float *samples, float *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_float32re_c(float *samples, float *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (float);
+ length /= sizeof(float);
for (channel = 0; length; length--) {
float t;
}
}
-static void
-pa_volume_s32ne_c (int32_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s32ne_c(int32_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (int32_t);
+ length /= sizeof(int32_t);
for (channel = 0; length; length--) {
int64_t t;
}
}
-static void
-pa_volume_s32re_c (int32_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s32re_c(int32_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (int32_t);
+ length /= sizeof(int32_t);
for (channel = 0; length; length--) {
int64_t t;
}
}
-static void
-pa_volume_s24ne_c (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s24ne_c(uint8_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
uint8_t *e;
}
}
-static void
-pa_volume_s24re_c (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s24re_c(uint8_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
uint8_t *e;
}
}
-static void
-pa_volume_s24_32ne_c (uint32_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s24_32ne_c(uint32_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (uint32_t);
+ length /= sizeof(uint32_t);
for (channel = 0; length; length--) {
int64_t t;
}
}
-static void
-pa_volume_s24_32re_c (uint32_t *samples, int32_t *volumes, unsigned channels, unsigned length)
-{
+static void pa_volume_s24_32re_c(uint32_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
unsigned channel;
- length /= sizeof (uint32_t);
+ length /= sizeof(uint32_t);
for (channel = 0; length; length--) {
int64_t t;
}
}
-static pa_do_volume_func_t do_volume_table[] =
-{
+static pa_do_volume_func_t do_volume_table[] = {
[PA_SAMPLE_U8] = (pa_do_volume_func_t) pa_volume_u8_c,
[PA_SAMPLE_ALAW] = (pa_do_volume_func_t) pa_volume_alaw_c,
[PA_SAMPLE_ULAW] = (pa_do_volume_func_t) pa_volume_ulaw_c,