recording: fix mono mode mixdown functions
Rewrite copy_buffer_mono_* functions for correctness. Bad pointer arithmetic in copy_buffer_mono_l produced wrong results, or panics on archs which can't handle the unaligned pointer. None of the functions handled zero size copies properly though this probably wasn't an issue in practice. Change-Id: I81c894e1b8a3440cb409092bec07fe3778a78959
This commit is contained in:
parent
f68c6c14d9
commit
525eb15864
1 changed files with 22 additions and 38 deletions
|
@ -878,54 +878,38 @@ copy_buffer_mono_lr(void *dst, const void *src, size_t src_size)
|
|||
ssize_t copy_size = src_size;
|
||||
|
||||
/* mono = (L + R) / 2 */
|
||||
do
|
||||
{
|
||||
*d++ = ((int32_t){s[0]} + s[1] + 1) >> 1;
|
||||
s+=2;
|
||||
while(copy_size > 0) {
|
||||
*d++ = ((int32_t)s[0] + (int32_t)s[1] + 1) >> 1;
|
||||
s += 2;
|
||||
copy_size -= PCM_SAMP_SIZE;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
static void * ICODE_ATTR
|
||||
copy_buffer_mono_l(void *dst, const void *src, size_t src_size)
|
||||
{
|
||||
int16_t *d = (int16_t*) dst;
|
||||
int16_t const *s = (int16_t const*) src;
|
||||
ssize_t copy_size = src_size;
|
||||
|
||||
/* mono = L */
|
||||
while(copy_size > 0) {
|
||||
*d++ = *s;
|
||||
s += 2;
|
||||
copy_size -= PCM_SAMP_SIZE;
|
||||
}
|
||||
while ((copy_size -= PCM_SAMP_SIZE) > 0);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* Copy with mono conversion - output 1/2 size of input */
|
||||
static void * ICODE_ATTR
|
||||
copy_buffer_mono_r(void *dst, const void *src, size_t src_size)
|
||||
{
|
||||
int16_t *d = (int16_t*)dst;
|
||||
int16_t const *s = (int16_t const*)src - 1;
|
||||
ssize_t copy_size = src_size;
|
||||
/* mono = R */
|
||||
do
|
||||
*d++ = *(s += 2);
|
||||
while ((copy_size -= PCM_SAMP_SIZE) > 0);
|
||||
|
||||
return dst;
|
||||
return copy_buffer_mono_l(dst, src + 2, src_size);
|
||||
}
|
||||
|
||||
#if 1
|
||||
static void * ICODE_ATTR
|
||||
copy_buffer_mono_l(void *dst, const void *src, size_t src_size)
|
||||
{
|
||||
return copy_buffer_mono_r(dst, src -1, src_size);
|
||||
}
|
||||
#else
|
||||
/* Copy with mono conversion - output 1/2 size of input */
|
||||
static void * ICODE_ATTR
|
||||
copy_buffer_mono_l(void *dst, const void *src, size_t src_size)
|
||||
{
|
||||
int16_t *d = (int16_t*)dst;
|
||||
int16_t const *s = (int16_t const*)src - 2;
|
||||
ssize_t copy_size = src_size;
|
||||
/* mono = L */
|
||||
do
|
||||
*d++ = *(s += 2);
|
||||
while ((copy_size -= PCM_SAMP_SIZE) > 0);
|
||||
|
||||
return dst;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** pcm_rec_* group **/
|
||||
|
||||
|
|
Loading…
Reference in a new issue