audioconvert: avoid unaligned writes and left shift of neagtives

See #3572
This commit is contained in:
Wim Taymans 2023-10-15 21:11:54 +02:00
parent 20b336b1d7
commit cc109843e5
2 changed files with 12 additions and 7 deletions

View file

@ -692,12 +692,17 @@ conv_f32d_to_s32_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const voi
int32_t *d = dst[0];
uint32_t i = 0, n_channels = conv->n_channels;
for(; i + 3 < n_channels; i += 4)
conv_f32d_to_s32_4s_avx2(conv, &d[i], &src[i], n_channels, n_samples);
for(; i + 1 < n_channels; i += 2)
conv_f32d_to_s32_2s_avx2(conv, &d[i], &src[i], n_channels, n_samples);
for(; i < n_channels; i++)
conv_f32d_to_s32_1s_avx2(conv, &d[i], &src[i], n_channels, n_samples);
if ((n_channels & 3) == 0) {
for(; i + 3 < n_channels; i += 4)
conv_f32d_to_s32_4s_avx2(conv, &d[i], &src[i], n_channels, n_samples);
}
else if ((n_channels & 1) == 0) {
for(; i + 1 < n_channels; i += 2)
conv_f32d_to_s32_2s_avx2(conv, &d[i], &src[i], n_channels, n_samples);
} else {
for(; i < n_channels; i++)
conv_f32d_to_s32_1s_avx2(conv, &d[i], &src[i], n_channels, n_samples);
}
}
static void

View file

@ -43,7 +43,7 @@ static inline uint24_t u32_to_u24(uint32_t src)
static inline int32_t s24_to_s32(int24_t src)
{
return ((int32_t)src.v1 << 16) | ((uint32_t)src.v2 << 8) | (uint32_t)src.v3;
return ((uint32_t)((int32_t)src.v1 & 0xFFFF) << 16) | ((uint32_t)src.v2 << 8) | (uint32_t)src.v3;
}
#define S32_TO_S24(s) (int24_t) { .v1 = (int8_t)(((int32_t)s) >> 16), \