diff options
-rw-r--r-- | src/pcm_convert.c | 3 | ||||
-rw-r--r-- | src/pcm_format.c | 2 | ||||
-rw-r--r-- | src/pcm_pack.c | 12 | ||||
-rw-r--r-- | src/pcm_pack.h | 4 | ||||
-rw-r--r-- | test/test_pcm_pack.c | 4 |
5 files changed, 13 insertions, 12 deletions
diff --git a/src/pcm_convert.c b/src/pcm_convert.c index 4dbeee41f..c145e437a 100644 --- a/src/pcm_convert.c +++ b/src/pcm_convert.c @@ -200,7 +200,8 @@ pcm_convert_24_packed(struct pcm_convert_state *state, size_t dest_size = num_samples * 3; uint8_t *dest = pcm_buffer_get(&state->pack_buffer, dest_size); - pcm_pack_24(dest, buffer, num_samples, dest_format->reverse_endian); + pcm_pack_24(dest, buffer, buffer + num_samples, + dest_format->reverse_endian); *dest_size_r = dest_size; return dest; diff --git a/src/pcm_format.c b/src/pcm_format.c index 544b0ccd9..21459f0f4 100644 --- a/src/pcm_format.c +++ b/src/pcm_format.c @@ -54,7 +54,7 @@ pcm_convert_24_to_24p32(struct pcm_buffer *buffer, const uint8_t *src, unsigned num_samples) { int32_t *dest = pcm_buffer_get(buffer, num_samples * 4); - pcm_unpack_24(dest, src, num_samples, false); + pcm_unpack_24(dest, src, src + num_samples * 3, false); return dest; } diff --git a/src/pcm_pack.c b/src/pcm_pack.c index 680d2a32f..94fda5910 100644 --- a/src/pcm_pack.c +++ b/src/pcm_pack.c @@ -35,19 +35,19 @@ pack_sample(uint8_t *dest, const int32_t *src0, bool reverse_endian) } void -pcm_pack_24(uint8_t *dest, const int32_t *src, unsigned num_samples, +pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end, bool reverse_endian) { /* duplicate loop to help the compiler's optimizer (constant parameter to the pack_sample() inline function) */ if (G_LIKELY(!reverse_endian)) { - while (num_samples-- > 0) { + while (src < src_end) { pack_sample(dest, src++, false); dest += 3; } } else { - while (num_samples-- > 0) { + while (src < src_end) { pack_sample(dest, src++, true); dest += 3; } @@ -73,19 +73,19 @@ unpack_sample(int32_t *dest0, const uint8_t *src, bool reverse_endian) } void -pcm_unpack_24(int32_t *dest, const uint8_t *src, unsigned num_samples, +pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end, bool reverse_endian) { /* duplicate loop to help the compiler's optimizer (constant parameter to the unpack_sample() inline function) */ if (G_LIKELY(!reverse_endian)) { - while (num_samples-- > 0) { + while (src < src_end) { unpack_sample(dest++, src, false); src += 3; } } else { - while (num_samples-- > 0) { + while (src < src_end) { unpack_sample(dest++, src, true); src += 3; } diff --git a/src/pcm_pack.h b/src/pcm_pack.h index 0055e91df..6f275608c 100644 --- a/src/pcm_pack.h +++ b/src/pcm_pack.h @@ -40,7 +40,7 @@ * @param reverse_endian is src and dest in non-host byte order? */ void -pcm_pack_24(uint8_t *dest, const int32_t *src, unsigned num_samples, +pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end, bool reverse_endian); /** @@ -53,7 +53,7 @@ pcm_pack_24(uint8_t *dest, const int32_t *src, unsigned num_samples, * @param reverse_endian is src and dest in non-host byte order? */ void -pcm_unpack_24(int32_t *dest, const uint8_t *src, unsigned num_samples, +pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end, bool reverse_endian); #endif diff --git a/test/test_pcm_pack.c b/test/test_pcm_pack.c index 81bc32575..921bb7932 100644 --- a/test/test_pcm_pack.c +++ b/test/test_pcm_pack.c @@ -44,7 +44,7 @@ test_pcm_pack_24(void) uint8_t dest[N * 3]; - pcm_pack_24(dest, src, N, false); + pcm_pack_24(dest, src, src + N, false); for (unsigned i = 0; i < N; ++i) { int32_t d; @@ -71,7 +71,7 @@ test_pcm_unpack_24(void) int32_t dest[N]; - pcm_unpack_24(dest, src, N, false); + pcm_unpack_24(dest, src, src + G_N_ELEMENTS(src), false); for (unsigned i = 0; i < N; ++i) { int32_t s; |