35 #if FF_API_AVCODEC_RESAMPLE
38 #define MAX_CHANNELS 8
44 return "audioresample";
75 q[0] = (p[0] + p[1]) >> 1;
76 q[1] = (p[2] + p[3]) >> 1;
77 q[2] = (p[4] + p[5]) >> 1;
78 q[3] = (p[6] + p[7]) >> 1;
84 q[0] = (p[0] + p[1]) >> 1;
101 v = p[0]; q[0] = v; q[1] = v;
102 v = p[1]; q[2] = v; q[3] = v;
103 v = p[2]; q[4] = v; q[5] = v;
104 v = p[3]; q[6] = v; q[7] = v;
110 v = p[0]; q[0] = v; q[1] = v;
129 for (i = 0; i < samples; i++) {
138 l = av_clip_int16(fl + (0.5 * rl) + (0.7 * c));
139 r = av_clip_int16(fr + (0.5 * rr) + (0.7 * c));
150 static void deinterleave(
short **output,
short *input,
int channels,
int samples)
154 for (i = 0; i < samples; i++) {
155 for (j = 0; j < channels; j++) {
156 *output[j]++ = *input++;
161 static void interleave(
short *output,
short **input,
int channels,
int samples)
165 for (i = 0; i < samples; i++) {
166 for (j = 0; j < channels; j++) {
167 *output++ = *input[j]++;
172 static void ac3_5p1_mux(
short *output,
short *input1,
short *input2,
int n)
177 for (i = 0; i <
n; i++) {
181 *output++ = (l / 2) + (r / 2);
189 #define SUPPORT_RESAMPLE(ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8) \
190 ch8<<7 | ch7<<6 | ch6<<5 | ch5<<4 | ch4<<3 | ch3<<2 | ch2<<1 | ch1<<0
205 int output_rate,
int input_rate,
209 int linear,
double cutoff)
215 "Resampling with input channels greater than %d is unsupported.\n",
222 "output channels for %d input channel%s", input_channels,
223 input_channels > 1 ?
"s:" :
":");
237 s->
ratio = (float)output_rate / (
float)input_rate;
255 "Cannot convert %s sample format to s16 sample format\n",
266 "Cannot convert s16 sample format to %s sample format\n",
275 filter_length, log2_phase_count,
291 short *output_bak =
NULL;
296 int ostride[1] = { 2 };
297 const void *ibuf[1] = { input };
316 "Audio sample format conversion failed\n");
348 if (!bufin[i] || !bufout[i]) {
354 memcpy(bufin[i], s->
temp[i], s->
temp_len *
sizeof(
short));
355 buftmp2[i] = bufin[i] + s->
temp_len;
362 buftmp3[0] = bufout[0];
363 memcpy(buftmp2[0], input, nb_samples *
sizeof(
short));
365 buftmp3[0] = bufout[0];
366 buftmp3[1] = bufout[1];
370 buftmp3[i] = bufout[i];
375 memcpy(buftmp2[0], input, nb_samples *
sizeof(
short));
387 &consumed, nb_samples, lenout, is_last);
388 s->
temp_len = nb_samples - consumed;
390 memcpy(s->
temp[i], bufin[i] + consumed, s->
temp_len *
sizeof(
short));
396 ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
403 int istride[1] = { 2 };
405 const void *ibuf[1] = { output };
406 void *obuf[1] = { output_bak };
411 "Audio sample format conversion failed\n");
static const uint8_t supported_resampling[MAX_CHANNELS]
static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
AVAudioConvert * convert_ctx[2]
static void deinterleave(short **output, short *input, int channels, int samples)
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
#define LIBAVUTIL_VERSION_INT
Memory handling functions.
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
static void stereo_to_mono(short *output, short *input, int n1)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
attribute_deprecated int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx)
Resample an array of samples using a previously configured context.
static const char * context_to_name(void *ptr)
static void surround_to_stereo(short **output, short *input, int channels, int samples)
static void mono_to_stereo(short *output, short *input, int n1)
attribute_deprecated void av_resample_close(struct AVResampleContext *c)
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_audio_convert(AVAudioConvert *ctx, void *const out[6], const int out_stride[6], const void *const in[6], const int in_stride[6], int len)
Convert between audio sample formats.
enum AVSampleFormat sample_fmt[2]
input and output sample format
static const AVClass audioresample_context_class
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
short * buffer[2]
buffers used for conversion to S16
unsigned buffer_size[2]
sizes of allocated buffers
short * temp[MAX_CHANNELS]
#define SUPPORT_RESAMPLE(ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8)
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
ReSampleContext * av_audio_resample_init(int output_channels, int input_channels, int output_rate, int input_rate, enum AVSampleFormat sample_fmt_out, enum AVSampleFormat sample_fmt_in, int filter_length, int log2_phase_count, int linear, double cutoff)
Initialize audio resampling context.
Describe the class of an AVClass context structure.
void audio_resample_close(ReSampleContext *s)
Free resample context.
unsigned sample_size[2]
size of one sample in sample_fmt
static void interleave(short *output, short **input, int channels, int samples)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Audio format conversion routines This interface is deprecated and will be dropped in a future version...
attribute_deprecated struct AVResampleContext * av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff)
Initialize an audio resampler.
#define FF_DISABLE_DEPRECATION_WARNINGS
AVAudioConvert * av_audio_convert_alloc(enum AVSampleFormat out_fmt, int out_channels, enum AVSampleFormat in_fmt, int in_channels, const float *matrix, int flags)
Create an audio sample format converter context.
static const AVOption options[]
struct AVResampleContext * resample_context
#define FF_ENABLE_DEPRECATION_WARNINGS
#define av_malloc_array(a, b)
void av_audio_convert_free(AVAudioConvert *ctx)
Free audio sample format converter context.