aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-23 20:11:24 +0200
committerMax Kellermann <max@duempel.org>2008-10-23 20:11:24 +0200
commit98e4817548ab18a696defb1db6bd74eafc3b7998 (patch)
tree887c351419697b45ee6fe5073fb52411a122deec
parent8489e90c1e8d275aabf891c2659a5cb59e5037b4 (diff)
downloadmpd-98e4817548ab18a696defb1db6bd74eafc3b7998.tar.gz
mpd-98e4817548ab18a696defb1db6bd74eafc3b7998.tar.xz
mpd-98e4817548ab18a696defb1db6bd74eafc3b7998.zip
pcm_utils: moved code to pcm_convert_16()
pcm_convert() converted only to 16 bit. To be able to support other sample sizes, move that 16 bit specific code to a separate function.
-rw-r--r--src/pcm_utils.c60
1 files changed, 39 insertions, 21 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 56627098f..63685e0b2 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -278,41 +278,41 @@ pcm_convert_to_16(struct pcm_convert_state *convert,
return NULL;
}
-/* outFormat bits must be 16 and channels must be 1 or 2! */
-size_t pcm_convert(const struct audio_format *inFormat,
- const char *src, size_t src_size,
- const struct audio_format *outFormat,
- char *outBuffer,
- struct pcm_convert_state *convState)
+static size_t
+pcm_convert_16(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)
{
const int16_t *buf;
- size_t len = 0;
- size_t dest_size = pcm_convert_size(inFormat, src_size, outFormat);
+ size_t len;
+ size_t dest_size = pcm_convert_size(src_format, src_size, dest_format);
- assert(outFormat->bits == 16);
+ assert(dest_format->bits == 16);
- /* everything else supports 16 bit only, so convert to that first */
- buf = pcm_convert_to_16(convState, inFormat->bits, src, src_size, &len);
+ buf = pcm_convert_to_16(state, src_format->bits,
+ src_buffer, src_size, &len);
if (!buf)
exit(EXIT_FAILURE);
- if (inFormat->channels != outFormat->channels) {
- buf = pcm_convert_channels_16(outFormat->channels,
- inFormat->channels,
+ if (src_format->channels != dest_format->channels) {
+ buf = pcm_convert_channels_16(dest_format->channels,
+ src_format->channels,
buf, len, &len);
if (!buf)
exit(EXIT_FAILURE);
}
- if (inFormat->sample_rate == outFormat->sample_rate) {
+ if (src_format->sample_rate == dest_format->sample_rate) {
assert(dest_size >= len);
- memcpy(outBuffer, buf, len);
+ memcpy(dest_buffer, buf, len);
} else {
- len = pcm_resample_16(outFormat->channels,
- inFormat->sample_rate, buf, len,
- outFormat->sample_rate,
- (int16_t*)outBuffer,
- dest_size, &convState->resample);
+ len = pcm_resample_16(dest_format->channels,
+ src_format->sample_rate, buf, len,
+ dest_format->sample_rate,
+ dest_buffer, dest_size,
+ &state->resample);
if (len == 0)
exit(EXIT_FAILURE);
}
@@ -320,6 +320,24 @@ size_t pcm_convert(const struct audio_format *inFormat,
return len;
}
+/* outFormat bits must be 16 and channels must be 1 or 2! */
+size_t pcm_convert(const struct audio_format *inFormat,
+ const char *src, size_t src_size,
+ const struct audio_format *outFormat,
+ char *outBuffer,
+ struct pcm_convert_state *convState)
+{
+ switch (outFormat->bits) {
+ case 16:
+ return pcm_convert_16(inFormat, src, src_size,
+ outFormat, (int16_t*)outBuffer,
+ convState);
+
+ default:
+ FATAL("cannot convert to %u bit\n", outFormat->bits);
+ }
+}
+
size_t pcm_convert_size(const struct audio_format *inFormat, size_t src_size,
const struct audio_format *outFormat)
{