Commit c5a662f4 authored by Max Kellermann's avatar Max Kellermann

pcm_convert: added pcm_convert_state.byteswap_buffer

Currently, byteswapping is performed on the format_buffer. This can go wrong when this buffer is used twice during one run. Add a separate buffer for swapping the byte order.
parent 92779504
...@@ -40,6 +40,7 @@ void pcm_convert_init(struct pcm_convert_state *state) ...@@ -40,6 +40,7 @@ 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->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)
...@@ -48,6 +49,7 @@ void pcm_convert_deinit(struct pcm_convert_state *state) ...@@ -48,6 +49,7 @@ 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->channels_buffer); pcm_buffer_deinit(&state->channels_buffer);
pcm_buffer_deinit(&state->byteswap_buffer);
} }
static const int16_t * static const int16_t *
...@@ -85,7 +87,7 @@ pcm_convert_16(struct pcm_convert_state *state, ...@@ -85,7 +87,7 @@ pcm_convert_16(struct pcm_convert_state *state,
&len); &len);
if (dest_format->reverse_endian) { if (dest_format->reverse_endian) {
buf = pcm_byteswap_16(&state->format_buffer, buf, len); buf = pcm_byteswap_16(&state->byteswap_buffer, buf, len);
if (!buf) if (!buf)
g_error("pcm_byteswap_16() failed"); g_error("pcm_byteswap_16() failed");
} }
...@@ -128,7 +130,7 @@ pcm_convert_24(struct pcm_convert_state *state, ...@@ -128,7 +130,7 @@ pcm_convert_24(struct pcm_convert_state *state,
&len); &len);
if (dest_format->reverse_endian) { if (dest_format->reverse_endian) {
buf = pcm_byteswap_32(&state->format_buffer, buf, len); buf = pcm_byteswap_32(&state->byteswap_buffer, buf, len);
if (!buf) if (!buf)
g_error("pcm_byteswap_32() failed"); g_error("pcm_byteswap_32() failed");
} }
...@@ -171,7 +173,7 @@ pcm_convert_32(struct pcm_convert_state *state, ...@@ -171,7 +173,7 @@ pcm_convert_32(struct pcm_convert_state *state,
&len); &len);
if (dest_format->reverse_endian) { if (dest_format->reverse_endian) {
buf = pcm_byteswap_32(&state->format_buffer, buf, len); buf = pcm_byteswap_32(&state->byteswap_buffer, buf, len);
if (!buf) if (!buf)
g_error("pcm_byteswap_32() failed"); g_error("pcm_byteswap_32() failed");
} }
......
...@@ -41,6 +41,9 @@ struct pcm_convert_state { ...@@ -41,6 +41,9 @@ 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;
}; };
/** /**
......
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