diff options
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/protocol-native.c | 4 | ||||
-rw-r--r-- | src/pulsecore/resampler.c | 4 | ||||
-rw-r--r-- | src/pulsecore/sample-util.c | 120 | ||||
-rw-r--r-- | src/pulsecore/sconv-s16be.c | 14 | ||||
-rw-r--r-- | src/pulsecore/sconv-s16be.h | 10 | ||||
-rw-r--r-- | src/pulsecore/sconv-s16le.c | 115 | ||||
-rw-r--r-- | src/pulsecore/sconv-s16le.h | 10 | ||||
-rw-r--r-- | src/pulsecore/sconv.c | 8 |
8 files changed, 281 insertions, 4 deletions
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index b1ef64f2..54122679 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -2642,9 +2642,9 @@ static void fixup_sample_spec(pa_native_connection *c, pa_sample_spec *fixed, co } if (c->version < 15) { - if (fixed->format == PA_SAMPLE_S24LE) + if (fixed->format == PA_SAMPLE_S24LE || fixed->format == PA_SAMPLE_S24_32LE) fixed->format = PA_SAMPLE_FLOAT32LE; - if (fixed->format == PA_SAMPLE_S24BE) + if (fixed->format == PA_SAMPLE_S24BE || fixed->format == PA_SAMPLE_S24_32BE) fixed->format = PA_SAMPLE_FLOAT32BE; } } diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 67c37581..6b3836e1 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -258,9 +258,11 @@ pa_resampler* pa_resampler_new( if (a->format == PA_SAMPLE_S32NE || a->format == PA_SAMPLE_S32RE || a->format == PA_SAMPLE_FLOAT32NE || a->format == PA_SAMPLE_FLOAT32RE || a->format == PA_SAMPLE_S24NE || a->format == PA_SAMPLE_S24RE || + a->format == PA_SAMPLE_S24_32NE || a->format == PA_SAMPLE_S24_32RE || b->format == PA_SAMPLE_S32NE || b->format == PA_SAMPLE_S32RE || b->format == PA_SAMPLE_FLOAT32NE || b->format == PA_SAMPLE_FLOAT32RE || - b->format == PA_SAMPLE_S24NE || b->format == PA_SAMPLE_S24RE) + b->format == PA_SAMPLE_S24NE || b->format == PA_SAMPLE_S24RE || + b->format == PA_SAMPLE_S24_32NE || b->format == PA_SAMPLE_S24_32RE) r->work_format = PA_SAMPLE_FLOAT32NE; else r->work_format = PA_SAMPLE_S16NE; diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c index 533181b8..cf7b4d58 100644 --- a/src/pulsecore/sample-util.c +++ b/src/pulsecore/sample-util.c @@ -85,6 +85,8 @@ static uint8_t silence_byte(pa_sample_format_t format) { case PA_SAMPLE_FLOAT32BE: case PA_SAMPLE_S24LE: case PA_SAMPLE_S24BE: + case PA_SAMPLE_S24_32LE: + case PA_SAMPLE_S24_32BE: return 0; case PA_SAMPLE_ALAW: return 0xd5; @@ -414,6 +416,78 @@ size_t pa_mix( break; } + case PA_SAMPLE_S24_32NE: { + unsigned channel = 0; + + calc_linear_integer_stream_volumes(streams, nstreams, volume, spec); + + while (data < end) { + int64_t sum = 0; + unsigned i; + + for (i = 0; i < nstreams; i++) { + pa_mix_info *m = streams + i; + int32_t cv = m->linear[channel].i; + int64_t v; + + if (PA_UNLIKELY(cv <= 0)) + continue; + + v = (int32_t) (*((uint32_t*)m->ptr) << 8); + v = (v * cv) / 0x10000; + sum += v; + + m->ptr = (uint8_t*) m->ptr + sizeof(int32_t); + } + + sum = PA_CLAMP_UNLIKELY(sum, -0x80000000LL, 0x7FFFFFFFLL); + *((uint32_t*) data) = ((uint32_t) (int32_t) sum) >> 8; + + data = (uint8_t*) data + sizeof(uint32_t); + + if (PA_UNLIKELY(++channel >= spec->channels)) + channel = 0; + } + + break; + } + + case PA_SAMPLE_S24_32RE: { + unsigned channel = 0; + + calc_linear_integer_stream_volumes(streams, nstreams, volume, spec); + + while (data < end) { + int64_t sum = 0; + unsigned i; + + for (i = 0; i < nstreams; i++) { + pa_mix_info *m = streams + i; + int32_t cv = m->linear[channel].i; + int64_t v; + + if (PA_UNLIKELY(cv <= 0)) + continue; + + v = (int32_t) (PA_UINT32_SWAP(*((uint32_t*) m->ptr)) << 8); + v = (v * cv) / 0x10000; + sum += v; + + m->ptr = (uint8_t*) m->ptr + 3; + } + + sum = PA_CLAMP_UNLIKELY(sum, -0x80000000LL, 0x7FFFFFFFLL); + *((uint32_t*) data) = PA_INT32_SWAP(((uint32_t) (int32_t) sum) >> 8); + + data = (uint8_t*) data + sizeof(uint32_t); + + if (PA_UNLIKELY(++channel >= spec->channels)) + channel = 0; + } + + break; + } + case PA_SAMPLE_U8: { unsigned channel = 0; @@ -765,6 +839,52 @@ void pa_volume_memchunk( break; } + case PA_SAMPLE_S24_32NE: { + uint32_t *d, *e; + unsigned channel; + int32_t linear[PA_CHANNELS_MAX]; + + calc_linear_integer_volume(linear, volume); + + e = (uint32_t*) ptr + c->length/sizeof(uint32_t); + + for (channel = 0, d = ptr; d < e; d++) { + int64_t t; + + t = (int64_t) ((int32_t) (*d << 8)); + t = (t * linear[channel]) / 0x10000; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + *d = ((uint32_t) ((int32_t) t)) >> 8; + + if (PA_UNLIKELY(++channel >= spec->channels)) + channel = 0; + } + break; + } + + case PA_SAMPLE_S24_32RE: { + uint32_t *d, *e; + unsigned channel; + int32_t linear[PA_CHANNELS_MAX]; + + calc_linear_integer_volume(linear, volume); + + e = (uint32_t*) ptr + c->length/sizeof(uint32_t); + + for (channel = 0, d = ptr; d < e; d++) { + int64_t t; + + t = (int64_t) ((int32_t) (PA_UINT32_SWAP(*d) << 8)); + t = (t * linear[channel]) / 0x10000; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + *d = PA_UINT32_SWAP(((uint32_t) ((int32_t) t)) >> 8); + + if (PA_UNLIKELY(++channel >= spec->channels)) + channel = 0; + } + break; + } + case PA_SAMPLE_U8: { uint8_t *d, *e; unsigned channel; diff --git a/src/pulsecore/sconv-s16be.c b/src/pulsecore/sconv-s16be.c index d6137d39..0d5146aa 100644 --- a/src/pulsecore/sconv-s16be.c +++ b/src/pulsecore/sconv-s16be.c @@ -27,9 +27,13 @@ #define INT16_FROM PA_INT16_FROM_BE #define INT16_TO PA_INT16_TO_BE +#define UINT16_FROM PA_UINT16_FROM_BE +#define UINT16_TO PA_UINT16_TO_BE #define INT32_FROM PA_INT32_FROM_BE #define INT32_TO PA_INT32_TO_BE +#define UINT32_FROM PA_UINT32_FROM_BE +#define UINT32_TO PA_UINT32_TO_BE #define READ24 PA_READ24BE #define WRITE24 PA_WRITE24BE @@ -49,6 +53,11 @@ #define pa_sconv_s24le_to_float32re pa_sconv_s24be_to_float32re #define pa_sconv_s24le_from_float32re pa_sconv_s24be_from_float32re +#define pa_sconv_s24_32le_to_float32ne pa_sconv_s24_32be_to_float32ne +#define pa_sconv_s24_32le_from_float32ne pa_sconv_s24_32be_from_float32ne +#define pa_sconv_s24_32le_to_float32re pa_sconv_s24_32be_to_float32re +#define pa_sconv_s24_32le_from_float32re pa_sconv_s24_32be_from_float32re + #define pa_sconv_s32le_to_s16ne pa_sconv_s32be_to_s16ne #define pa_sconv_s32le_from_s16ne pa_sconv_s32be_from_s16ne #define pa_sconv_s32le_to_s16re pa_sconv_s32be_to_s16re @@ -59,6 +68,11 @@ #define pa_sconv_s24le_to_s16re pa_sconv_s24be_to_s16re #define pa_sconv_s24le_from_s16re pa_sconv_s24be_from_s16re +#define pa_sconv_s24_32le_to_s16ne pa_sconv_s24_32be_to_s16ne +#define pa_sconv_s24_32le_from_s16ne pa_sconv_s24_32be_from_s16ne +#define pa_sconv_s24_32le_to_s16re pa_sconv_s24_32be_to_s16re +#define pa_sconv_s24_32le_from_s16re pa_sconv_s24_32be_from_s16re + #ifdef WORDS_BIGENDIAN #define SWAP_WORDS 0 #else diff --git a/src/pulsecore/sconv-s16be.h b/src/pulsecore/sconv-s16be.h index 1b88fd45..02633333 100644 --- a/src/pulsecore/sconv-s16be.h +++ b/src/pulsecore/sconv-s16be.h @@ -39,6 +39,11 @@ void pa_sconv_s24be_from_float32ne(unsigned n, const float *a, uint8_t *b); void pa_sconv_s24be_to_float32re(unsigned n, const uint8_t *a, float *b); void pa_sconv_s24be_from_float32re(unsigned n, const float *a, uint8_t *b); +void pa_sconv_s24_32be_to_float32ne(unsigned n, const uint8_t *a, float *b); +void pa_sconv_s24_32be_from_float32ne(unsigned n, const float *a, uint8_t *b); +void pa_sconv_s24_32be_to_float32re(unsigned n, const uint8_t *a, float *b); +void pa_sconv_s24_32be_from_float32re(unsigned n, const float *a, uint8_t *b); + void pa_sconv_s32be_to_s16ne(unsigned n, const int32_t *a, int16_t *b); void pa_sconv_s32be_from_s16ne(unsigned n, const int16_t *a, int32_t *b); void pa_sconv_s32be_to_s16re(unsigned n, const int32_t *a, int16_t *b); @@ -49,6 +54,11 @@ void pa_sconv_s24be_from_s16ne(unsigned n, const int16_t *a, uint8_t *b); void pa_sconv_s24be_to_s16re(unsigned n, const uint8_t *a, int16_t *b); void pa_sconv_s24be_from_s16re(unsigned n, const int16_t *a, uint8_t *b); +void pa_sconv_s24_32be_to_s16ne(unsigned n, const uint8_t *a, int16_t *b); +void pa_sconv_s24_32be_from_s16ne(unsigned n, const int16_t *a, uint8_t *b); +void pa_sconv_s24_32be_to_s16re(unsigned n, const uint8_t *a, int16_t *b); +void pa_sconv_s24_32be_from_s16re(unsigned n, const int16_t *a, uint8_t *b); + #ifdef WORDS_BIGENDIAN #define pa_sconv_float32be_to_s16ne pa_sconv_s16be_from_float32ne #define pa_sconv_float32be_from_s16ne pa_sconv_s16be_to_float32ne diff --git a/src/pulsecore/sconv-s16le.c b/src/pulsecore/sconv-s16le.c index 37ebc983..79f0391c 100644 --- a/src/pulsecore/sconv-s16le.c +++ b/src/pulsecore/sconv-s16le.c @@ -41,23 +41,34 @@ #ifndef INT16_FROM #define INT16_FROM PA_INT16_FROM_LE #endif +#ifndef UINT16_FROM +#define UINT16_FROM PA_UINT16_FROM_LE +#endif #ifndef INT16_TO #define INT16_TO PA_INT16_TO_LE #endif +#ifndef UINT16_TO +#define UINT16_TO PA_UINT16_TO_LE +#endif #ifndef INT32_FROM #define INT32_FROM PA_INT32_FROM_LE #endif +#ifndef UINT32_FROM +#define UINT32_FROM PA_UINT32_FROM_LE +#endif #ifndef INT32_TO #define INT32_TO PA_INT32_TO_LE #endif +#ifndef UINT32_TO +#define UINT32_TO PA_UINT32_TO_LE +#endif #ifndef READ24 #define READ24 PA_READ24LE #endif - #ifndef WRITE24 #define WRITE24 PA_WRITE24LE #endif @@ -353,3 +364,105 @@ void pa_sconv_s24le_from_float32re(unsigned n, const float *a, uint8_t *b) { b+=3; } } + +void pa_sconv_s24_32le_to_s16ne(unsigned n, const uint32_t *a, int16_t *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + *b = (int16_t) ((int32_t) (UINT32_FROM(*a) << 8) >> 16); + a++; + b++; + } +} + +void pa_sconv_s24_32le_to_s16re(unsigned n, const uint32_t *a, int16_t *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + int16_t s = (int16_t) ((int32_t) (UINT32_FROM(*a) << 8) >> 16); + *b = PA_INT16_SWAP(s); + a++; + b++; + } +} + +void pa_sconv_s24_32le_from_s16ne(unsigned n, const int16_t *a, uint32_t *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + *b = UINT32_TO(((uint32_t) ((int32_t) *a << 16)) >> 8); + a++; + b++; + } +} + +void pa_sconv_s24_32le_from_s16re(unsigned n, const int16_t *a, uint32_t *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + uint32_t s = ((uint32_t) ((int32_t) PA_INT16_SWAP(*a) << 16)) >> 8; + *b = UINT32_TO(s); + a++; + b++; + } +} + +void pa_sconv_s24_32le_to_float32ne(unsigned n, const uint32_t *a, float *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + int32_t s = (int16_t) ((int32_t) (UINT32_FROM(*a) << 8)); + *b = ((float) s) / 0x7FFFFFFF; + a ++; + b ++; + } +} + +void pa_sconv_s24_32le_to_float32re(unsigned n, const uint32_t *a, float *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + int32_t s = (int16_t) ((int32_t) (UINT32_FROM(*a) << 8)); + float k = ((float) s) / 0x7FFFFFFF; + *b = PA_FLOAT32_SWAP(k); + a ++; + b ++; + } +} + +void pa_sconv_s24_32le_from_float32ne(unsigned n, const float *a, uint32_t *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + int32_t s; + float v = *a; + v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.0f); + s = (int32_t) lrint((double) v * (double) 0x7FFFFFFF); + *b = UINT32_TO(((uint32_t) s) >> 8); + a++; + b++; + } +} + +void pa_sconv_s24_32le_from_float32re(unsigned n, const float *a, uint32_t *b) { + pa_assert(a); + pa_assert(b); + + for (; n > 0; n--) { + int32_t s; + float v = *a; + v = PA_FLOAT32_SWAP(v); + v = PA_CLAMP_UNLIKELY(v, -1.0f, 1.0f); + s = (int32_t) lrint((double) v * (double) 0x7FFFFFFF); + *b = UINT32_TO(((uint32_t) s) >> 8); + a++; + b++; + } +} diff --git a/src/pulsecore/sconv-s16le.h b/src/pulsecore/sconv-s16le.h index b853515c..f7b00645 100644 --- a/src/pulsecore/sconv-s16le.h +++ b/src/pulsecore/sconv-s16le.h @@ -39,6 +39,11 @@ void pa_sconv_s24le_from_float32ne(unsigned n, const float *a, uint8_t *b); void pa_sconv_s24le_to_float32re(unsigned n, const uint8_t *a, float *b); void pa_sconv_s24le_from_float32re(unsigned n, const float *a, uint8_t *b); +void pa_sconv_s24_32le_to_float32ne(unsigned n, const uint32_t *a, float *b); +void pa_sconv_s24_32le_from_float32ne(unsigned n, const float *a, uint32_t *b); +void pa_sconv_s24_32le_to_float32re(unsigned n, const uint32_t *a, float *b); +void pa_sconv_s24_32le_from_float32re(unsigned n, const float *a, uint32_t *b); + void pa_sconv_s32le_to_s16ne(unsigned n, const int32_t *a, int16_t *b); void pa_sconv_s32le_from_s16ne(unsigned n, const int16_t *a, int32_t *b); void pa_sconv_s32le_to_s16re(unsigned n, const int32_t *a, int16_t *b); @@ -49,6 +54,11 @@ void pa_sconv_s24le_from_s16ne(unsigned n, const int16_t *a, uint8_t *b); void pa_sconv_s24le_to_s16re(unsigned n, const uint8_t *a, int16_t *b); void pa_sconv_s24le_from_s16re(unsigned n, const int16_t *a, uint8_t *b); +void pa_sconv_s24_32le_to_s16ne(unsigned n, const uint32_t *a, int16_t *b); +void pa_sconv_s24_32le_from_s16ne(unsigned n, const int16_t *a, uint32_t *b); +void pa_sconv_s24_32le_to_s16re(unsigned n, const uint32_t *a, int16_t *b); +void pa_sconv_s24_32le_from_s16re(unsigned n, const int16_t *a, uint32_t *b); + #ifndef WORDS_BIGENDIAN #define pa_sconv_float32be_to_s16ne pa_sconv_s16le_from_float32re #define pa_sconv_float32be_from_s16ne pa_sconv_s16le_to_float32re diff --git a/src/pulsecore/sconv.c b/src/pulsecore/sconv.c index 13700c12..fcd0309c 100644 --- a/src/pulsecore/sconv.c +++ b/src/pulsecore/sconv.c @@ -200,6 +200,8 @@ pa_convert_func_t pa_get_convert_to_float32ne_function(pa_sample_format_t f) { [PA_SAMPLE_S32BE] = (pa_convert_func_t) pa_sconv_s32be_to_float32ne, [PA_SAMPLE_S24LE] = (pa_convert_func_t) pa_sconv_s24le_to_float32ne, [PA_SAMPLE_S24BE] = (pa_convert_func_t) pa_sconv_s24be_to_float32ne, + [PA_SAMPLE_S24_32LE] = (pa_convert_func_t) pa_sconv_s24_32le_to_float32ne, + [PA_SAMPLE_S24_32BE] = (pa_convert_func_t) pa_sconv_s24_32be_to_float32ne, [PA_SAMPLE_FLOAT32NE] = (pa_convert_func_t) float32ne_to_float32ne, [PA_SAMPLE_FLOAT32RE] = (pa_convert_func_t) float32re_to_float32ne, }; @@ -220,6 +222,8 @@ pa_convert_func_t pa_get_convert_from_float32ne_function(pa_sample_format_t f) { [PA_SAMPLE_S32BE] = (pa_convert_func_t) pa_sconv_s32be_from_float32ne, [PA_SAMPLE_S24LE] = (pa_convert_func_t) pa_sconv_s24le_from_float32ne, [PA_SAMPLE_S24BE] = (pa_convert_func_t) pa_sconv_s24be_from_float32ne, + [PA_SAMPLE_S24_32LE] = (pa_convert_func_t) pa_sconv_s24_32le_from_float32ne, + [PA_SAMPLE_S24_32BE] = (pa_convert_func_t) pa_sconv_s24_32be_from_float32ne, [PA_SAMPLE_FLOAT32NE] = (pa_convert_func_t) float32ne_to_float32ne, [PA_SAMPLE_FLOAT32RE] = (pa_convert_func_t) float32re_to_float32ne, [PA_SAMPLE_ALAW] = (pa_convert_func_t) alaw_from_float32ne, @@ -244,6 +248,8 @@ pa_convert_func_t pa_get_convert_to_s16ne_function(pa_sample_format_t f) { [PA_SAMPLE_S32LE] = (pa_convert_func_t) pa_sconv_s32le_to_s16ne, [PA_SAMPLE_S24BE] = (pa_convert_func_t) pa_sconv_s24be_to_s16ne, [PA_SAMPLE_S24LE] = (pa_convert_func_t) pa_sconv_s24le_to_s16ne, + [PA_SAMPLE_S24_32BE] = (pa_convert_func_t) pa_sconv_s24_32be_to_s16ne, + [PA_SAMPLE_S24_32LE] = (pa_convert_func_t) pa_sconv_s24_32le_to_s16ne, [PA_SAMPLE_ALAW] = (pa_convert_func_t) alaw_to_s16ne, [PA_SAMPLE_ULAW] = (pa_convert_func_t) ulaw_to_s16ne }; @@ -266,6 +272,8 @@ pa_convert_func_t pa_get_convert_from_s16ne_function(pa_sample_format_t f) { [PA_SAMPLE_S32LE] = (pa_convert_func_t) pa_sconv_s32le_from_s16ne, [PA_SAMPLE_S24BE] = (pa_convert_func_t) pa_sconv_s24be_from_s16ne, [PA_SAMPLE_S24LE] = (pa_convert_func_t) pa_sconv_s24le_from_s16ne, + [PA_SAMPLE_S24_32BE] = (pa_convert_func_t) pa_sconv_s24_32be_from_s16ne, + [PA_SAMPLE_S24_32LE] = (pa_convert_func_t) pa_sconv_s24_32le_from_s16ne, [PA_SAMPLE_ALAW] = (pa_convert_func_t) alaw_from_s16ne, [PA_SAMPLE_ULAW] = (pa_convert_func_t) ulaw_from_s16ne, }; |