| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * audio conversion | ||
| 3 | * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * audio conversion | ||
| 25 | * @author Michael Niedermayer <michaelni@gmx.at> | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <math.h> | ||
| 29 | |||
| 30 | #include "libavutil/avassert.h" | ||
| 31 | #include "libavutil/internal.h" | ||
| 32 | #include "libavutil/mem.h" | ||
| 33 | #include "libavutil/samplefmt.h" | ||
| 34 | #include "audioconvert.h" | ||
| 35 | |||
| 36 | |||
| 37 | #define CONV_FUNC_NAME(dst_fmt, src_fmt) conv_ ## src_fmt ## _to_ ## dst_fmt | ||
| 38 | |||
| 39 | //FIXME rounding ? | ||
| 40 | #define CONV_FUNC(ofmt, otype, ifmt, expr)\ | ||
| 41 | static void CONV_FUNC_NAME(ofmt, ifmt)(DSDContext *st, uint8_t *po, const uint8_t *pi, int is, int os, uint8_t *end)\ | ||
| 42 | {\ | ||
| 43 | uint8_t *end2 = end - 3*os;\ | ||
| 44 | while(po < end2){\ | ||
| 45 | *(otype*)po = expr; pi += is; po += os;\ | ||
| 46 | *(otype*)po = expr; pi += is; po += os;\ | ||
| 47 | *(otype*)po = expr; pi += is; po += os;\ | ||
| 48 | *(otype*)po = expr; pi += is; po += os;\ | ||
| 49 | }\ | ||
| 50 | while(po < end){\ | ||
| 51 | *(otype*)po = expr; pi += is; po += os;\ | ||
| 52 | }\ | ||
| 53 | } | ||
| 54 | |||
| 55 | //FIXME put things below under ifdefs so we do not waste space for cases no codec will need | ||
| 56 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_U8 , *(const uint8_t*)pi) | |
| 57 |
4/4✓ Branch 0 taken 1370593 times.
✓ Branch 1 taken 3393 times.
✓ Branch 2 taken 689 times.
✓ Branch 3 taken 3393 times.
|
1374675 | CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80U)<<8) |
| 58 |
3/4✓ Branch 0 taken 23040 times.
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 90 times.
|
23130 | CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80U)<<24) |
| 59 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8 , (uint64_t)((*(const uint8_t*)pi - 0x80U))<<56) | |
| 60 |
3/4✓ Branch 0 taken 22050 times.
✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 88 times.
|
22138 | CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0f/ (1<<7))) |
| 61 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7))) | |
| 62 |
4/4✓ Branch 0 taken 2497572 times.
✓ Branch 1 taken 996 times.
✓ Branch 2 taken 236 times.
✓ Branch 3 taken 996 times.
|
2498804 | CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S16, (*(const int16_t*)pi>>8) + 0x80) |
| 63 |
4/4✓ Branch 0 taken 117646321 times.
✓ Branch 1 taken 180659 times.
✓ Branch 2 taken 35308 times.
✓ Branch 3 taken 180659 times.
|
117862288 | CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi) |
| 64 |
4/4✓ Branch 0 taken 2561572 times.
✓ Branch 1 taken 3500 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 3500 times.
|
2565086 | CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi * (1 << 16)) |
| 65 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16, (uint64_t)(*(const int16_t*)pi)<<48) | |
| 66 |
4/4✓ Branch 0 taken 4587505 times.
✓ Branch 1 taken 7468 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 7468 times.
|
4595025 | CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0f/ (1<<15))) |
| 67 |
3/4✓ Branch 0 taken 1224084 times.
✓ Branch 1 taken 2102 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2102 times.
|
1226186 | CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15))) |
| 68 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S32, (*(const int32_t*)pi>>24) + 0x80) | |
| 69 |
4/4✓ Branch 0 taken 9104288 times.
✓ Branch 1 taken 33037 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 33037 times.
|
9138111 | CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi>>16) |
| 70 |
4/4✓ Branch 0 taken 12889668 times.
✓ Branch 1 taken 24971 times.
✓ Branch 2 taken 78 times.
✓ Branch 3 taken 24971 times.
|
12914717 | CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi) |
| 71 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32, (uint64_t)(*(const int32_t*)pi)<<32) | |
| 72 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0f/ (1U<<31))) | |
| 73 |
4/4✓ Branch 0 taken 671998 times.
✓ Branch 1 taken 584 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 584 times.
|
672586 | CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31))) |
| 74 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S64, (*(const int64_t*)pi>>56) + 0x80) | |
| 75 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S64, *(const int64_t*)pi>>48) | |
| 76 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S64, *(const int64_t*)pi>>32) | |
| 77 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S64, *(const int64_t*)pi) | |
| 78 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S64, *(const int64_t*)pi*(1.0f/ (UINT64_C(1)<<63))) | |
| 79 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S64, *(const int64_t*)pi*(1.0 / (UINT64_C(1)<<63))) | |
| 80 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80)) | |
| 81 |
4/4✓ Branch 0 taken 40252182 times.
✓ Branch 1 taken 190132 times.
✓ Branch 2 taken 1242 times.
✓ Branch 3 taken 190132 times.
|
40443556 | CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15)))) |
| 82 |
4/4✓ Branch 0 taken 100939 times.
✓ Branch 1 taken 326 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 326 times.
|
101268 | CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31)))) |
| 83 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float*)pi * (UINT64_C(1)<<63))) | |
| 84 |
4/4✓ Branch 0 taken 2650850 times.
✓ Branch 1 taken 3021 times.
✓ Branch 2 taken 352 times.
✓ Branch 3 taken 3021 times.
|
2654223 | CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_FLT, *(const float*)pi) |
| 85 |
3/4✓ Branch 0 taken 66150 times.
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 65 times.
|
66215 | CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_FLT, *(const float*)pi) |
| 86 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8( lrint(*(const double*)pi * (1<<7)) + 0x80)) | |
| 87 |
4/4✓ Branch 0 taken 3749884 times.
✓ Branch 1 taken 11786 times.
✓ Branch 2 taken 306 times.
✓ Branch 3 taken 11786 times.
|
3761976 | CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16( lrint(*(const double*)pi * (1<<15)))) |
| 88 |
4/4✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
|
1158 | CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31)))) |
| 89 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double*)pi * (UINT64_C(1)<<63))) | |
| 90 |
3/4✓ Branch 0 taken 66150 times.
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 65 times.
|
66215 | CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_DBL, *(const double*)pi) |
| 91 |
4/4✓ Branch 0 taken 2587978 times.
✓ Branch 1 taken 9742 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9742 times.
|
2597721 | CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_DBL, *(const double*)pi) |
| 92 | ✗ | CONV_FUNC(AV_SAMPLE_FMT_DSD, uint8_t, AV_SAMPLE_FMT_DSD, *(const uint8_t*)pi) | |
| 93 | |||
| 94 | 362 | static void CONV_FUNC_NAME(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DSD)(DSDContext *st, uint8_t *po, const uint8_t *pi, int is, int os, uint8_t *end) | |
| 95 | { | ||
| 96 | 362 | swri_dsd2pcm_translate(st, (end - po) / os, pi, is, (float *)po, os / sizeof(float)); | |
| 97 | 362 | } | |
| 98 | |||
| 99 | #define FMT_PAIR_FUNC(out, in) [(out) + AV_SAMPLE_FMT_NB*(in)] = CONV_FUNC_NAME(out, in) | ||
| 100 | |||
| 101 | static conv_func_type * const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB*AV_SAMPLE_FMT_NB] = { | ||
| 102 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_U8 ), | ||
| 103 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8 ), | ||
| 104 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8 ), | ||
| 105 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8 ), | ||
| 106 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8 ), | ||
| 107 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8 ), | ||
| 108 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_S16), | ||
| 109 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), | ||
| 110 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), | ||
| 111 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), | ||
| 112 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), | ||
| 113 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), | ||
| 114 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_S32), | ||
| 115 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), | ||
| 116 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), | ||
| 117 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), | ||
| 118 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), | ||
| 119 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), | ||
| 120 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_FLT), | ||
| 121 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), | ||
| 122 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), | ||
| 123 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), | ||
| 124 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), | ||
| 125 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), | ||
| 126 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_DBL), | ||
| 127 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), | ||
| 128 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), | ||
| 129 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), | ||
| 130 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), | ||
| 131 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), | ||
| 132 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_S64), | ||
| 133 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), | ||
| 134 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), | ||
| 135 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), | ||
| 136 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), | ||
| 137 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), | ||
| 138 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DSD), | ||
| 139 | FMT_PAIR_FUNC(AV_SAMPLE_FMT_DSD, AV_SAMPLE_FMT_DSD), | ||
| 140 | }; | ||
| 141 | |||
| 142 | ✗ | static void cpy1(uint8_t **dst, const uint8_t **src, int len){ | |
| 143 | ✗ | memcpy(*dst, *src, len); | |
| 144 | ✗ | } | |
| 145 | ✗ | static void cpy2(uint8_t **dst, const uint8_t **src, int len){ | |
| 146 | ✗ | memcpy(*dst, *src, 2*len); | |
| 147 | ✗ | } | |
| 148 | ✗ | static void cpy4(uint8_t **dst, const uint8_t **src, int len){ | |
| 149 | ✗ | memcpy(*dst, *src, 4*len); | |
| 150 | ✗ | } | |
| 151 | ✗ | static void cpy8(uint8_t **dst, const uint8_t **src, int len){ | |
| 152 | ✗ | memcpy(*dst, *src, 8*len); | |
| 153 | ✗ | } | |
| 154 | |||
| 155 | 2357 | AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, | |
| 156 | enum AVSampleFormat in_fmt, | ||
| 157 | int channels, const int *ch_map, | ||
| 158 | int flags) | ||
| 159 | { | ||
| 160 | AudioConvert *ctx; | ||
| 161 | 2357 | conv_func_type *f = fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)]; | |
| 162 | |||
| 163 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2356 times.
|
2357 | if (!f) |
| 164 | 1 | return NULL; | |
| 165 | 2356 | ctx = av_mallocz(sizeof(*ctx)); | |
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2356 times.
|
2356 | if (!ctx) |
| 167 | ✗ | return NULL; | |
| 168 | |||
| 169 |
2/2✓ Branch 0 taken 1674 times.
✓ Branch 1 taken 682 times.
|
2356 | if(channels == 1){ |
| 170 | 1674 | in_fmt = av_get_planar_sample_fmt( in_fmt); | |
| 171 | 1674 | out_fmt = av_get_planar_sample_fmt(out_fmt); | |
| 172 | } | ||
| 173 | |||
| 174 | 2356 | ctx->channels = channels; | |
| 175 | 2356 | ctx->conv_f = f; | |
| 176 | 2356 | ctx->ch_map = ch_map; | |
| 177 |
4/4✓ Branch 0 taken 2350 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 2330 times.
|
2356 | if (in_fmt == AV_SAMPLE_FMT_U8 || in_fmt == AV_SAMPLE_FMT_U8P) |
| 178 | 26 | memset(ctx->silence, 0x80, sizeof(ctx->silence)); | |
| 179 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2351 times.
|
2356 | if (in_fmt == AV_SAMPLE_FMT_DSD) { |
| 180 | 5 | swri_dsd2pcm_init(); | |
| 181 | 5 | memset(ctx->silence, 0x69, sizeof(ctx->silence)); | |
| 182 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 5 times.
|
325 | for (int ch = 0; ch < FF_ARRAY_ELEMS(ctx->dsd_state); ch++) |
| 183 | 320 | memset(ctx->dsd_state[ch].buf, 0x69, sizeof(ctx->dsd_state[ch].buf)); | |
| 184 | } | ||
| 185 | |||
| 186 |
4/4✓ Branch 0 taken 1153 times.
✓ Branch 1 taken 1203 times.
✓ Branch 2 taken 1143 times.
✓ Branch 3 taken 10 times.
|
2356 | if(out_fmt == in_fmt && !ch_map) { |
| 187 |
3/5✗ Branch 1 not taken.
✓ Branch 2 taken 569 times.
✓ Branch 3 taken 402 times.
✓ Branch 4 taken 172 times.
✗ Branch 5 not taken.
|
1143 | switch(av_get_bytes_per_sample(in_fmt)){ |
| 188 | ✗ | case 1:ctx->simd_f = cpy1; break; | |
| 189 | 569 | case 2:ctx->simd_f = cpy2; break; | |
| 190 | 402 | case 4:ctx->simd_f = cpy4; break; | |
| 191 | 172 | case 8:ctx->simd_f = cpy8; break; | |
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | #if ARCH_X86 && HAVE_X86ASM | ||
| 196 | 2356 | swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels); | |
| 197 | #elif ARCH_ARM | ||
| 198 | swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels); | ||
| 199 | #elif ARCH_AARCH64 | ||
| 200 | swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels); | ||
| 201 | #endif | ||
| 202 | |||
| 203 | 2356 | return ctx; | |
| 204 | } | ||
| 205 | |||
| 206 | 12771 | void swri_audio_convert_free(AudioConvert **ctx) | |
| 207 | { | ||
| 208 | 12771 | av_freep(ctx); | |
| 209 | 12771 | } | |
| 210 | |||
| 211 | 270109 | int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) | |
| 212 | { | ||
| 213 | int ch; | ||
| 214 | 270109 | int off=0; | |
| 215 |
2/2✓ Branch 0 taken 142089 times.
✓ Branch 1 taken 128020 times.
|
270109 | const int os= (out->planar ? 1 :out->ch_count) *out->bps; |
| 216 | 270109 | unsigned misaligned = 0; | |
| 217 | |||
| 218 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 270109 times.
|
270109 | av_assert0(ctx->channels == out->ch_count); |
| 219 | |||
| 220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 270109 times.
|
270109 | if (ctx->in_simd_align_mask) { |
| 221 | ✗ | int planes = in->planar ? in->ch_count : 1; | |
| 222 | ✗ | unsigned m = 0; | |
| 223 | ✗ | for (ch = 0; ch < planes; ch++) | |
| 224 | ✗ | m |= (intptr_t)in->ch[ch]; | |
| 225 | ✗ | misaligned |= m & ctx->in_simd_align_mask; | |
| 226 | } | ||
| 227 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 270109 times.
|
270109 | if (ctx->out_simd_align_mask) { |
| 228 | ✗ | int planes = out->planar ? out->ch_count : 1; | |
| 229 | ✗ | unsigned m = 0; | |
| 230 | ✗ | for (ch = 0; ch < planes; ch++) | |
| 231 | ✗ | m |= (intptr_t)out->ch[ch]; | |
| 232 | ✗ | misaligned |= m & ctx->out_simd_align_mask; | |
| 233 | } | ||
| 234 | |||
| 235 | //FIXME optimize common cases | ||
| 236 | |||
| 237 |
4/6✓ Branch 0 taken 425 times.
✓ Branch 1 taken 269684 times.
✓ Branch 2 taken 425 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 425 times.
✗ Branch 5 not taken.
|
270109 | if(ctx->simd_f && !ctx->ch_map && !misaligned){ |
| 238 | 425 | off = len&~15; | |
| 239 | av_assert1(off>=0); | ||
| 240 | av_assert1(off<=len); | ||
| 241 | av_assert2(ctx->channels == SWR_CH_MAX || !in->ch[ctx->channels]); | ||
| 242 |
1/2✓ Branch 0 taken 425 times.
✗ Branch 1 not taken.
|
425 | if(off>0){ |
| 243 |
2/2✓ Branch 0 taken 188 times.
✓ Branch 1 taken 237 times.
|
425 | if(out->planar == in->planar){ |
| 244 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 141 times.
|
188 | int planes = out->planar ? out->ch_count : 1; |
| 245 |
2/2✓ Branch 0 taken 188 times.
✓ Branch 1 taken 188 times.
|
376 | for(ch=0; ch<planes; ch++){ |
| 246 |
2/2✓ Branch 0 taken 141 times.
✓ Branch 1 taken 47 times.
|
188 | ctx->simd_f(out->ch+ch, (const uint8_t **)in->ch+ch, off * (out->planar ? 1 :out->ch_count)); |
| 247 | } | ||
| 248 | }else{ | ||
| 249 | 237 | ctx->simd_f(out->ch, (const uint8_t **)in->ch, off); | |
| 250 | } | ||
| 251 | } | ||
| 252 |
2/2✓ Branch 0 taken 421 times.
✓ Branch 1 taken 4 times.
|
425 | if(off == len) |
| 253 | 421 | return 0; | |
| 254 | } | ||
| 255 | |||
| 256 |
2/2✓ Branch 0 taken 472442 times.
✓ Branch 1 taken 269688 times.
|
742130 | for(ch=0; ch<ctx->channels; ch++){ |
| 257 |
2/2✓ Branch 0 taken 2289 times.
✓ Branch 1 taken 470153 times.
|
472442 | const int ich= ctx->ch_map ? ctx->ch_map[ch] : ch; |
| 258 |
4/4✓ Branch 0 taken 471987 times.
✓ Branch 1 taken 455 times.
✓ Branch 2 taken 28873 times.
✓ Branch 3 taken 443114 times.
|
472442 | const int is= ich < 0 ? 0 : (in->planar ? 1 : in->ch_count) * in->bps; |
| 259 |
2/2✓ Branch 0 taken 455 times.
✓ Branch 1 taken 471987 times.
|
472442 | const uint8_t *pi= ich < 0 ? ctx->silence : in->ch[ich]; |
| 260 | 472442 | uint8_t *end, *po = out->ch[ch]; | |
| 261 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 472390 times.
|
472442 | if(!po) |
| 262 | 52 | continue; | |
| 263 | 472390 | end = po + os * len; | |
| 264 | 472390 | ctx->conv_f(&ctx->dsd_state[ch], po+off*os, pi+off*is, is, os, end); | |
| 265 | } | ||
| 266 | 269688 | return 0; | |
| 267 | } | ||
| 268 |