| | |
| | | #include "SDL_cpuinfo.h" |
| | | #include "SDL_assert.h" |
| | | |
| | | /* !!! FIXME: write NEON code. */ |
| | | #define HAVE_NEON_INTRINSICS 0 |
| | | /* !!! FIXME: disabled until we fix https://bugzilla.libsdl.org/show_bug.cgi?id=4186 */ |
| | | #if 0 /*def __ARM_NEON__*/ |
| | | #define HAVE_NEON_INTRINSICS 1 |
| | | #endif |
| | | |
| | | #ifdef __SSE2__ |
| | | #define HAVE_SSE2_INTRINSICS 1 |
| | |
| | | |
| | | #define DIVBY128 0.0078125f |
| | | #define DIVBY32768 0.000030517578125f |
| | | #define DIVBY2147483648 0.00000000046566128730773926 |
| | | #define DIVBY8388607 0.00000011920930376163766f |
| | | |
| | | |
| | | #if NEED_SCALAR_CONVERTER_FALLBACKS |
| | |
| | | LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32"); |
| | | |
| | | for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) { |
| | | *dst = (float) (((double) *src) * DIVBY2147483648); |
| | | *dst = ((float) (*src>>8)) * DIVBY8388607; |
| | | } |
| | | |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | |
| | | |
| | | for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample > 1.0f) { |
| | | if (sample >= 1.0f) { |
| | | *dst = 127; |
| | | } else if (sample < -1.0f) { |
| | | *dst = -127; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -128; |
| | | } else { |
| | | *dst = (Sint8)(sample * 127.0f); |
| | | } |
| | |
| | | |
| | | for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample > 1.0f) { |
| | | if (sample >= 1.0f) { |
| | | *dst = 255; |
| | | } else if (sample < -1.0f) { |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint8)((sample + 1.0f) * 127.0f); |
| | |
| | | |
| | | for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample > 1.0f) { |
| | | if (sample >= 1.0f) { |
| | | *dst = 32767; |
| | | } else if (sample < -1.0f) { |
| | | *dst = -32767; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -32768; |
| | | } else { |
| | | *dst = (Sint16)(sample * 32767.0f); |
| | | } |
| | |
| | | |
| | | for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample > 1.0f) { |
| | | *dst = 65534; |
| | | } else if (sample < -1.0f) { |
| | | if (sample >= 1.0f) { |
| | | *dst = 65535; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint16)((sample + 1.0f) * 32767.0f); |
| | |
| | | |
| | | for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample > 1.0f) { |
| | | if (sample >= 1.0f) { |
| | | *dst = 2147483647; |
| | | } else if (sample < -1.0f) { |
| | | *dst = -2147483647; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = (Sint32) -2147483648LL; |
| | | } else { |
| | | *dst = (Sint32)((double)sample * 2147483647.0); |
| | | *dst = ((Sint32)(sample * 8388607.0f)) << 8; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | #if defined(__GNUC__) && (__GNUC__ < 4) |
| | | /* these were added as of gcc-4.0: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19418 */ |
| | | static inline __m128 _mm_castsi128_ps(__m128i __A) { |
| | | return (__m128) __A; |
| | | } |
| | | static inline __m128i _mm_castps_si128(__m128 __A) { |
| | | return (__m128i) __A; |
| | | } |
| | | #endif |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_S32_to_F32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (Sint32); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = (float) (((double) *src) * DIVBY2147483648); |
| | | *dst = ((float) (*src>>8)) * DIVBY8388607; |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | |
| | | |
| | | { |
| | | /* Aligned! Do SSE blocks as long as we have 16 bytes available. */ |
| | | const __m128d divby2147483648 = _mm_set1_pd(DIVBY2147483648); |
| | | const __m128 divby8388607 = _mm_set1_ps(DIVBY8388607); |
| | | const __m128i *mmsrc = (const __m128i *) src; |
| | | while (i >= 4) { /* 4 * sint32 */ |
| | | const __m128i ints = _mm_load_si128(mmsrc); |
| | | /* bitshift the whole register over, so _mm_cvtepi32_pd can read the top ints in the bottom of the vector. */ |
| | | const __m128d doubles1 = _mm_mul_pd(_mm_cvtepi32_pd(_mm_srli_si128(ints, 8)), divby2147483648); |
| | | const __m128d doubles2 = _mm_mul_pd(_mm_cvtepi32_pd(ints), divby2147483648); |
| | | /* convert to float32, bitshift/or to get these into a vector to store. */ |
| | | _mm_store_ps(dst, _mm_castsi128_ps(_mm_or_si128(_mm_slli_si128(_mm_castps_si128(_mm_cvtpd_ps(doubles1)), 8), _mm_castps_si128(_mm_cvtpd_ps(doubles2))))); |
| | | /* shift out lowest bits so int fits in a float32. Small precision loss, but much faster. */ |
| | | _mm_store_ps(dst, _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_load_si128(mmsrc), 8)), divby8388607)); |
| | | i -= 4; mmsrc++; dst += 4; |
| | | } |
| | | src = (const Sint32 *) mmsrc; |
| | |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (float) (((double) *src) * DIVBY2147483648); |
| | | *dst = ((float) (*src>>8)) * DIVBY8388607; |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = (Sint8) (*src * 127.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 127; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -128; |
| | | } else { |
| | | *dst = (Sint8)(sample * 127.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do SSE blocks as long as we have 16 bytes available. */ |
| | | const __m128 one = _mm_set1_ps(1.0f); |
| | | const __m128 negone = _mm_set1_ps(-1.0f); |
| | | const __m128 mulby127 = _mm_set1_ps(127.0f); |
| | | __m128i *mmdst = (__m128i *) dst; |
| | | while (i >= 16) { /* 16 * float32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+4), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints3 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+8), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints4 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+12), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+4)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints3 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+8)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints4 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+12)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | _mm_store_si128(mmdst, _mm_packs_epi16(_mm_packs_epi32(ints1, ints2), _mm_packs_epi32(ints3, ints4))); /* pack down, store out. */ |
| | | i -= 16; src += 16; mmdst++; |
| | | } |
| | |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (Sint8) (*src * 127.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 127; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -128; |
| | | } else { |
| | | *dst = (Sint8)(sample * 127.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = (Uint8) ((*src + 1.0f) * 127.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 255; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint8)((sample + 1.0f) * 127.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do SSE blocks as long as we have 16 bytes available. */ |
| | | const __m128 add1 = _mm_set1_ps(1.0f); |
| | | const __m128 one = _mm_set1_ps(1.0f); |
| | | const __m128 negone = _mm_set1_ps(-1.0f); |
| | | const __m128 mulby127 = _mm_set1_ps(127.0f); |
| | | __m128i *mmdst = (__m128i *) dst; |
| | | while (i >= 16) { /* 16 * float32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src), add1), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src+4), add1), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints3 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src+8), add1), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints4 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src+12), add1), mulby127)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src)), one), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+4)), one), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints3 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+8)), one), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints4 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+12)), one), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | _mm_store_si128(mmdst, _mm_packus_epi16(_mm_packs_epi32(ints1, ints2), _mm_packs_epi32(ints3, ints4))); /* pack down, store out. */ |
| | | i -= 16; src += 16; mmdst++; |
| | | } |
| | |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (Uint8) ((*src + 1.0f) * 127.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 255; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint8)((sample + 1.0f) * 127.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = (Sint16) (*src * 32767.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 32767; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -32768; |
| | | } else { |
| | | *dst = (Sint16)(sample * 32767.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do SSE blocks as long as we have 16 bytes available. */ |
| | | const __m128 one = _mm_set1_ps(1.0f); |
| | | const __m128 negone = _mm_set1_ps(-1.0f); |
| | | const __m128 mulby32767 = _mm_set1_ps(32767.0f); |
| | | __m128i *mmdst = (__m128i *) dst; |
| | | while (i >= 8) { /* 8 * float32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src), mulby32767)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+4), mulby32767)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src)), one), mulby32767)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+4)), one), mulby32767)); /* load 4 floats, clamp, convert to sint32 */ |
| | | _mm_store_si128(mmdst, _mm_packs_epi32(ints1, ints2)); /* pack to sint16, store out. */ |
| | | i -= 8; src += 8; mmdst++; |
| | | } |
| | |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (Sint16) (*src * 32767.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 32767; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -32768; |
| | | } else { |
| | | *dst = (Sint16)(sample * 32767.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = (Uint16) ((*src + 1.0f) * 32767.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 65535; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint16)((sample + 1.0f) * 32767.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | |
| | | though it looks like dark magic. */ |
| | | const __m128 mulby32767 = _mm_set1_ps(32767.0f); |
| | | const __m128i topbit = _mm_set1_epi16(-32768); |
| | | const __m128 one = _mm_set1_ps(1.0f); |
| | | const __m128 negone = _mm_set1_ps(-1.0f); |
| | | __m128i *mmdst = (__m128i *) dst; |
| | | while (i >= 8) { /* 8 * float32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src), mulby32767)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+4), mulby32767)); /* load 4 floats, convert to sint32 */ |
| | | const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src)), one), mulby32767)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src+4)), one), mulby32767)); /* load 4 floats, clamp, convert to sint32 */ |
| | | _mm_store_si128(mmdst, _mm_xor_si128(_mm_packs_epi32(ints1, ints2), topbit)); /* pack to sint16, xor top bit, store out. */ |
| | | i -= 8; src += 8; mmdst++; |
| | | } |
| | |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (Uint16) ((*src + 1.0f) * 32767.0f); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 65535; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint16)((sample + 1.0f) * 32767.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = (Sint32) (((double) *src) * 2147483647.0); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 2147483647; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = (Sint32) -2147483648LL; |
| | | } else { |
| | | *dst = ((Sint32)(sample * 8388607.0f)) << 8; |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | |
| | | |
| | | { |
| | | /* Aligned! Do SSE blocks as long as we have 16 bytes available. */ |
| | | const __m128d mulby2147483647 = _mm_set1_pd(2147483647.0); |
| | | const __m128 one = _mm_set1_ps(1.0f); |
| | | const __m128 negone = _mm_set1_ps(-1.0f); |
| | | const __m128 mulby8388607 = _mm_set1_ps(8388607.0f); |
| | | __m128i *mmdst = (__m128i *) dst; |
| | | while (i >= 4) { /* 4 * float32 */ |
| | | const __m128 floats = _mm_load_ps(src); |
| | | /* bitshift the whole register over, so _mm_cvtps_pd can read the top floats in the bottom of the vector. */ |
| | | const __m128d doubles1 = _mm_mul_pd(_mm_cvtps_pd(_mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(floats), 8))), mulby2147483647); |
| | | const __m128d doubles2 = _mm_mul_pd(_mm_cvtps_pd(floats), mulby2147483647); |
| | | _mm_store_si128(mmdst, _mm_or_si128(_mm_slli_si128(_mm_cvtpd_epi32(doubles1), 8), _mm_cvtpd_epi32(doubles2))); |
| | | _mm_store_si128(mmdst, _mm_slli_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_min_ps(_mm_max_ps(negone, _mm_load_ps(src)), one), mulby8388607)), 8)); /* load 4 floats, clamp, convert to sint32 */ |
| | | i -= 4; src += 4; mmdst++; |
| | | } |
| | | dst = (Sint32 *) mmdst; |
| | |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (Sint32) (((double) *src) * 2147483647.0); |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 2147483647; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = (Sint32) -2147483648LL; |
| | | } else { |
| | | *dst = ((Sint32)(sample * 8388607.0f)) << 8; |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | #endif |
| | | |
| | | |
| | | #if HAVE_NEON_INTRINSICS |
| | | static void SDLCALL |
| | | SDL_Convert_S8_to_F32_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1; |
| | | float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */ |
| | | for (i = cvt->len_cvt; i && (((size_t) (dst-15)) & 15); --i, --src, --dst) { |
| | | *dst = ((float) *src) * DIVBY128; |
| | | } |
| | | |
| | | src -= 15; dst -= 15; /* adjust to read NEON blocks from the start. */ |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const int8_t *mmsrc = (const int8_t *) src; |
| | | const float32x4_t divby128 = vdupq_n_f32(DIVBY128); |
| | | while (i >= 16) { /* 16 * 8-bit */ |
| | | const int8x16_t bytes = vld1q_s8(mmsrc); /* get 16 sint8 into a NEON register. */ |
| | | const int16x8_t int16hi = vmovl_s8(vget_high_s8(bytes)); /* convert top 8 bytes to 8 int16 */ |
| | | const int16x8_t int16lo = vmovl_s8(vget_low_s8(bytes)); /* convert bottom 8 bytes to 8 int16 */ |
| | | /* split int16 to two int32, then convert to float, then multiply to normalize, store. */ |
| | | vst1q_f32(dst, vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(int16hi))), divby128)); |
| | | vst1q_f32(dst+4, vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(int16hi))), divby128)); |
| | | vst1q_f32(dst+8, vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(int16lo))), divby128)); |
| | | vst1q_f32(dst+12, vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(int16lo))), divby128)); |
| | | i -= 16; mmsrc -= 16; dst -= 16; |
| | | } |
| | | |
| | | src = (const Sint8 *) mmsrc; |
| | | } |
| | | |
| | | src += 15; dst += 15; /* adjust for any scalar finishing. */ |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = ((float) *src) * DIVBY128; |
| | | i--; src--; dst--; |
| | | } |
| | | |
| | | cvt->len_cvt *= 4; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_U8_to_F32_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1; |
| | | float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */ |
| | | for (i = cvt->len_cvt; i && (((size_t) (dst-15)) & 15); --i, --src, --dst) { |
| | | *dst = (((float) *src) * DIVBY128) - 1.0f; |
| | | } |
| | | |
| | | src -= 15; dst -= 15; /* adjust to read NEON blocks from the start. */ |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const uint8_t *mmsrc = (const uint8_t *) src; |
| | | const float32x4_t divby128 = vdupq_n_f32(DIVBY128); |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | while (i >= 16) { /* 16 * 8-bit */ |
| | | const uint8x16_t bytes = vld1q_u8(mmsrc); /* get 16 uint8 into a NEON register. */ |
| | | const uint16x8_t uint16hi = vmovl_u8(vget_high_u8(bytes)); /* convert top 8 bytes to 8 uint16 */ |
| | | const uint16x8_t uint16lo = vmovl_u8(vget_low_u8(bytes)); /* convert bottom 8 bytes to 8 uint16 */ |
| | | /* split uint16 to two uint32, then convert to float, then multiply to normalize, subtract to adjust for sign, store. */ |
| | | vst1q_f32(dst, vmlsq_f32(vcvtq_f32_u32(vmovl_u16(vget_high_u16(uint16hi))), divby128, one)); |
| | | vst1q_f32(dst+4, vmlsq_f32(vcvtq_f32_u32(vmovl_u16(vget_low_u16(uint16hi))), divby128, one)); |
| | | vst1q_f32(dst+8, vmlsq_f32(vcvtq_f32_u32(vmovl_u16(vget_high_u16(uint16lo))), divby128, one)); |
| | | vst1q_f32(dst+12, vmlsq_f32(vcvtq_f32_u32(vmovl_u16(vget_low_u16(uint16lo))), divby128, one)); |
| | | i -= 16; mmsrc -= 16; dst -= 16; |
| | | } |
| | | |
| | | src = (const Uint8 *) mmsrc; |
| | | } |
| | | |
| | | src += 15; dst += 15; /* adjust for any scalar finishing. */ |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (((float) *src) * DIVBY128) - 1.0f; |
| | | i--; src--; dst--; |
| | | } |
| | | |
| | | cvt->len_cvt *= 4; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_S16_to_F32_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1; |
| | | float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */ |
| | | for (i = cvt->len_cvt / sizeof (Sint16); i && (((size_t) (dst-7)) & 15); --i, --src, --dst) { |
| | | *dst = ((float) *src) * DIVBY32768; |
| | | } |
| | | |
| | | src -= 7; dst -= 7; /* adjust to read NEON blocks from the start. */ |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t divby32768 = vdupq_n_f32(DIVBY32768); |
| | | while (i >= 8) { /* 8 * 16-bit */ |
| | | const int16x8_t ints = vld1q_s16((int16_t const *) src); /* get 8 sint16 into a NEON register. */ |
| | | /* split int16 to two int32, then convert to float, then multiply to normalize, store. */ |
| | | vst1q_f32(dst, vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_low_s16(ints))), divby32768)); |
| | | vst1q_f32(dst+4, vmulq_f32(vcvtq_f32_s32(vmovl_s16(vget_high_s16(ints))), divby32768)); |
| | | i -= 8; src -= 8; dst -= 8; |
| | | } |
| | | } |
| | | |
| | | src += 7; dst += 7; /* adjust for any scalar finishing. */ |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = ((float) *src) * DIVBY32768; |
| | | i--; src--; dst--; |
| | | } |
| | | |
| | | cvt->len_cvt *= 2; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_U16_to_F32_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const Uint16 *src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1; |
| | | float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_U16", "AUDIO_F32 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */ |
| | | for (i = cvt->len_cvt / sizeof (Sint16); i && (((size_t) (dst-7)) & 15); --i, --src, --dst) { |
| | | *dst = (((float) *src) * DIVBY32768) - 1.0f; |
| | | } |
| | | |
| | | src -= 7; dst -= 7; /* adjust to read NEON blocks from the start. */ |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t divby32768 = vdupq_n_f32(DIVBY32768); |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | while (i >= 8) { /* 8 * 16-bit */ |
| | | const uint16x8_t uints = vld1q_u16((uint16_t const *) src); /* get 8 uint16 into a NEON register. */ |
| | | /* split uint16 to two int32, then convert to float, then multiply to normalize, subtract for sign, store. */ |
| | | vst1q_f32(dst, vmlsq_f32(one, vcvtq_f32_u32(vmovl_u16(vget_low_u16(uints))), divby32768)); |
| | | vst1q_f32(dst+4, vmlsq_f32(one, vcvtq_f32_u32(vmovl_u16(vget_high_u16(uints))), divby32768)); |
| | | i -= 8; src -= 8; dst -= 8; |
| | | } |
| | | } |
| | | |
| | | src += 7; dst += 7; /* adjust for any scalar finishing. */ |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = (((float) *src) * DIVBY32768) - 1.0f; |
| | | i--; src--; dst--; |
| | | } |
| | | |
| | | cvt->len_cvt *= 2; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_S32_to_F32_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const Sint32 *src = (const Sint32 *) cvt->buf; |
| | | float *dst = (float *) cvt->buf; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (Sint32); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | *dst = ((float) (*src>>8)) * DIVBY8388607; |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | SDL_assert(!i || ((((size_t) src) & 15) == 0)); |
| | | |
| | | { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t divby8388607 = vdupq_n_f32(DIVBY8388607); |
| | | const int32_t *mmsrc = (const int32_t *) src; |
| | | while (i >= 4) { /* 4 * sint32 */ |
| | | /* shift out lowest bits so int fits in a float32. Small precision loss, but much faster. */ |
| | | vst1q_f32(dst, vmulq_f32(vcvtq_f32_s32(vshrq_n_s32(vld1q_s32(mmsrc), 8)), divby8388607)); |
| | | i -= 4; mmsrc += 4; dst += 4; |
| | | } |
| | | src = (const Sint32 *) mmsrc; |
| | | } |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | *dst = ((float) (*src>>8)) * DIVBY8388607; |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_F32_to_S8_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const float *src = (const float *) cvt->buf; |
| | | Sint8 *dst = (Sint8 *) cvt->buf; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 127; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -128; |
| | | } else { |
| | | *dst = (Sint8)(sample * 127.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | const float32x4_t negone = vdupq_n_f32(-1.0f); |
| | | const float32x4_t mulby127 = vdupq_n_f32(127.0f); |
| | | int8_t *mmdst = (int8_t *) dst; |
| | | while (i >= 16) { /* 16 * float32 */ |
| | | const int32x4_t ints1 = vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const int32x4_t ints2 = vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+4)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const int32x4_t ints3 = vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+8)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const int32x4_t ints4 = vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+12)), one), mulby127)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const int8x8_t i8lo = vmovn_s16(vcombine_s16(vmovn_s32(ints1), vmovn_s32(ints2))); /* narrow to sint16, combine, narrow to sint8 */ |
| | | const int8x8_t i8hi = vmovn_s16(vcombine_s16(vmovn_s32(ints3), vmovn_s32(ints4))); /* narrow to sint16, combine, narrow to sint8 */ |
| | | vst1q_s8(mmdst, vcombine_s8(i8lo, i8hi)); /* combine to int8x16_t, store out */ |
| | | i -= 16; src += 16; mmdst += 16; |
| | | } |
| | | dst = (Sint8 *) mmdst; |
| | | } |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 127; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -128; |
| | | } else { |
| | | *dst = (Sint8)(sample * 127.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | | cvt->len_cvt /= 4; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_S8); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_F32_to_U8_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const float *src = (const float *) cvt->buf; |
| | | Uint8 *dst = (Uint8 *) cvt->buf; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 255; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint8)((sample + 1.0f) * 127.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | const float32x4_t negone = vdupq_n_f32(-1.0f); |
| | | const float32x4_t mulby127 = vdupq_n_f32(127.0f); |
| | | uint8_t *mmdst = (uint8_t *) dst; |
| | | while (i >= 16) { /* 16 * float32 */ |
| | | const uint32x4_t uints1 = vcvtq_u32_f32(vmulq_f32(vaddq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src)), one), one), mulby127)); /* load 4 floats, clamp, convert to uint32 */ |
| | | const uint32x4_t uints2 = vcvtq_u32_f32(vmulq_f32(vaddq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+4)), one), one), mulby127)); /* load 4 floats, clamp, convert to uint32 */ |
| | | const uint32x4_t uints3 = vcvtq_u32_f32(vmulq_f32(vaddq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+8)), one), one), mulby127)); /* load 4 floats, clamp, convert to uint32 */ |
| | | const uint32x4_t uints4 = vcvtq_u32_f32(vmulq_f32(vaddq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+12)), one), one), mulby127)); /* load 4 floats, clamp, convert to uint32 */ |
| | | const uint8x8_t ui8lo = vmovn_u16(vcombine_u16(vmovn_u32(uints1), vmovn_u32(uints2))); /* narrow to uint16, combine, narrow to uint8 */ |
| | | const uint8x8_t ui8hi = vmovn_u16(vcombine_u16(vmovn_u32(uints3), vmovn_u32(uints4))); /* narrow to uint16, combine, narrow to uint8 */ |
| | | vst1q_u8(mmdst, vcombine_u8(ui8lo, ui8hi)); /* combine to uint8x16_t, store out */ |
| | | i -= 16; src += 16; mmdst += 16; |
| | | } |
| | | |
| | | dst = (Uint8 *) mmdst; |
| | | } |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 255; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint8)((sample + 1.0f) * 127.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | | cvt->len_cvt /= 4; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_U8); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_F32_to_S16_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const float *src = (const float *) cvt->buf; |
| | | Sint16 *dst = (Sint16 *) cvt->buf; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 32767; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -32768; |
| | | } else { |
| | | *dst = (Sint16)(sample * 32767.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | const float32x4_t negone = vdupq_n_f32(-1.0f); |
| | | const float32x4_t mulby32767 = vdupq_n_f32(32767.0f); |
| | | int16_t *mmdst = (int16_t *) dst; |
| | | while (i >= 8) { /* 8 * float32 */ |
| | | const int32x4_t ints1 = vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src)), one), mulby32767)); /* load 4 floats, clamp, convert to sint32 */ |
| | | const int32x4_t ints2 = vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+4)), one), mulby32767)); /* load 4 floats, clamp, convert to sint32 */ |
| | | vst1q_s16(mmdst, vcombine_s16(vmovn_s32(ints1), vmovn_s32(ints2))); /* narrow to sint16, combine, store out. */ |
| | | i -= 8; src += 8; mmdst += 8; |
| | | } |
| | | dst = (Sint16 *) mmdst; |
| | | } |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 32767; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -32768; |
| | | } else { |
| | | *dst = (Sint16)(sample * 32767.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | | cvt->len_cvt /= 2; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_F32_to_U16_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const float *src = (const float *) cvt->buf; |
| | | Uint16 *dst = (Uint16 *) cvt->buf; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 65535; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint16)((sample + 1.0f) * 32767.0f); |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | |
| | | /* Make sure src is aligned too. */ |
| | | if ((((size_t) src) & 15) == 0) { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | const float32x4_t negone = vdupq_n_f32(-1.0f); |
| | | const float32x4_t mulby32767 = vdupq_n_f32(32767.0f); |
| | | uint16_t *mmdst = (uint16_t *) dst; |
| | | while (i >= 8) { /* 8 * float32 */ |
| | | const uint32x4_t uints1 = vcvtq_u32_f32(vmulq_f32(vaddq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src)), one), one), mulby32767)); /* load 4 floats, clamp, convert to uint32 */ |
| | | const uint32x4_t uints2 = vcvtq_u32_f32(vmulq_f32(vaddq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src+4)), one), one), mulby32767)); /* load 4 floats, clamp, convert to uint32 */ |
| | | vst1q_u16(mmdst, vcombine_u16(vmovn_u32(uints1), vmovn_u32(uints2))); /* narrow to uint16, combine, store out. */ |
| | | i -= 8; src += 8; mmdst += 8; |
| | | } |
| | | dst = (Uint16 *) mmdst; |
| | | } |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 65535; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = 0; |
| | | } else { |
| | | *dst = (Uint16)((sample + 1.0f) * 32767.0f); |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | | cvt->len_cvt /= 2; |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_U16SYS); |
| | | } |
| | | } |
| | | |
| | | static void SDLCALL |
| | | SDL_Convert_F32_to_S32_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format) |
| | | { |
| | | const float *src = (const float *) cvt->buf; |
| | | Sint32 *dst = (Sint32 *) cvt->buf; |
| | | int i; |
| | | |
| | | LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32 (using NEON)"); |
| | | |
| | | /* Get dst aligned to 16 bytes */ |
| | | for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 2147483647; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -2147483648; |
| | | } else { |
| | | *dst = ((Sint32)(sample * 8388607.0f)) << 8; |
| | | } |
| | | } |
| | | |
| | | SDL_assert(!i || ((((size_t) dst) & 15) == 0)); |
| | | SDL_assert(!i || ((((size_t) src) & 15) == 0)); |
| | | |
| | | { |
| | | /* Aligned! Do NEON blocks as long as we have 16 bytes available. */ |
| | | const float32x4_t one = vdupq_n_f32(1.0f); |
| | | const float32x4_t negone = vdupq_n_f32(-1.0f); |
| | | const float32x4_t mulby8388607 = vdupq_n_f32(8388607.0f); |
| | | int32_t *mmdst = (int32_t *) dst; |
| | | while (i >= 4) { /* 4 * float32 */ |
| | | vst1q_s32(mmdst, vshlq_n_s32(vcvtq_s32_f32(vmulq_f32(vminq_f32(vmaxq_f32(negone, vld1q_f32(src)), one), mulby8388607)), 8)); |
| | | i -= 4; src += 4; mmdst += 4; |
| | | } |
| | | dst = (Sint32 *) mmdst; |
| | | } |
| | | |
| | | /* Finish off any leftovers with scalar operations. */ |
| | | while (i) { |
| | | const float sample = *src; |
| | | if (sample >= 1.0f) { |
| | | *dst = 2147483647; |
| | | } else if (sample <= -1.0f) { |
| | | *dst = -2147483648; |
| | | } else { |
| | | *dst = ((Sint32)(sample * 8388607.0f)) << 8; |
| | | } |
| | | i--; src++; dst++; |
| | | } |
| | | |
| | | if (cvt->filters[++cvt->filter_index]) { |
| | | cvt->filters[cvt->filter_index](cvt, AUDIO_S32SYS); |
| | | } |
| | | } |
| | | #endif |
| | | |
| | | |
| | | |
| | | void SDL_ChooseAudioConverters(void) |
| | |
| | | } |
| | | #endif |
| | | |
| | | #if HAVE_NEON_INTRINSICS |
| | | if (SDL_HasNEON()) { |
| | | SET_CONVERTER_FUNCS(NEON); |
| | | return; |
| | | } |
| | | #endif |
| | | |
| | | #if NEED_SCALAR_CONVERTER_FALLBACKS |
| | | SET_CONVERTER_FUNCS(Scalar); |
| | | #endif |