aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_channels.c
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 /src/pcm_channels.c
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 'src/pcm_channels.c')
-rw-r--r--src/pcm_channels.c39
1 files changed, 15 insertions, 24 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;
}