aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-07 23:56:35 +0100
committerMax Kellermann <max@duempel.org>2009-01-07 23:56:35 +0100
commitaab85577bf7576895ccae0403d5cb95aa113f7f0 (patch)
tree587622c9ddd091c2d81926fe0aab05614ee357d9
parent5fe7e3bc1465a1a5f618b50f87aa0266d22ec75e (diff)
downloadmpd-aab85577bf7576895ccae0403d5cb95aa113f7f0.tar.gz
mpd-aab85577bf7576895ccae0403d5cb95aa113f7f0.tar.xz
mpd-aab85577bf7576895ccae0403d5cb95aa113f7f0.zip
pcm_channels: use pcm_buffer
Replace a "static" buffer with the PCM buffer library.
Diffstat (limited to '')
-rw-r--r--src/pcm_channels.c39
-rw-r--r--src/pcm_channels.h8
-rw-r--r--src/pcm_convert.c8
-rw-r--r--src/pcm_convert.h3
4 files changed, 30 insertions, 28 deletions
diff --git a/src/pcm_channels.c b/src/pcm_channels.c
index 13fe81cb4..a63c7f2e9 100644
--- a/src/pcm_channels.c
+++ b/src/pcm_channels.c
@@ -17,6 +17,7 @@
*/
#include "pcm_channels.h"
+#include "pcm_buffer.h"
#include <glib.h>
@@ -72,28 +73,23 @@ pcm_convert_channels_16_n_to_2(int16_t *dest,
}
const int16_t *
-pcm_convert_channels_16(int8_t dest_channels,
+pcm_convert_channels_16(struct pcm_buffer *buffer,
+ int8_t dest_channels,
int8_t src_channels, const int16_t *src,
size_t src_size, size_t *dest_size_r)
{
- static int16_t *buf;
- static size_t len;
unsigned num_frames = src_size / src_channels / sizeof(*src);
unsigned dest_size = num_frames * dest_channels * sizeof(*src);
-
- if (dest_size > len) {
- len = dest_size;
- buf = g_realloc(buf, len);
- }
+ int16_t *dest = pcm_buffer_get(buffer, dest_size);
*dest_size_r = dest_size;
if (src_channels == 1 && dest_channels == 2)
- pcm_convert_channels_16_1_to_2(buf, src, num_frames);
+ pcm_convert_channels_16_1_to_2(dest, src, num_frames);
else if (src_channels == 2 && dest_channels == 1)
- pcm_convert_channels_16_2_to_1(buf, src, num_frames);
+ pcm_convert_channels_16_2_to_1(dest, src, num_frames);
else if (dest_channels == 2)
- pcm_convert_channels_16_n_to_2(buf, src_channels, src,
+ pcm_convert_channels_16_n_to_2(dest, src_channels, src,
num_frames);
else {
g_warning("conversion %u->%u channels is not supported",
@@ -101,7 +97,7 @@ pcm_convert_channels_16(int8_t dest_channels,
return NULL;
}
- return buf;
+ return dest;
}
static void
@@ -151,28 +147,23 @@ pcm_convert_channels_24_n_to_2(int32_t *dest,
}
const int32_t *
-pcm_convert_channels_24(int8_t dest_channels,
+pcm_convert_channels_24(struct pcm_buffer *buffer,
+ int8_t dest_channels,
int8_t src_channels, const int32_t *src,
size_t src_size, size_t *dest_size_r)
{
- static int32_t *buf;
- static size_t len;
unsigned num_frames = src_size / src_channels / sizeof(*src);
unsigned dest_size = num_frames * dest_channels * sizeof(*src);
-
- if (dest_size > len) {
- len = dest_size;
- buf = g_realloc(buf, len);
- }
+ int32_t *dest = pcm_buffer_get(buffer, dest_size);
*dest_size_r = dest_size;
if (src_channels == 1 && dest_channels == 2)
- pcm_convert_channels_24_1_to_2(buf, src, num_frames);
+ pcm_convert_channels_24_1_to_2(dest, src, num_frames);
else if (src_channels == 2 && dest_channels == 1)
- pcm_convert_channels_24_2_to_1(buf, src, num_frames);
+ pcm_convert_channels_24_2_to_1(dest, src, num_frames);
else if (dest_channels == 2)
- pcm_convert_channels_24_n_to_2(buf, src_channels, src,
+ pcm_convert_channels_24_n_to_2(dest, src_channels, src,
num_frames);
else {
g_warning("conversion %u->%u channels is not supported",
@@ -180,5 +171,5 @@ pcm_convert_channels_24(int8_t dest_channels,
return NULL;
}
- return buf;
+ return dest;
}
diff --git a/src/pcm_channels.h b/src/pcm_channels.h
index fa27fdb8f..b4699ed8f 100644
--- a/src/pcm_channels.h
+++ b/src/pcm_channels.h
@@ -22,13 +22,17 @@
#include <stdint.h>
#include <stddef.h>
+struct pcm_buffer;
+
const int16_t *
-pcm_convert_channels_16(int8_t dest_channels,
+pcm_convert_channels_16(struct pcm_buffer *buffer,
+ int8_t dest_channels,
int8_t src_channels, const int16_t *src,
size_t src_size, size_t *dest_size_r);
const int32_t *
-pcm_convert_channels_24(int8_t dest_channels,
+pcm_convert_channels_24(struct pcm_buffer *buffer,
+ int8_t dest_channels,
int8_t src_channels, const int32_t *src,
size_t src_size, size_t *dest_size_r);
diff --git a/src/pcm_convert.c b/src/pcm_convert.c
index e0ab4ecd3..b9db24b9a 100644
--- a/src/pcm_convert.c
+++ b/src/pcm_convert.c
@@ -37,6 +37,7 @@ void pcm_convert_init(struct pcm_convert_state *state)
pcm_dither_24_init(&state->dither);
pcm_buffer_init(&state->format_buffer);
+ pcm_buffer_init(&state->channels_buffer);
}
void pcm_convert_deinit(struct pcm_convert_state *state)
@@ -44,6 +45,7 @@ void pcm_convert_deinit(struct pcm_convert_state *state)
pcm_resample_deinit(&state->resample);
pcm_buffer_deinit(&state->format_buffer);
+ pcm_buffer_deinit(&state->channels_buffer);
}
static size_t
@@ -66,7 +68,8 @@ pcm_convert_16(const struct audio_format *src_format,
g_error("pcm_convert_to_16() failed");
if (src_format->channels != dest_format->channels) {
- buf = pcm_convert_channels_16(dest_format->channels,
+ buf = pcm_convert_channels_16(&state->channels_buffer,
+ dest_format->channels,
src_format->channels,
buf, len, &len);
if (!buf)
@@ -106,7 +109,8 @@ pcm_convert_24(const struct audio_format *src_format,
g_error("pcm_convert_to_24() failed");
if (src_format->channels != dest_format->channels) {
- buf = pcm_convert_channels_24(dest_format->channels,
+ buf = pcm_convert_channels_24(&state->channels_buffer,
+ dest_format->channels,
src_format->channels,
buf, len, &len);
if (!buf)
diff --git a/src/pcm_convert.h b/src/pcm_convert.h
index e48315795..46ee55407 100644
--- a/src/pcm_convert.h
+++ b/src/pcm_convert.h
@@ -32,6 +32,9 @@ struct pcm_convert_state {
/** the buffer for converting the sample format */
struct pcm_buffer format_buffer;
+
+ /** the buffer for converting the channel count */
+ struct pcm_buffer channels_buffer;
};
void pcm_convert_init(struct pcm_convert_state *state);