Fix cast-align.

This commit is contained in:
HiFiPhile 2023-09-19 16:32:49 +02:00
parent 9d0251f7a6
commit 6be7f354c2

View File

@ -631,64 +631,55 @@ static bool audiod_rx_done_cb(uint8_t rhport, audiod_function_t* audio, uint16_t
// Decoding according to 2.3.1.5 Audio Streams // Decoding according to 2.3.1.5 Audio Streams
// Helper function // Helper function
static inline uint8_t * audiod_interleaved_copy_bytes_fast_decode(uint16_t const nBytesToCopy, uint8_t * dst, uint8_t * dst_end, uint8_t * src, uint8_t const n_ff_used) static inline void * audiod_interleaved_copy_bytes_fast_decode(uint16_t const nBytesToCopy, void * dst, const void * dst_end, void * src, uint8_t const n_ff_used)
{ {
// Due to one FIFO contains 2 channels, data always aligned to (nBytesToCopy * 2) // Due to one FIFO contains 2 channels, data always aligned to (nBytesToCopy * 2)
uint16_t * dst16 = dst;
uint16_t * src16 = src;
const uint16_t * dst_end16 = dst_end;
uint32_t * dst32 = dst;
uint32_t * src32 = src;
const uint32_t * dst_end32 = dst_end;
switch (nBytesToCopy) if (nBytesToCopy == 1)
{ {
case 1: while(dst16 < dst_end16)
while((uint8_t *)dst < dst_end)
{ {
*(uint16_t*)dst = *(uint16_t*)src; *dst16++ = *src16++;
src += 2; src16 += n_ff_used - 1;
dst += 2;
src += 2 * (n_ff_used - 1);
} }
break; return src16;
}
case 2: else if (nBytesToCopy == 2)
while((uint8_t *)dst < dst_end)
{ {
*(uint32_t*)dst = *(uint32_t*)src; while(dst32 < dst_end32)
src += 4;
dst += 4;
src += 4 * (n_ff_used - 1);
}
break;
case 3:
while((uint8_t *)dst < dst_end)
{ {
*(uint16_t*)dst = *(uint16_t*)src; *dst32++ = *src32++;
src += 2; src32 += n_ff_used - 1;
dst += 2;
*(uint16_t*)dst = *(uint16_t*)src;
src += 2;
dst += 2;
*(uint16_t*)dst = *(uint16_t*)src;
src += 2;
dst += 2;
src += 6 * (n_ff_used - 1);
} }
break; return src32;
}
case 4: else if (nBytesToCopy == 3)
while((uint8_t *)dst < dst_end)
{ {
*(uint32_t*)dst++ = *(uint32_t*)src++; while(dst16 < dst_end16)
src += 4; {
dst += 4; *dst16++ = *src16++;
*(uint32_t*)dst++ = *(uint32_t*)src++; *dst16++ = *src16++;
src += 4; *dst16++ = *src16++;
dst += 4; src16 += 3 * (n_ff_used - 1);
src += 8 * (n_ff_used - 1);
} }
break; return src16;
}
else // nBytesToCopy == 4
{
while(dst32 < dst_end32)
{
*dst32++ = *src32++;
*dst32++ = *src32++;
src32 += 2 * (n_ff_used - 1);
}
return src32;
} }
return src;
} }
static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received) static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received)
@ -935,62 +926,55 @@ range [-1, +1)
* */ * */
// Helper function // Helper function
static inline uint8_t * audiod_interleaved_copy_bytes_fast_encode(uint16_t const nBytesToCopy, uint8_t * src, uint8_t * src_end, uint8_t * dst, uint8_t const n_ff_used) static inline void * audiod_interleaved_copy_bytes_fast_encode(uint16_t const nBytesToCopy, void * src, const void * src_end, void * dst, uint8_t const n_ff_used)
{ {
// Due to one FIFO contains 2 channels, data always aligned to (nBytesToCopy * 2) // Due to one FIFO contains 2 channels, data always aligned to (nBytesToCopy * 2)
switch (nBytesToCopy) uint16_t * dst16 = dst;
{ uint16_t * src16 = src;
case 1: const uint16_t * src_end16 = src_end;
while(src < src_end) uint32_t * dst32 = dst;
{ uint32_t * src32 = src;
*(uint16_t*)dst = *(uint16_t*)src; const uint32_t * src_end32 = src_end;
src += 2;
dst += 2;
dst += 2 * (n_ff_used - 1);
}
break;
case 2: if (nBytesToCopy == 1)
while(src < src_end)
{ {
*(uint32_t*)dst = *(uint32_t*)src; while(src16 < src_end16)
src += 4;
dst += 4;
dst += 4 * (n_ff_used - 1);
}
break;
case 3:
while(src < src_end)
{ {
*(uint16_t*)dst = *(uint16_t*)src; *dst16++ = *src16++;
src += 2; dst16 += n_ff_used - 1;
dst += 2;
*(uint16_t*)dst = *(uint16_t*)src;
src += 2;
dst += 2;
*(uint16_t*)dst = *(uint16_t*)src;
src += 2;
dst += 2;
dst += 6 * (n_ff_used - 1);
} }
break; return dst16;
}
case 4: else if (nBytesToCopy == 2)
while(src < src_end)
{ {
*(uint32_t*)dst++ = *(uint32_t*)src++; while(src32 < src_end32)
src += 4; {
dst += 4; *dst32++ = *src32++;
*(uint32_t*)dst++ = *(uint32_t*)src++; dst32 += n_ff_used - 1;
src += 4;
dst += 4;
dst += 8 * (n_ff_used - 1);
} }
break; return dst32;
}
else if (nBytesToCopy == 3)
{
while(src16 < src_end16)
{
*dst16++ = *src16++;
*dst16++ = *src16++;
*dst16++ = *src16++;
dst16 += 3 * (n_ff_used - 1);
}
return dst16;
}
else // nBytesToCopy == 4
{
while(src32 < src_end32)
{
*dst32++ = *src32++;
*dst32++ = *src32++;
dst32 += 2 * (n_ff_used - 1);
}
return dst32;
} }
return dst;
} }
static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audio) static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audio)