Commit a47e9d1a authored by Max Kellermann's avatar Max Kellermann

pcm_pack: pass an "end" pointer instead of a sample count

parent e93dd374
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment