aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_convert.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-17 13:11:16 +0100
committerMax Kellermann <max@duempel.org>2009-01-17 13:11:16 +0100
commit356526457c49384d6ff5b652aa0f33dc74d23508 (patch)
treeb6fe57ffde36c366e2c6e3e650300b8e3b6126f8 /src/pcm_convert.c
parente726e2a0042f88d84a167bc955fe9d280db82c90 (diff)
downloadmpd-356526457c49384d6ff5b652aa0f33dc74d23508.tar.gz
mpd-356526457c49384d6ff5b652aa0f33dc74d23508.tar.xz
mpd-356526457c49384d6ff5b652aa0f33dc74d23508.zip
pcm_convert: return PCM buffer from pcm_convert()
Removed yet another superfluous buffer layer: return the PCM buffer from pcm_convert() instead of copying PCM data into the caller-supplied buffer.
Diffstat (limited to '')
-rw-r--r--src/pcm_convert.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/pcm_convert.c b/src/pcm_convert.c
index 2209249a6..42d72e367 100644
--- a/src/pcm_convert.c
+++ b/src/pcm_convert.c
@@ -48,12 +48,12 @@ void pcm_convert_deinit(struct pcm_convert_state *state)
pcm_buffer_deinit(&state->channels_buffer);
}
-static size_t
-pcm_convert_16(const struct audio_format *src_format,
+static const int16_t *
+pcm_convert_16(struct pcm_convert_state *state,
+ const struct audio_format *src_format,
const void *src_buffer, size_t src_size,
const struct audio_format *dest_format,
- int16_t *dest_buffer,
- struct pcm_convert_state *state)
+ size_t *dest_size_r)
{
const int16_t *buf;
size_t len;
@@ -82,18 +82,16 @@ pcm_convert_16(const struct audio_format *src_format,
dest_format->sample_rate,
&len);
- assert(pcm_convert_size(src_format, src_size, dest_format) >= len);
- memcpy(dest_buffer, buf, len);
-
- return len;
+ *dest_size_r = len;
+ return buf;
}
-static size_t
-pcm_convert_24(const struct audio_format *src_format,
+static const int32_t *
+pcm_convert_24(struct pcm_convert_state *state,
+ const struct audio_format *src_format,
const void *src_buffer, size_t src_size,
const struct audio_format *dest_format,
- int32_t *dest_buffer,
- struct pcm_convert_state *state)
+ size_t *dest_size_r)
{
const int32_t *buf;
size_t len;
@@ -121,30 +119,30 @@ pcm_convert_24(const struct audio_format *src_format,
dest_format->sample_rate,
&len);
- assert(pcm_convert_size(src_format, src_size, dest_format) >= len);
- memcpy(dest_buffer, buf, len);
-
- return len;
+ *dest_size_r = len;
+ return buf;
}
-size_t pcm_convert(const struct audio_format *inFormat,
- const void *src, size_t src_size,
- const struct audio_format *outFormat,
- void *dest,
- struct pcm_convert_state *convState)
+const void *
+pcm_convert(struct pcm_convert_state *state,
+ const struct audio_format *src_format,
+ const void *src, size_t src_size,
+ const struct audio_format *dest_format,
+ size_t *dest_size_r)
{
- switch (outFormat->bits) {
+ switch (dest_format->bits) {
case 16:
- return pcm_convert_16(inFormat, src, src_size,
- outFormat, (int16_t*)dest,
- convState);
+ return pcm_convert_16(state,
+ src_format, src, src_size,
+ dest_format, dest_size_r);
+
case 24:
- return pcm_convert_24(inFormat, src, src_size,
- outFormat, (int32_t*)dest,
- convState);
+ return pcm_convert_24(state,
+ src_format, src, src_size,
+ dest_format, dest_size_r);
default:
- g_error("cannot convert to %u bit\n", outFormat->bits);
+ g_error("cannot convert to %u bit\n", dest_format->bits);
return 0;
}
}