Commit 8c5ebdff authored by Max Kellermann's avatar Max Kellermann

audio_format: remove the reverse_endian attribute

Eliminate support for reverse endian samples from the MPD core. This moves a lot of complexity to the plugins that really need it (only ALSA and CDIO currently).
parent 1c84f324
...@@ -22,12 +22,6 @@ ...@@ -22,12 +22,6 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define REVERSE_ENDIAN_SUFFIX "_le"
#else
#define REVERSE_ENDIAN_SUFFIX "_be"
#endif
void void
audio_format_mask_apply(struct audio_format *af, audio_format_mask_apply(struct audio_format *af,
const struct audio_format *mask) const struct audio_format *mask)
...@@ -100,9 +94,8 @@ audio_format_to_string(const struct audio_format *af, ...@@ -100,9 +94,8 @@ audio_format_to_string(const struct audio_format *af,
assert(af != NULL); assert(af != NULL);
assert(s != NULL); assert(s != NULL);
snprintf(s->buffer, sizeof(s->buffer), "%u:%s%s:%u", snprintf(s->buffer, sizeof(s->buffer), "%u:%s:%u",
af->sample_rate, sample_format_to_string(af->format), af->sample_rate, sample_format_to_string(af->format),
af->reverse_endian ? REVERSE_ENDIAN_SUFFIX : "",
af->channels); af->channels);
return s->buffer; return s->buffer;
......
...@@ -88,13 +88,6 @@ struct audio_format { ...@@ -88,13 +88,6 @@ struct audio_format {
* fully supported currently. * fully supported currently.
*/ */
uint8_t channels; uint8_t channels;
/**
* If zero, then samples are stored in host byte order. If
* nonzero, then samples are stored in the reverse host byte
* order.
*/
bool reverse_endian;
}; };
/** /**
...@@ -113,7 +106,6 @@ static inline void audio_format_clear(struct audio_format *af) ...@@ -113,7 +106,6 @@ static inline void audio_format_clear(struct audio_format *af)
af->sample_rate = 0; af->sample_rate = 0;
af->format = SAMPLE_FORMAT_UNDEFINED; af->format = SAMPLE_FORMAT_UNDEFINED;
af->channels = 0; af->channels = 0;
af->reverse_endian = false;
} }
/** /**
...@@ -127,7 +119,6 @@ static inline void audio_format_init(struct audio_format *af, ...@@ -127,7 +119,6 @@ static inline void audio_format_init(struct audio_format *af,
af->sample_rate = sample_rate; af->sample_rate = sample_rate;
af->format = (uint8_t)format; af->format = (uint8_t)format;
af->channels = channels; af->channels = channels;
af->reverse_endian = false;
} }
/** /**
...@@ -239,8 +230,7 @@ static inline bool audio_format_equals(const struct audio_format *a, ...@@ -239,8 +230,7 @@ static inline bool audio_format_equals(const struct audio_format *a,
{ {
return a->sample_rate == b->sample_rate && return a->sample_rate == b->sample_rate &&
a->format == b->format && a->format == b->format &&
a->channels == b->channels && a->channels == b->channels;
a->reverse_endian == b->reverse_endian;
} }
void void
......
...@@ -56,9 +56,6 @@ decoder_initialized(struct decoder *decoder, ...@@ -56,9 +56,6 @@ decoder_initialized(struct decoder *decoder,
dc->in_audio_format = *audio_format; dc->in_audio_format = *audio_format;
getOutputAudioFormat(audio_format, &dc->out_audio_format); getOutputAudioFormat(audio_format, &dc->out_audio_format);
/* force host byte order, even if the decoder supplies reverse
endian */
dc->out_audio_format.reverse_endian = false;
dc->seekable = seekable; dc->seekable = seekable;
dc->total_time = total_time; dc->total_time = total_time;
......
...@@ -141,7 +141,6 @@ convert_filter_set(struct filter *_filter, ...@@ -141,7 +141,6 @@ convert_filter_set(struct filter *_filter,
assert(audio_format_valid(&filter->out_audio_format)); assert(audio_format_valid(&filter->out_audio_format));
assert(out_audio_format != NULL); assert(out_audio_format != NULL);
assert(audio_format_valid(out_audio_format)); assert(audio_format_valid(out_audio_format));
assert(!filter->in_audio_format.reverse_endian);
filter->out_audio_format = *out_audio_format; filter->out_audio_format = *out_audio_format;
} }
...@@ -67,7 +67,6 @@ normalize_filter_open(struct filter *_filter, ...@@ -67,7 +67,6 @@ normalize_filter_open(struct filter *_filter,
struct normalize_filter *filter = (struct normalize_filter *)_filter; struct normalize_filter *filter = (struct normalize_filter *)_filter;
audio_format->format = SAMPLE_FORMAT_S16; audio_format->format = SAMPLE_FORMAT_S16;
audio_format->reverse_endian = false;
filter->compressor = Compressor_new(0); filter->compressor = Compressor_new(0);
......
...@@ -140,8 +140,6 @@ replay_gain_filter_open(struct filter *_filter, ...@@ -140,8 +140,6 @@ replay_gain_filter_open(struct filter *_filter,
struct replay_gain_filter *filter = struct replay_gain_filter *filter =
(struct replay_gain_filter *)_filter; (struct replay_gain_filter *)_filter;
audio_format->reverse_endian = false;
filter->audio_format = *audio_format; filter->audio_format = *audio_format;
pcm_buffer_init(&filter->buffer); pcm_buffer_init(&filter->buffer);
......
...@@ -74,8 +74,6 @@ volume_filter_open(struct filter *_filter, struct audio_format *audio_format, ...@@ -74,8 +74,6 @@ volume_filter_open(struct filter *_filter, struct audio_format *audio_format,
{ {
struct volume_filter *filter = (struct volume_filter *)_filter; struct volume_filter *filter = (struct volume_filter *)_filter;
audio_format->reverse_endian = false;
filter->audio_format = *audio_format; filter->audio_format = *audio_format;
pcm_buffer_init(&filter->buffer); pcm_buffer_init(&filter->buffer);
......
...@@ -314,10 +314,8 @@ alsa_output_try_reverse(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams, ...@@ -314,10 +314,8 @@ alsa_output_try_reverse(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
return -EINVAL; return -EINVAL;
int err = snd_pcm_hw_params_set_format(pcm, hwparams, alsa_format); int err = snd_pcm_hw_params_set_format(pcm, hwparams, alsa_format);
if (err == 0) { if (err == 0)
audio_format->format = sample_format; audio_format->format = sample_format;
audio_format->reverse_endian = true;
}
return err; return err;
} }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "pcm_convert.h" #include "pcm_convert.h"
#include "pcm_channels.h" #include "pcm_channels.h"
#include "pcm_format.h" #include "pcm_format.h"
#include "pcm_byteswap.h"
#include "pcm_pack.h" #include "pcm_pack.h"
#include "audio_format.h" #include "audio_format.h"
#include "glib_compat.h" #include "glib_compat.h"
...@@ -45,7 +44,6 @@ void pcm_convert_init(struct pcm_convert_state *state) ...@@ -45,7 +44,6 @@ void pcm_convert_init(struct pcm_convert_state *state)
pcm_buffer_init(&state->format_buffer); pcm_buffer_init(&state->format_buffer);
pcm_buffer_init(&state->pack_buffer); pcm_buffer_init(&state->pack_buffer);
pcm_buffer_init(&state->channels_buffer); pcm_buffer_init(&state->channels_buffer);
pcm_buffer_init(&state->byteswap_buffer);
} }
void pcm_convert_deinit(struct pcm_convert_state *state) void pcm_convert_deinit(struct pcm_convert_state *state)
...@@ -56,7 +54,6 @@ void pcm_convert_deinit(struct pcm_convert_state *state) ...@@ -56,7 +54,6 @@ void pcm_convert_deinit(struct pcm_convert_state *state)
pcm_buffer_deinit(&state->format_buffer); pcm_buffer_deinit(&state->format_buffer);
pcm_buffer_deinit(&state->pack_buffer); pcm_buffer_deinit(&state->pack_buffer);
pcm_buffer_deinit(&state->channels_buffer); pcm_buffer_deinit(&state->channels_buffer);
pcm_buffer_deinit(&state->byteswap_buffer);
} }
void void
...@@ -164,11 +161,6 @@ pcm_convert_16(struct pcm_convert_state *state, ...@@ -164,11 +161,6 @@ pcm_convert_16(struct pcm_convert_state *state,
return NULL; return NULL;
} }
if (dest_format->reverse_endian) {
buf = pcm_byteswap_16(&state->byteswap_buffer, buf, len);
assert(buf != NULL);
}
*dest_size_r = len; *dest_size_r = len;
return buf; return buf;
} }
...@@ -219,11 +211,6 @@ pcm_convert_24(struct pcm_convert_state *state, ...@@ -219,11 +211,6 @@ pcm_convert_24(struct pcm_convert_state *state,
return NULL; return NULL;
} }
if (dest_format->reverse_endian) {
buf = pcm_byteswap_32(&state->byteswap_buffer, buf, len);
assert(buf != NULL);
}
*dest_size_r = len; *dest_size_r = len;
return buf; return buf;
} }
...@@ -261,8 +248,7 @@ pcm_convert_24_packed(struct pcm_convert_state *state, ...@@ -261,8 +248,7 @@ pcm_convert_24_packed(struct pcm_convert_state *state,
size_t dest_size = num_samples * 3; size_t dest_size = num_samples * 3;
uint8_t *dest = pcm_buffer_get(&state->pack_buffer, dest_size); uint8_t *dest = pcm_buffer_get(&state->pack_buffer, dest_size);
pcm_pack_24(dest, buffer, buffer + num_samples, pcm_pack_24(dest, buffer, buffer + num_samples);
dest_format->reverse_endian);
*dest_size_r = dest_size; *dest_size_r = dest_size;
return dest; return dest;
...@@ -314,11 +300,6 @@ pcm_convert_32(struct pcm_convert_state *state, ...@@ -314,11 +300,6 @@ pcm_convert_32(struct pcm_convert_state *state,
return buf; return buf;
} }
if (dest_format->reverse_endian) {
buf = pcm_byteswap_32(&state->byteswap_buffer, buf, len);
assert(buf != NULL);
}
*dest_size_r = len; *dest_size_r = len;
return buf; return buf;
} }
...@@ -335,12 +316,6 @@ pcm_convert_float(struct pcm_convert_state *state, ...@@ -335,12 +316,6 @@ pcm_convert_float(struct pcm_convert_state *state,
assert(dest_format->format == SAMPLE_FORMAT_FLOAT); assert(dest_format->format == SAMPLE_FORMAT_FLOAT);
if (src_format->reverse_endian || dest_format->reverse_endian) {
g_set_error_literal(error_r, pcm_convert_quark(), 0,
"Reverse endian not supported");
return NULL;
}
/* convert channels first, hoping the source format is /* convert channels first, hoping the source format is
supported (float is not) */ supported (float is not) */
...@@ -392,20 +367,6 @@ pcm_convert(struct pcm_convert_state *state, ...@@ -392,20 +367,6 @@ pcm_convert(struct pcm_convert_state *state,
size_t *dest_size_r, size_t *dest_size_r,
GError **error_r) GError **error_r)
{ {
if (src_format->reverse_endian) {
/* convert to host byte order, because all of our
conversion libraries assume host byte order */
src = pcm_byteswap(&state->byteswap_buffer, src_format->format,
src, src_size);
if (src == NULL) {
g_set_error(error_r, pcm_convert_quark(), 0,
"PCM byte order change of format '%s' is not implemented",
sample_format_to_string(src_format->format));
return NULL;
}
}
struct audio_format float_format; struct audio_format float_format;
if (src_format->format == SAMPLE_FORMAT_DSD) { if (src_format->format == SAMPLE_FORMAT_DSD) {
size_t f_size; size_t f_size;
......
...@@ -47,9 +47,6 @@ struct pcm_convert_state { ...@@ -47,9 +47,6 @@ struct pcm_convert_state {
/** the buffer for converting the channel count */ /** the buffer for converting the channel count */
struct pcm_buffer channels_buffer; struct pcm_buffer channels_buffer;
/** the buffer for swapping the byte order */
struct pcm_buffer byteswap_buffer;
}; };
static inline GQuark static inline GQuark
......
...@@ -76,7 +76,7 @@ pcm_allocate_24_to_24p32(struct pcm_buffer *buffer, const uint8_t *src, ...@@ -76,7 +76,7 @@ pcm_allocate_24_to_24p32(struct pcm_buffer *buffer, const uint8_t *src,
int32_t *dest; int32_t *dest;
*dest_size_r = src_size / 3 * sizeof(*dest); *dest_size_r = src_size / 3 * sizeof(*dest);
dest = pcm_buffer_get(buffer, *dest_size_r); dest = pcm_buffer_get(buffer, *dest_size_r);
pcm_unpack_24(dest, src, pcm_end_pointer(src, src_size), false); pcm_unpack_24(dest, src, pcm_end_pointer(src, src_size));
return dest; return dest;
} }
......
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
#include <glib.h> #include <glib.h>
static void static void
pack_sample(uint8_t *dest, const int32_t *src0, bool reverse_endian) pack_sample(uint8_t *dest, const int32_t *src0)
{ {
const uint8_t *src = (const uint8_t *)src0; const uint8_t *src = (const uint8_t *)src0;
if ((G_BYTE_ORDER == G_BIG_ENDIAN) != reverse_endian) if (G_BYTE_ORDER == G_BIG_ENDIAN)
++src; ++src;
*dest++ = *src++; *dest++ = *src++;
...@@ -35,31 +35,23 @@ pack_sample(uint8_t *dest, const int32_t *src0, bool reverse_endian) ...@@ -35,31 +35,23 @@ pack_sample(uint8_t *dest, const int32_t *src0, bool reverse_endian)
} }
void void
pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end, pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end)
bool reverse_endian)
{ {
/* duplicate loop to help the compiler's optimizer (constant /* duplicate loop to help the compiler's optimizer (constant
parameter to the pack_sample() inline function) */ parameter to the pack_sample() inline function) */
if (G_LIKELY(!reverse_endian)) { while (src < src_end) {
while (src < src_end) { pack_sample(dest, src++);
pack_sample(dest, src++, false); dest += 3;
dest += 3;
}
} else {
while (src < src_end) {
pack_sample(dest, src++, true);
dest += 3;
}
} }
} }
static void static void
unpack_sample(int32_t *dest0, const uint8_t *src, bool reverse_endian) unpack_sample(int32_t *dest0, const uint8_t *src)
{ {
uint8_t *dest = (uint8_t *)dest0; uint8_t *dest = (uint8_t *)dest0;
if ((G_BYTE_ORDER == G_BIG_ENDIAN) != reverse_endian) if (G_BYTE_ORDER == G_BIG_ENDIAN)
/* extend the sign bit to the most fourth byte */ /* extend the sign bit to the most fourth byte */
*dest++ = *src & 0x80 ? 0xff : 0x00; *dest++ = *src & 0x80 ? 0xff : 0x00;
...@@ -67,27 +59,19 @@ unpack_sample(int32_t *dest0, const uint8_t *src, bool reverse_endian) ...@@ -67,27 +59,19 @@ unpack_sample(int32_t *dest0, const uint8_t *src, bool reverse_endian)
*dest++ = *src++; *dest++ = *src++;
*dest++ = *src; *dest++ = *src;
if ((G_BYTE_ORDER == G_LITTLE_ENDIAN) != reverse_endian) if (G_BYTE_ORDER != G_LITTLE_ENDIAN)
/* extend the sign bit to the most fourth byte */ /* extend the sign bit to the most fourth byte */
*dest++ = *src & 0x80 ? 0xff : 0x00; *dest++ = *src & 0x80 ? 0xff : 0x00;
} }
void void
pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end, pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end)
bool reverse_endian)
{ {
/* duplicate loop to help the compiler's optimizer (constant /* duplicate loop to help the compiler's optimizer (constant
parameter to the unpack_sample() inline function) */ parameter to the unpack_sample() inline function) */
if (G_LIKELY(!reverse_endian)) { while (src < src_end) {
while (src < src_end) { unpack_sample(dest++, src);
unpack_sample(dest++, src, false); src += 3;
src += 3;
}
} else {
while (src < src_end) {
unpack_sample(dest++, src, true);
src += 3;
}
} }
} }
...@@ -37,11 +37,9 @@ ...@@ -37,11 +37,9 @@
* @param dest the destination buffer (array of triples) * @param dest the destination buffer (array of triples)
* @param src the source buffer * @param src the source buffer
* @param num_samples the number of samples to convert * @param num_samples the number of samples to convert
* @param reverse_endian is src and dest in non-host byte order?
*/ */
void void
pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end, pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end);
bool reverse_endian);
/** /**
* Converts packed 24 bit samples (3 bytes per sample) to padded 24 * Converts packed 24 bit samples (3 bytes per sample) to padded 24
...@@ -50,10 +48,8 @@ pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end, ...@@ -50,10 +48,8 @@ pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end,
* @param dest the destination buffer * @param dest the destination buffer
* @param src the source buffer (array of triples) * @param src the source buffer (array of triples)
* @param num_samples the number of samples to convert * @param num_samples the number of samples to convert
* @param reverse_endian is src and dest in non-host byte order?
*/ */
void void
pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end, pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end);
bool reverse_endian);
#endif #endif
...@@ -45,7 +45,7 @@ test_pcm_pack_24(void) ...@@ -45,7 +45,7 @@ test_pcm_pack_24(void)
uint8_t dest[N * 3]; uint8_t dest[N * 3];
pcm_pack_24(dest, src, src + N, false); pcm_pack_24(dest, src, src + N);
for (unsigned i = 0; i < N; ++i) { for (unsigned i = 0; i < N; ++i) {
int32_t d; int32_t d;
...@@ -72,7 +72,7 @@ test_pcm_unpack_24(void) ...@@ -72,7 +72,7 @@ test_pcm_unpack_24(void)
int32_t dest[N]; int32_t dest[N];
pcm_unpack_24(dest, src, src + G_N_ELEMENTS(src), false); pcm_unpack_24(dest, src, src + G_N_ELEMENTS(src));
for (unsigned i = 0; i < N; ++i) { for (unsigned i = 0; i < N; ++i) {
int32_t s; int32_t s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment