49 enum ColorMode {
CHANNEL,
INTENSITY,
RAINBOW,
MORELAND,
NEBULAE,
FIRE,
FIERY,
FRUIT,
COOL,
MAGMA,
GREEN,
NB_CLMODES };
100 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
101 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
179 { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
180 { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
181 { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
182 { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
183 { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
184 { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
188 { 0.13, 44/256., (189-128)/256., (138-128)/256. },
189 { 0.25, 29/256., (186-128)/256., (119-128)/256. },
190 { 0.38, 119/256., (194-128)/256., (53-128)/256. },
191 { 0.60, 111/256., (73-128)/256., (59-128)/256. },
192 { 0.73, 205/256., (19-128)/256., (149-128)/256. },
193 { 0.86, 135/256., (83-128)/256., (200-128)/256. },
194 { 1, 73/256., (95-128)/256., (225-128)/256. }},
196 { 0, 44/256., (181-128)/256., (112-128)/256. },
197 { 0.13, 126/256., (177-128)/256., (106-128)/256. },
198 { 0.25, 164/256., (163-128)/256., (109-128)/256. },
199 { 0.38, 200/256., (140-128)/256., (120-128)/256. },
200 { 0.60, 201/256., (117-128)/256., (141-128)/256. },
201 { 0.73, 177/256., (103-128)/256., (165-128)/256. },
202 { 0.86, 136/256., (100-128)/256., (183-128)/256. },
203 { 1, 68/256., (117-128)/256., (203-128)/256. }},
205 { 0, 10/256., (134-128)/256., (132-128)/256. },
206 { 0.23, 21/256., (137-128)/256., (130-128)/256. },
207 { 0.45, 35/256., (134-128)/256., (134-128)/256. },
208 { 0.57, 51/256., (130-128)/256., (139-128)/256. },
209 { 0.67, 104/256., (116-128)/256., (162-128)/256. },
210 { 0.77, 120/256., (105-128)/256., (188-128)/256. },
211 { 0.87, 140/256., (105-128)/256., (188-128)/256. },
215 { 0.23, 44/256., (132-128)/256., (127-128)/256. },
216 { 0.45, 62/256., (116-128)/256., (140-128)/256. },
217 { 0.57, 75/256., (105-128)/256., (152-128)/256. },
218 { 0.67, 95/256., (91-128)/256., (166-128)/256. },
219 { 0.77, 126/256., (74-128)/256., (172-128)/256. },
220 { 0.87, 164/256., (73-128)/256., (162-128)/256. },
224 { 0.23, 36/256., (116-128)/256., (163-128)/256. },
225 { 0.45, 52/256., (102-128)/256., (200-128)/256. },
226 { 0.57, 116/256., (84-128)/256., (196-128)/256. },
227 { 0.67, 157/256., (67-128)/256., (181-128)/256. },
228 { 0.77, 193/256., (40-128)/256., (155-128)/256. },
229 { 0.87, 221/256., (101-128)/256., (134-128)/256. },
233 { 0.20, 29/256., (136-128)/256., (119-128)/256. },
234 { 0.30, 60/256., (119-128)/256., (90-128)/256. },
235 { 0.40, 85/256., (91-128)/256., (85-128)/256. },
236 { 0.50, 116/256., (70-128)/256., (105-128)/256. },
237 { 0.60, 151/256., (50-128)/256., (146-128)/256. },
238 { 0.70, 191/256., (63-128)/256., (178-128)/256. },
239 { 1, 98/256., (80-128)/256., (221-128)/256. }},
246 { 0.10, 23/256., (175-128)/256., (120-128)/256. },
247 { 0.23, 43/256., (158-128)/256., (144-128)/256. },
248 { 0.35, 85/256., (138-128)/256., (179-128)/256. },
249 { 0.48, 96/256., (128-128)/256., (189-128)/256. },
250 { 0.64, 128/256., (103-128)/256., (214-128)/256. },
251 { 0.78, 167/256., (85-128)/256., (174-128)/256. },
252 { 1, 205/256., (80-128)/256., (152-128)/256. }},
342 const int ch = jobnr;
354 double theta, phi, psi,
a,
b,
S,
c;
364 for (
int n = 0; n <
M; n++) {
365 h[
n].
re = cos(n * n / 2.0 * phi);
366 h[
n].
im = sin(n * n / 2.0 * phi);
369 for (
int n = M; n <
L; n++) {
374 for (
int n = L - N; n <
L; n++) {
375 h[
n].
re = cos((L - n) * (L - n) / 2.0 * phi);
376 h[
n].
im = sin((L - n) * (L - n) / 2.0 * phi);
379 for (
int n = 0; n <
N; n++) {
384 for (
int n = N; n <
L; n++) {
389 for (
int n = 0; n <
N; n++) {
390 psi = n * theta + n * n / 2.0 * phi;
393 a = c * g[
n].
re - S * g[
n].
im;
394 b = S * g[
n].
re + c * g[
n].
im;
405 for (
int n = 0; n <
L; n++) {
408 a = c * h[
n].
re - S * h[
n].
im;
409 b = S * h[
n].
re + c * h[
n].
im;
418 for (
int k = 0; k <
M; k++) {
419 psi = k * k / 2.0 * phi;
422 a = c * g[k].
re - S * g[k].
im;
423 b = S * g[k].
re + c * g[k].
im;
444 for (i = 0; txt[i]; i++) {
448 for (char_y = font_height - 1; char_y >= 0; char_y--) {
450 for (mask = 0x80;
mask; mask >>= 1) {
451 if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
452 p[char_y] = ~p[char_y];
458 for (char_y = 0; char_y < font_height; char_y++) {
459 for (mask = 0x80;
mask; mask >>= 1) {
460 if (font[txt[i] * font_height + char_y] & mask)
471 float *yf,
float *uf,
float *vf)
529 float yf,
float uf,
float vf,
553 float lerpfrac = (a -
start) / (end - start);
578 else if (log10(seconds) > 6)
580 else if (log10(seconds) > 3)
594 float spp = samples / (float)sz;
597 char chlayout_str[128];
615 for (x = 0; x < s->
w + 1; x++)
618 for (x = 0; x < s->
w + 1; x++)
620 for (y = 0; y < s->
h + 2; y++) {
629 for (y = 0; y <
h; y += 20) {
634 for (y = 0; y <
h; y += 40) {
640 for (x = 0; x < s->
w; x+=40)
643 for (x = 0; x < s->
w; x+=80)
646 for (x = 0; x < s->
w; x+=40) {
650 for (x = 0; x < s->
w; x+=80) {
653 for (y = 0; y <
h; y += 40) {
655 float hertz = s->
start + y * range / (float)(1 << (
int)ceil(
log2(h)));
672 char *units =
get_time(ctx, seconds, x);
683 for (y = 0; y < s->
h; y += 20) {
688 for (y = 0; y < s->
h; y += 40) {
695 for (x = 0; x <
w; x+=40)
698 for (x = 0; x <
w; x+=80)
701 for (x = 0; x <
w; x+=40) {
705 for (x = 0; x <
w; x+=80) {
708 for (x = 0; x < w - 79; x += 80) {
710 float hertz = s->
start + x * range / (float)(1 << (
int)ceil(
log2(w)));
727 char *units =
get_time(ctx, seconds, x);
739 for (y = 0; y <
h; y++) {
740 float out[3] = { 0., 127.5, 127.5};
749 pick_color(s, yf, uf, vf, y / (
float)h, lout);
759 for (y = 0; ch == 0 && y <
h; y += h / 10) {
760 float value = 120.0 * log10(1. - y / (
float)h);
781 int i, fft_bits,
h,
w;
790 if (!strcmp(ctx->
filter->
name,
"showspectrumpic"))
811 for (fft_bits = 1; 1 << fft_bits < 2 *
h; fft_bits++);
814 for (fft_bits = 1; 1 << fft_bits < 2 *
w; fft_bits++);
860 "The window size might be too high.\n");
866 "The window size might be too high.\n");
930 for (s->
win_scale = 0, i = 0; i < s->win_size; i++) {
942 for (i = 0; i < outlink->
h; i++) {
943 memset(outpicref->
data[0] + i * outpicref->
linesize[0], 0, outlink->
w);
944 memset(outpicref->
data[1] + i * outpicref->
linesize[1], 128, outlink->
w);
945 memset(outpicref->
data[2] + i * outpicref->
linesize[2], 128, outlink->
w);
992 #define RE(y, ch) s->fft_data[ch][y].re
993 #define IM(y, ch) s->fft_data[ch][y].im
994 #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
995 #define PHASE(y, ch) atan2(IM(y, ch), RE(y, ch))
1002 const float f = s->
gain *
w;
1003 const int ch = jobnr;
1006 for (y = 0; y <
h; y++)
1016 const int ch = jobnr;
1020 for (y = 0; y <
h; y++)
1021 phases[y] = (
PHASE(y, ch) /
M_PI + 1) / 2;
1030 const float f = s->
gain *
w;
1035 for (y = 0; y <
h; y++)
1047 for (y = 0; y <
h; y++)
1048 magnitudes[y] *= scale;
1056 for (y = 0; y <
size; y++) {
1067 const int ch = jobnr;
1077 for (y = 0; y <
h; y++) {
1098 a = av_clipf(a, 0, 1);
1101 a = av_clipf(sqrt(a), 0, 1);
1104 a = av_clipf(
cbrt(a), 0, 1);
1107 a = av_clipf(sqrt(sqrt(a)), 0, 1);
1110 a = av_clipf(pow(a, 0.20), 0, 1);
1113 a = 1 + log10(av_clipd(a, 1e-6, 1)) / 6;
1139 for (y = 0; y < z * 3; y++) {
1149 for (plane = 0; plane < 3; plane++) {
1150 for (y = 0; y < s->
h; y++) {
1153 memmove(p, p + 1, s->
w - 1);
1158 for (plane = 0; plane < 3; plane++) {
1159 for (y = 0; y < s->
h; y++) {
1162 memmove(p + 1, p, s->
w - 1);
1167 for (plane = 0; plane < 3; plane++) {
1171 for (y = 0; y < s->
h; y++) {
1178 for (plane = 0; plane < 3; plane++) {
1179 for (y = 1; y < s->
h; y++) {
1187 for (plane = 0; plane < 3; plane++) {
1188 for (y = s->
h - 1; y >= 1; y--) {
1196 for (plane = 0; plane < 3; plane++) {
1199 for (x = 0; x < s->
w; x++) {
1220 for (y = 0; y < 10; y++) {
1225 outlink->
w / 2 - 4 * strlen(units),
1229 for (y = 0; y < 10 * s->
old_len; y++) {
1235 outlink->
h / 2 - 4 * strlen(units),
1252 #if CONFIG_SHOWSPECTRUM_FILTER
1316 for (
int i = 0; i < outlink->
h; i++) {
1322 for (
int i = s->
xpos; i < outlink->
h; i++) {
1349 static const AVFilterPad showspectrum_inputs[] = {
1357 static const AVFilterPad showspectrum_outputs[] = {
1367 .
name =
"showspectrum",
1372 .
inputs = showspectrum_inputs,
1373 .
outputs = showspectrum_outputs,
1375 .priv_class = &showspectrum_class,
1378 #endif // CONFIG_SHOWSPECTRUM_FILTER
1380 #if CONFIG_SHOWSPECTRUMPIC_FILTER
1382 static const AVOption showspectrumpic_options[] = {
1443 static int showspectrumpic_request_frame(
AVFilterLink *outlink)
1459 spf =
FFMAX(1, spf);
1461 spb = (samples / (spf * sz)) * spf;
1476 if (ret < s->win_size) {
1479 (s->
win_size - ret) *
sizeof(
float));
1487 if (consumed >= spb) {
1495 memset(s->
magnitudes[ch], 0, h *
sizeof(
float));
1523 static const AVFilterPad showspectrumpic_inputs[] = {
1527 .filter_frame = showspectrumpic_filter_frame,
1532 static const AVFilterPad showspectrumpic_outputs[] = {
1537 .request_frame = showspectrumpic_request_frame,
1543 .
name =
"showspectrumpic",
1544 .description =
NULL_IF_CONFIG_SMALL(
"Convert input audio to a spectrum video output single picture."),
1548 .
inputs = showspectrumpic_inputs,
1549 .
outputs = showspectrumpic_outputs,
1550 .priv_class = &showspectrumpic_class,
1554 #endif // CONFIG_SHOWSPECTRUMPIC_FILTER
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
#define av_realloc_f(p, o, n)
This structure describes decoded (raw) audio or video data.
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
static int activate(AVFilterContext *ctx)
ptrdiff_t const GLvoid * data
av_cold void av_fft_end(FFTContext *s)
float rotation
color rotation
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
FFTComplex ** fft_data
bins holder for each (displayed) channels
int h
agreed upon image height
static int draw_legend(AVFilterContext *ctx, int samples)
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
#define FFERROR_NOT_READY
Filters implementation helper functions.
float * window_func_lut
Window function LUT.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
int fft_bits
number of bits (FFT window size = 1<<fft_bits)
static int query_formats(AVFilterContext *ctx)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int sliding
1 if sliding mode, 0 otherwise
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
int mode
channel display mode
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o)
static const AVOption showspectrum_options[]
static int calc_channel_magnitudes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold int end(AVCodecContext *avctx)
AVRational auto_frame_rate
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define u(width, name, range_min, range_max)
static int run_channel_fft(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int calc_channel_phases(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
static char * get_time(AVFilterContext *ctx, float seconds, int x)
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static int plot_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint8_t avpriv_cga_font[2048]
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static const uint16_t mask[17]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
float ** color_buffer
color buffer (3 * h * ch items)
void * priv
private data for use by the filter
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
float saturation
color saturation multiplier
float * combine_buffer
color combining buffer (3 * h items)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
struct AVFilterChannelLayouts * out_channel_layouts
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
Context for an Audio FIFO Buffer.
int w
agreed upon image width
char * av_asprintf(const char *fmt,...)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
audio channel layout utility functions
GLsizei GLboolean const GLfloat * value
static void acalc_magnitudes(ShowSpectrumContext *s)
AVFilterContext * src
source filter
static const AVFilterPad inputs[]
AVFilterFormats * out_samplerates
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
static const AVFilterPad outputs[]
int format
agreed upon media format
#define FF_ARRAY_ELEMS(a)
FFTContext ** ifft
Inverse Fast Fourier Transform context.
the normal 2^n-1 "JPEG" YUV ranges
A list of supported channel layouts.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
static int config_output(AVFilterLink *outlink)
static void color_range(ShowSpectrumContext *s, int ch, float *yf, float *uf, float *vf)
AVSampleFormat
Audio sample formats.
static const struct ColorTable color_table[][8]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilter ff_avf_showspectrum
static AVRational av_make_q(int num, int den)
Create an AVRational.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Describe the class of an AVClass context structure.
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
AVFILTER_DEFINE_CLASS(showspectrum)
Rational number (pair of numerator and denominator).
const char * name
Filter name.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
offset must point to two consecutive integers
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
static enum AVPixelFormat pix_fmts[]
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
static av_cold void uninit(AVFilterContext *ctx)
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
channel
Use these values when setting the channel map with ebur128_set_channel().
FFTContext ** fft
Fast Fourier Transform context.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int channels
Number of channels.
avfilter_execute_func * execute
AVFilterContext * dst
dest filter
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
AVFilter ff_avf_showspectrumpic
static enum AVSampleFormat sample_fmts[]
static void scale_magnitudes(ShowSpectrumContext *s, float scale)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static void pick_color(ShowSpectrumContext *s, float yf, float uf, float vf, float a, float *out)
uint8_t ** extended_data
pointers to the data planes/channels.
int xpos
x position (current column)
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
AVPixelFormat
Pixel format.
static void clear_combine_buffer(ShowSpectrumContext *s, int size)
mode
Use these values in ebur128_init (or'ed).
int nb_samples
number of audio samples (per channel) described by this frame
const AVFilter * filter
the AVFilter of which this is an instance
FFTComplex ** fft_scratch
scratch buffers
CGA/EGA/VGA ROM font data.
AVFilterFormats * out_formats
int color_mode
display color scheme
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;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)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch