aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_format.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-10-09 12:37:32 +0200
committerMax Kellermann <max@duempel.org>2011-10-10 10:24:06 +0200
commit20c6159c041cc5ec644c51009503cf6801b6fcab (patch)
tree55e38810c32ca6059bafd61578705172feb299e2 /src/pcm_format.c
parenta47e9d1a4b5bd6b999eaec33624d7c96a29f24e6 (diff)
downloadmpd-20c6159c041cc5ec644c51009503cf6801b6fcab.tar.gz
mpd-20c6159c041cc5ec644c51009503cf6801b6fcab.tar.xz
mpd-20c6159c041cc5ec644c51009503cf6801b6fcab.zip
pcm_dither: pass an "end" pointer instead of a sample count
This is easier and more efficient to loop on, because only two variables get modified (src and dest).
Diffstat (limited to '')
-rw-r--r--src/pcm_format.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/pcm_format.c b/src/pcm_format.c
index 21459f0f4..148cd70ed 100644
--- a/src/pcm_format.c
+++ b/src/pcm_format.c
@@ -35,18 +35,16 @@ pcm_convert_8_to_16(int16_t *out, const int8_t *in,
static void
pcm_convert_24_to_16(struct pcm_dither *dither,
- int16_t *out, const int32_t *in,
- unsigned num_samples)
+ int16_t *out, const int32_t *in, const int32_t *in_end)
{
- pcm_dither_24_to_16(dither, out, in, num_samples);
+ pcm_dither_24_to_16(dither, out, in, in_end);
}
static void
pcm_convert_32_to_16(struct pcm_dither *dither,
- int16_t *out, const int32_t *in,
- unsigned num_samples)
+ int16_t *out, const int32_t *in, const int32_t *in_end)
{
- pcm_dither_32_to_16(dither, out, in, num_samples);
+ pcm_dither_32_to_16(dither, out, in, in_end);
}
static int32_t *
@@ -63,6 +61,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r)
{
+ const void *src_end = (const char *)src + src_size;
unsigned num_samples;
int16_t *dest;
int32_t *dest32;
@@ -95,7 +94,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
/* convert to 16 bit in-place */
*dest_size_r = num_samples * sizeof(*dest);
pcm_convert_24_to_16(dither, dest, dest32,
- num_samples);
+ dest32 + num_samples);
return dest;
case SAMPLE_FORMAT_S24_P32:
@@ -105,7 +104,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
pcm_convert_24_to_16(dither, dest,
(const int32_t *)src,
- num_samples);
+ (const int32_t *)src_end);
return dest;
case SAMPLE_FORMAT_S32:
@@ -115,7 +114,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
pcm_convert_32_to_16(dither, dest,
(const int32_t *)src,
- num_samples);
+ (const int32_t *)src_end);
return dest;
}