FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avresample.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVRESAMPLE_AVRESAMPLE_H
22 #define AVRESAMPLE_AVRESAMPLE_H
23 
24 /**
25  * @file
26  * @ingroup lavr
27  * external API header
28  */
29 
30 /**
31  * @defgroup lavr Libavresample
32  * @{
33  *
34  * Libavresample (lavr) is a library that handles audio resampling, sample
35  * format conversion and mixing.
36  *
37  * Interaction with lavr is done through AVAudioResampleContext, which is
38  * allocated with avresample_alloc_context(). It is opaque, so all parameters
39  * must be set with the @ref avoptions API.
40  *
41  * For example the following code will setup conversion from planar float sample
42  * format to interleaved signed 16-bit integer, downsampling from 48kHz to
43  * 44.1kHz and downmixing from 5.1 channels to stereo (using the default mixing
44  * matrix):
45  * @code
46  * AVAudioResampleContext *avr = avresample_alloc_context();
47  * av_opt_set_int(avr, "in_channel_layout", AV_CH_LAYOUT_5POINT1, 0);
48  * av_opt_set_int(avr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
49  * av_opt_set_int(avr, "in_sample_rate", 48000, 0);
50  * av_opt_set_int(avr, "out_sample_rate", 44100, 0);
51  * av_opt_set_int(avr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
52  * av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
53  * @endcode
54  *
55  * Once the context is initialized, it must be opened with avresample_open(). If
56  * you need to change the conversion parameters, you must close the context with
57  * avresample_close(), change the parameters as described above, then reopen it
58  * again.
59  *
60  * The conversion itself is done by repeatedly calling avresample_convert().
61  * Note that the samples may get buffered in two places in lavr. The first one
62  * is the output FIFO, where the samples end up if the output buffer is not
63  * large enough. The data stored in there may be retrieved at any time with
64  * avresample_read(). The second place is the resampling delay buffer,
65  * applicable only when resampling is done. The samples in it require more input
66  * before they can be processed. Their current amount is returned by
67  * avresample_get_delay(). At the end of conversion the resampling buffer can be
68  * flushed by calling avresample_convert() with NULL input.
69  *
70  * The following code demonstrates the conversion loop assuming the parameters
71  * from above and caller-defined functions get_input() and handle_output():
72  * @code
73  * uint8_t **input;
74  * int in_linesize, in_samples;
75  *
76  * while (get_input(&input, &in_linesize, &in_samples)) {
77  * uint8_t *output
78  * int out_linesize;
79  * int out_samples = avresample_get_out_samples(avr, in_samples);
80  *
81  * av_samples_alloc(&output, &out_linesize, 2, out_samples,
82  * AV_SAMPLE_FMT_S16, 0);
83  * out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
84  * input, in_linesize, in_samples);
85  * handle_output(output, out_linesize, out_samples);
86  * av_freep(&output);
87  * }
88  * @endcode
89  *
90  * When the conversion is finished and the FIFOs are flushed if required, the
91  * conversion context and everything associated with it must be freed with
92  * avresample_free().
93  */
94 
95 #include "libavutil/avutil.h"
97 #include "libavutil/dict.h"
98 #include "libavutil/frame.h"
99 #include "libavutil/log.h"
100 #include "libavutil/mathematics.h"
101 
102 #include "libavresample/version.h"
103 
104 #define AVRESAMPLE_MAX_CHANNELS 32
105 
107 
108 /** Mixing Coefficient Types */
110  AV_MIX_COEFF_TYPE_Q8, /** 16-bit 8.8 fixed-point */
111  AV_MIX_COEFF_TYPE_Q15, /** 32-bit 17.15 fixed-point */
112  AV_MIX_COEFF_TYPE_FLT, /** floating-point */
113  AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */
114 };
115 
116 /** Resampling Filter Types */
119  AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall Windowed Sinc */
120  AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */
121 };
122 
124  AV_RESAMPLE_DITHER_NONE, /**< Do not use dithering */
125  AV_RESAMPLE_DITHER_RECTANGULAR, /**< Rectangular Dither */
126  AV_RESAMPLE_DITHER_TRIANGULAR, /**< Triangular Dither*/
127  AV_RESAMPLE_DITHER_TRIANGULAR_HP, /**< Triangular Dither with High Pass */
128  AV_RESAMPLE_DITHER_TRIANGULAR_NS, /**< Triangular Dither with Noise Shaping */
129  AV_RESAMPLE_DITHER_NB, /**< Number of dither types. Not part of ABI. */
130 };
131 
132 /**
133  * Return the LIBAVRESAMPLE_VERSION_INT constant.
134  */
135 unsigned avresample_version(void);
136 
137 /**
138  * Return the libavresample build-time configuration.
139  * @return configure string
140  */
141 const char *avresample_configuration(void);
142 
143 /**
144  * Return the libavresample license.
145  */
146 const char *avresample_license(void);
147 
148 /**
149  * Get the AVClass for AVAudioResampleContext.
150  *
151  * Can be used in combination with AV_OPT_SEARCH_FAKE_OBJ for examining options
152  * without allocating a context.
153  *
154  * @see av_opt_find().
155  *
156  * @return AVClass for AVAudioResampleContext
157  */
158 const AVClass *avresample_get_class(void);
159 
160 /**
161  * Allocate AVAudioResampleContext and set options.
162  *
163  * @return allocated audio resample context, or NULL on failure
164  */
166 
167 /**
168  * Initialize AVAudioResampleContext.
169  * @note The context must be configured using the AVOption API.
170  * @note The fields "in_channel_layout", "out_channel_layout",
171  * "in_sample_rate", "out_sample_rate", "in_sample_fmt",
172  * "out_sample_fmt" must be set.
173  *
174  * @see av_opt_set_int()
175  * @see av_opt_set_dict()
176  * @see av_get_default_channel_layout()
177  *
178  * @param avr audio resample context
179  * @return 0 on success, negative AVERROR code on failure
180  */
182 
183 /**
184  * Check whether an AVAudioResampleContext is open or closed.
185  *
186  * @param avr AVAudioResampleContext to check
187  * @return 1 if avr is open, 0 if avr is closed.
188  */
190 
191 /**
192  * Close AVAudioResampleContext.
193  *
194  * This closes the context, but it does not change the parameters. The context
195  * can be reopened with avresample_open(). It does, however, clear the output
196  * FIFO and any remaining leftover samples in the resampling delay buffer. If
197  * there was a custom matrix being used, that is also cleared.
198  *
199  * @see avresample_convert()
200  * @see avresample_set_matrix()
201  *
202  * @param avr audio resample context
203  */
205 
206 /**
207  * Free AVAudioResampleContext and associated AVOption values.
208  *
209  * This also calls avresample_close() before freeing.
210  *
211  * @param avr audio resample context
212  */
214 
215 /**
216  * Generate a channel mixing matrix.
217  *
218  * This function is the one used internally by libavresample for building the
219  * default mixing matrix. It is made public just as a utility function for
220  * building custom matrices.
221  *
222  * @param in_layout input channel layout
223  * @param out_layout output channel layout
224  * @param center_mix_level mix level for the center channel
225  * @param surround_mix_level mix level for the surround channel(s)
226  * @param lfe_mix_level mix level for the low-frequency effects channel
227  * @param normalize if 1, coefficients will be normalized to prevent
228  * overflow. if 0, coefficients will not be
229  * normalized.
230  * @param[out] matrix mixing coefficients; matrix[i + stride * o] is
231  * the weight of input channel i in output channel o.
232  * @param stride distance between adjacent input channels in the
233  * matrix array
234  * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii)
235  * @return 0 on success, negative AVERROR code on failure
236  */
237 int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
238  double center_mix_level, double surround_mix_level,
239  double lfe_mix_level, int normalize, double *matrix,
241 
242 /**
243  * Get the current channel mixing matrix.
244  *
245  * If no custom matrix has been previously set or the AVAudioResampleContext is
246  * not open, an error is returned.
247  *
248  * @param avr audio resample context
249  * @param matrix mixing coefficients; matrix[i + stride * o] is the weight of
250  * input channel i in output channel o.
251  * @param stride distance between adjacent input channels in the matrix array
252  * @return 0 on success, negative AVERROR code on failure
253  */
254 int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix,
255  int stride);
256 
257 /**
258  * Set channel mixing matrix.
259  *
260  * Allows for setting a custom mixing matrix, overriding the default matrix
261  * generated internally during avresample_open(). This function can be called
262  * anytime on an allocated context, either before or after calling
263  * avresample_open(), as long as the channel layouts have been set.
264  * avresample_convert() always uses the current matrix.
265  * Calling avresample_close() on the context will clear the current matrix.
266  *
267  * @see avresample_close()
268  *
269  * @param avr audio resample context
270  * @param matrix mixing coefficients; matrix[i + stride * o] is the weight of
271  * input channel i in output channel o.
272  * @param stride distance between adjacent input channels in the matrix array
273  * @return 0 on success, negative AVERROR code on failure
274  */
275 int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
276  int stride);
277 
278 /**
279  * Set a customized input channel mapping.
280  *
281  * This function can only be called when the allocated context is not open.
282  * Also, the input channel layout must have already been set.
283  *
284  * Calling avresample_close() on the context will clear the channel mapping.
285  *
286  * The map for each input channel specifies the channel index in the source to
287  * use for that particular channel, or -1 to mute the channel. Source channels
288  * can be duplicated by using the same index for multiple input channels.
289  *
290  * Examples:
291  *
292  * Reordering 5.1 AAC order (C,L,R,Ls,Rs,LFE) to FFmpeg order (L,R,C,LFE,Ls,Rs):
293  * { 1, 2, 0, 5, 3, 4 }
294  *
295  * Muting the 3rd channel in 4-channel input:
296  * { 0, 1, -1, 3 }
297  *
298  * Duplicating the left channel of stereo input:
299  * { 0, 0 }
300  *
301  * @param avr audio resample context
302  * @param channel_map customized input channel mapping
303  * @return 0 on success, negative AVERROR code on failure
304  */
306  const int *channel_map);
307 
308 /**
309  * Set compensation for resampling.
310  *
311  * This can be called anytime after avresample_open(). If resampling is not
312  * automatically enabled because of a sample rate conversion, the
313  * "force_resampling" option must have been set to 1 when opening the context
314  * in order to use resampling compensation.
315  *
316  * @param avr audio resample context
317  * @param sample_delta compensation delta, in samples
318  * @param compensation_distance compensation distance, in samples
319  * @return 0 on success, negative AVERROR code on failure
320  */
321 int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta,
322  int compensation_distance);
323 
324 /**
325  * Provide the upper bound on the number of samples the configured
326  * conversion would output.
327  *
328  * @param avr audio resample context
329  * @param in_nb_samples number of input samples
330  *
331  * @return number of samples or AVERROR(EINVAL) if the value
332  * would exceed INT_MAX
333  */
334 
335 int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples);
336 
337 /**
338  * Convert input samples and write them to the output FIFO.
339  *
340  * The upper bound on the number of output samples can be obtained through
341  * avresample_get_out_samples().
342  *
343  * The output data can be NULL or have fewer allocated samples than required.
344  * In this case, any remaining samples not written to the output will be added
345  * to an internal FIFO buffer, to be returned at the next call to this function
346  * or to avresample_read().
347  *
348  * If converting sample rate, there may be data remaining in the internal
349  * resampling delay buffer. avresample_get_delay() tells the number of remaining
350  * samples. To get this data as output, call avresample_convert() with NULL
351  * input.
352  *
353  * At the end of the conversion process, there may be data remaining in the
354  * internal FIFO buffer. avresample_available() tells the number of remaining
355  * samples. To get this data as output, either call avresample_convert() with
356  * NULL input or call avresample_read().
357  *
358  * @see avresample_get_out_samples()
359  * @see avresample_read()
360  * @see avresample_get_delay()
361  *
362  * @param avr audio resample context
363  * @param output output data pointers
364  * @param out_plane_size output plane size, in bytes.
365  * This can be 0 if unknown, but that will lead to
366  * optimized functions not being used directly on the
367  * output, which could slow down some conversions.
368  * @param out_samples maximum number of samples that the output buffer can hold
369  * @param input input data pointers
370  * @param in_plane_size input plane size, in bytes
371  * This can be 0 if unknown, but that will lead to
372  * optimized functions not being used directly on the
373  * input, which could slow down some conversions.
374  * @param in_samples number of input samples to convert
375  * @return number of samples written to the output buffer,
376  * not including converted samples added to the internal
377  * output FIFO
378  */
380  int out_plane_size, int out_samples,
381  uint8_t * const *input, int in_plane_size,
382  int in_samples);
383 
384 /**
385  * Return the number of samples currently in the resampling delay buffer.
386  *
387  * When resampling, there may be a delay between the input and output. Any
388  * unconverted samples in each call are stored internally in a delay buffer.
389  * This function allows the user to determine the current number of samples in
390  * the delay buffer, which can be useful for synchronization.
391  *
392  * @see avresample_convert()
393  *
394  * @param avr audio resample context
395  * @return number of samples currently in the resampling delay buffer
396  */
398 
399 /**
400  * Return the number of available samples in the output FIFO.
401  *
402  * During conversion, if the user does not specify an output buffer or
403  * specifies an output buffer that is smaller than what is needed, remaining
404  * samples that are not written to the output are stored to an internal FIFO
405  * buffer. The samples in the FIFO can be read with avresample_read() or
406  * avresample_convert().
407  *
408  * @see avresample_read()
409  * @see avresample_convert()
410  *
411  * @param avr audio resample context
412  * @return number of samples available for reading
413  */
415 
416 /**
417  * Read samples from the output FIFO.
418  *
419  * During conversion, if the user does not specify an output buffer or
420  * specifies an output buffer that is smaller than what is needed, remaining
421  * samples that are not written to the output are stored to an internal FIFO
422  * buffer. This function can be used to read samples from that internal FIFO.
423  *
424  * @see avresample_available()
425  * @see avresample_convert()
426  *
427  * @param avr audio resample context
428  * @param output output data pointers. May be NULL, in which case
429  * nb_samples of data is discarded from output FIFO.
430  * @param nb_samples number of samples to read from the FIFO
431  * @return the number of samples written to output
432  */
433 int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples);
434 
435 /**
436  * Convert the samples in the input AVFrame and write them to the output AVFrame.
437  *
438  * Input and output AVFrames must have channel_layout, sample_rate and format set.
439  *
440  * The upper bound on the number of output samples is obtained through
441  * avresample_get_out_samples().
442  *
443  * If the output AVFrame does not have the data pointers allocated the nb_samples
444  * field will be set using avresample_get_out_samples() and av_frame_get_buffer()
445  * is called to allocate the frame.
446  *
447  * The output AVFrame can be NULL or have fewer allocated samples than required.
448  * In this case, any remaining samples not written to the output will be added
449  * to an internal FIFO buffer, to be returned at the next call to this function
450  * or to avresample_convert() or to avresample_read().
451  *
452  * If converting sample rate, there may be data remaining in the internal
453  * resampling delay buffer. avresample_get_delay() tells the number of
454  * remaining samples. To get this data as output, call this function or
455  * avresample_convert() with NULL input.
456  *
457  * At the end of the conversion process, there may be data remaining in the
458  * internal FIFO buffer. avresample_available() tells the number of remaining
459  * samples. To get this data as output, either call this function or
460  * avresample_convert() with NULL input or call avresample_read().
461  *
462  * If the AVAudioResampleContext configuration does not match the output and
463  * input AVFrame settings the conversion does not take place and depending on
464  * which AVFrame is not matching AVERROR_OUTPUT_CHANGED, AVERROR_INPUT_CHANGED
465  * or AVERROR_OUTPUT_CHANGED|AVERROR_INPUT_CHANGED is returned.
466  *
467  * @see avresample_get_out_samples()
468  * @see avresample_available()
469  * @see avresample_convert()
470  * @see avresample_read()
471  * @see avresample_get_delay()
472  *
473  * @param avr audio resample context
474  * @param output output AVFrame
475  * @param input input AVFrame
476  * @return 0 on success, AVERROR on failure or nonmatching
477  * configuration.
478  */
480  AVFrame *output, AVFrame *input);
481 
482 /**
483  * Configure or reconfigure the AVAudioResampleContext using the information
484  * provided by the AVFrames.
485  *
486  * The original resampling context is reset even on failure.
487  * The function calls avresample_close() internally if the context is open.
488  *
489  * @see avresample_open();
490  * @see avresample_close();
491  *
492  * @param avr audio resample context
493  * @param output output AVFrame
494  * @param input input AVFrame
495  * @return 0 on success, AVERROR on failure.
496  */
498 
499 /**
500  * @}
501  */
502 
503 #endif /* AVRESAMPLE_AVRESAMPLE_H */
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
Kaiser Windowed Sinc.
Definition: avresample.h:120
int avresample_convert_frame(AVAudioResampleContext *avr, AVFrame *output, AVFrame *input)
Convert the samples in the input AVFrame and write them to the output AVFrame.
Definition: utils.c:603
int avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t *const *input, int in_plane_size, int in_samples)
Convert input samples and write them to the output FIFO.
Definition: utils.c:330
Do not use dithering.
Definition: avresample.h:124
int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
Read samples from the output FIFO.
Definition: utils.c:772
external API header
int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, int compensation_distance)
Set compensation for resampling.
Definition: resample.c:233
32-bit 17.15 fixed-point
Definition: avresample.h:112
int avresample_set_channel_mapping(AVAudioResampleContext *avr, const int *channel_map)
Set a customized input channel mapping.
Definition: utils.c:697
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values.
Definition: utils.c:278
Triangular Dither with Noise Shaping.
Definition: avresample.h:128
double surround_mix_level
surround mix level
Definition: internal.h:65
const AVClass * avresample_get_class(void)
Get the AVClass for AVAudioResampleContext.
Definition: options.c:110
Rectangular Dither.
Definition: avresample.h:125
Triangular Dither with High Pass.
Definition: avresample.h:127
Public dictionary API.
uint8_t
const char * avresample_license(void)
Return the libavresample license.
Definition: utils.c:784
int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, int normalize, double *matrix, int stride, enum AVMatrixEncoding matrix_encoding)
Generate a channel mixing matrix.
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
Definition: utils.c:262
double center_mix_level
center mix level
Definition: internal.h:64
AVResampleFilterType
Resampling Filter Types.
Definition: avresample.h:117
reference-counted frame API
int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
Configure or reconfigure the AVAudioResampleContext using the information provided by the AVFrames...
Definition: utils.c:505
audio channel layout utility functions
int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, int stride)
Set channel mixing matrix.
Definition: utils.c:666
Triangular Dither.
Definition: avresample.h:126
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
Definition: resample.c:438
int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix, int stride)
Get the current channel mixing matrix.
Definition: utils.c:637
int avresample_available(AVAudioResampleContext *avr)
Return the number of available samples in the output FIFO.
Definition: utils.c:748
int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
Provide the upper bound on the number of samples the configured conversion would output.
Definition: utils.c:753
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
floating-point
Definition: avresample.h:113
const char * avresample_configuration(void)
Return the libavresample build-time configuration.
Definition: utils.c:790
Describe the class of an AVClass context structure.
Definition: log.h:67
Blackman Nuttall Windowed Sinc.
Definition: avresample.h:119
Number of dither types.
Definition: avresample.h:129
AVAudioResampleContext * avresample_alloc_context(void)
Allocate AVAudioResampleContext and set options.
Definition: options.c:96
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
enum AVMatrixEncoding matrix_encoding
matrixed stereo encoding
Definition: internal.h:97
16-bit 8.8 fixed-point
Definition: avresample.h:111
int avresample_is_open(AVAudioResampleContext *avr)
Check whether an AVAudioResampleContext is open or closed.
Definition: utils.c:257
AVMixCoeffType
Mixing Coefficient Types.
Definition: avresample.h:109
unsigned avresample_version(void)
Return the LIBAVRESAMPLE_VERSION_INT constant.
Definition: utils.c:779
FILE * out
Definition: movenc.c:54
AVMatrixEncoding
Libavresample version macros.
double lfe_mix_level
lfe mix level
Definition: internal.h:66
AVResampleDitherMethod
Definition: avresample.h:123
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
Definition: utils.c:36