void memcpy_to_i16_from_p24(int16_t *dst, const uint8_t *src, size_t count)
{
while (count--) {
-#ifdef HAVE_BIG_ENDIAN
+#if HAVE_BIG_ENDIAN
*dst++ = src[1] | (src[0] << 8);
#else
*dst++ = src[1] | (src[2] << 8);
}
}
+void memcpy_to_i32_from_p24(int32_t *dst, const uint8_t *src, size_t count)
+{
+ while (count--) {
+#if HAVE_BIG_ENDIAN
+ *dst++ = (src[2] << 8) | (src[1] << 16) | (src[0] << 24);
+#else
+ *dst++ = (src[0] << 8) | (src[1] << 16) | (src[2] << 24);
+#endif
+ src += 3;
+ }
+}
+
void memcpy_to_p24_from_i16(uint8_t *dst, const int16_t *src, size_t count)
{
while (count--) {
-#ifdef HAVE_BIG_ENDIAN
+#if HAVE_BIG_ENDIAN
*dst++ = *src >> 8;
*dst++ = *src++;
*dst++ = 0;
while (count--) {
int32_t ival = clamp24_from_float(*src++);
-#ifdef HAVE_BIG_ENDIAN
+#if HAVE_BIG_ENDIAN
*dst++ = ival >> 16;
*dst++ = ival >> 8;
*dst++ = ival;
while (count--) {
int32_t ival = clamp24_from_q8_23(*src++);
-#ifdef HAVE_BIG_ENDIAN
+#if HAVE_BIG_ENDIAN
+ *dst++ = ival >> 16;
+ *dst++ = ival >> 8;
+ *dst++ = ival;
+#else
+ *dst++ = ival;
+ *dst++ = ival >> 8;
+ *dst++ = ival >> 16;
+#endif
+ }
+}
+
+void memcpy_to_p24_from_i32(uint8_t *dst, const int32_t *src, size_t count)
+{
+ while (count--) {
+ int32_t ival = *src++ >> 8;
+
+#if HAVE_BIG_ENDIAN
*dst++ = ival >> 16;
*dst++ = ival >> 8;
*dst++ = ival;
void memcpy_to_q8_23_from_p24(int32_t *dst, const uint8_t *src, size_t count)
{
while (count--) {
-#ifdef HAVE_BIG_ENDIAN
+#if HAVE_BIG_ENDIAN
*dst++ = (int8_t)src[0] << 16 | src[1] << 8 | src[2];
#else
*dst++ = (int8_t)src[2] << 16 | src[1] << 8 | src[0];
}
}
+void downmix_to_mono_float_from_stereo_float(float *dst, const float *src, size_t frames)
+{
+ while (frames--) {
+ *dst++ = (src[0] + src[1]) * 0.5;
+ src += 2;
+ }
+}
+
+void upmix_to_stereo_float_from_mono_float(float *dst, const float *src, size_t frames)
+{
+ while (frames--) {
+ float temp = *src++;
+ dst[0] = temp;
+ dst[1] = temp;
+ dst += 2;
+ }
+}
+
size_t nonZeroMono32(const int32_t *samples, size_t count)
{
size_t nonZero = 0;
#define copy_frame_by_mask(dst, dmask, src, smask, count, zero) \
{ \
uint32_t bit, ormask; \
- while (count--) { \
- ormask = dmask | smask; \
+ while ((count)--) { \
+ ormask = (dmask) | (smask); \
while (ormask) { \
bit = ormask & -ormask; /* get lowest bit */ \
ormask ^= bit; /* remove lowest bit */ \
- if (dmask & bit) { \
- *dst++ = smask & bit ? *src++ : zero; \
+ if ((dmask) & bit) { \
+ *(dst)++ = (smask) & bit ? *(src)++ : (zero); \
} else { /* source channel only */ \
- ++src; \
+ ++(src); \
} \
} \
} \
{ \
unsigned i; \
int index; \
- while (count--) { \
- for (i = 0; i < dst_channels; ++i) { \
- index = idxary[i]; \
- *dst++ = index < 0 ? zero : src[index]; \
+ while ((count)--) { \
+ for (i = 0; i < (dst_channels); ++i) { \
+ index = (idxary)[i]; \
+ *(dst)++ = index < 0 ? (zero) : (src)[index]; \
} \
- src += src_channels; \
+ (src) += (src_channels); \
} \
}
}
return dst_idx;
}
+
+size_t memcpy_by_index_array_initialization_dst_index(int8_t *idxary, size_t idxcount,
+ uint32_t dst_mask, uint32_t src_mask) {
+ size_t src_idx, dst_idx;
+ size_t dst_count = __builtin_popcount(dst_mask);
+ size_t src_count = __builtin_popcount(src_mask);
+ if (idxcount == 0) {
+ return dst_count;
+ }
+ if (dst_count > idxcount) {
+ dst_count = idxcount;
+ }
+ for (src_idx = 0, dst_idx = 0; dst_idx < dst_count; ++src_idx) {
+ if (dst_mask & 1) {
+ idxary[dst_idx++] = src_idx < src_count ? (signed)src_idx : -1;
+ }
+ dst_mask >>= 1;
+ }
+ return dst_idx;
+}