audiomixer: add support for U8, U16, U24, U32, S24_32 and U24_32 formats

This commit is contained in:
Julian Bouzas 2021-09-08 09:15:21 -04:00
parent 20e64b39da
commit 7d0a8b68e8
4 changed files with 173 additions and 1 deletions

View file

@ -49,6 +49,25 @@ mix_s8_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT
}
}
void
mix_u8_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
{
uint32_t i, n;
uint8_t *d = dst;
if (n_src == 0)
memset(dst, 0, n_samples * ops->n_channels * sizeof(uint8_t));
else if (dst != src[0])
memcpy(dst, src[0], n_samples * ops->n_channels * sizeof(uint8_t));
for (i = 1; i < n_src; i++) {
const uint8_t *s = src[i];
for (n = 0; n < n_samples * ops->n_channels; n++)
d[n] = U8_MIX(d[n], s[n]);
}
}
void
mix_s16_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
@ -68,6 +87,25 @@ mix_s16_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRIC
}
}
void
mix_u16_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
{
uint32_t i, n;
uint16_t *d = dst;
if (n_src == 0)
memset(dst, 0, n_samples * ops->n_channels * sizeof(uint16_t));
else if (dst != src[0])
memcpy(dst, src[0], n_samples * ops->n_channels * sizeof(uint16_t));
for (i = 1; i < n_src; i++) {
const uint16_t *s = src[i];
for (n = 0; n < n_samples * ops->n_channels; n++)
d[n] = U16_MIX(d[n], s[n]);
}
}
void
mix_s24_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
@ -90,6 +128,28 @@ mix_s24_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRIC
}
}
void
mix_u24_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
{
uint32_t i, n;
uint8_t *d = dst;
if (n_src == 0)
memset(dst, 0, n_samples * ops->n_channels * sizeof(uint8_t) * 3);
else if (dst != src[0])
memcpy(dst, src[0], n_samples * ops->n_channels * sizeof(uint8_t) * 3);
for (i = 1; i < n_src; i++) {
const uint8_t *s = src[i];
for (n = 0; n < n_samples * ops->n_channels; n++) {
write_u24(d, U24_MIX(read_u24(d), read_u24(s)));
d += 3;
s += 3;
}
}
}
void
mix_s32_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
@ -109,6 +169,63 @@ mix_s32_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRIC
}
}
void
mix_u32_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
{
uint32_t i, n;
uint32_t *d = dst;
if (n_src == 0)
memset(dst, 0, n_samples * ops->n_channels * sizeof(uint32_t));
else if (dst != src[0])
memcpy(dst, src[0], n_samples * ops->n_channels * sizeof(uint32_t));
for (i = 1; i < n_src; i++) {
const uint32_t *s = src[i];
for (n = 0; n < n_samples * ops->n_channels; n++)
d[n] = U32_MIX(d[n], s[n]);
}
}
void
mix_s24_32_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
{
uint32_t i, n;
int32_t *d = dst;
if (n_src == 0)
memset(dst, 0, n_samples * ops->n_channels * sizeof(int32_t));
else if (dst != src[0])
memcpy(dst, src[0], n_samples * ops->n_channels * sizeof(int32_t));
for (i = 1; i < n_src; i++) {
const int32_t *s = src[i];
for (n = 0; n < n_samples * ops->n_channels; n++)
d[n] = S24_32_MIX(d[n], s[n]);
}
}
void
mix_u24_32_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)
{
uint32_t i, n;
uint32_t *d = dst;
if (n_src == 0)
memset(dst, 0, n_samples * ops->n_channels * sizeof(uint32_t));
else if (dst != src[0])
memcpy(dst, src[0], n_samples * ops->n_channels * sizeof(uint32_t));
for (i = 1; i < n_src; i++) {
const uint32_t *s = src[i];
for (n = 0; n < n_samples * ops->n_channels; n++)
d[n] = U24_32_MIX(d[n], s[n]);
}
}
void
mix_f32_c(struct mix_ops *ops, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src[],
uint32_t n_src, uint32_t n_samples)