32 #define MAX_CHANNELS 8
38 return "audioresample";
69 q[0] = (p[0] + p[1]) >> 1;
70 q[1] = (p[2] + p[3]) >> 1;
71 q[2] = (p[4] + p[5]) >> 1;
72 q[3] = (p[6] + p[7]) >> 1;
78 q[0] = (p[0] + p[1]) >> 1;
95 v = p[0]; q[0] =
v; q[1] =
v;
96 v = p[1]; q[2] =
v; q[3] =
v;
97 v = p[2]; q[4] =
v; q[5] =
v;
98 v = p[3]; q[6] =
v; q[7] =
v;
104 v = p[0]; q[0] =
v; q[1] =
v;
115 for (i = 0; i <
samples; i++) {
116 for (j = 0; j < channels; j++) {
117 *output[j]++ = *input++;
126 for (i = 0; i <
samples; i++) {
127 for (j = 0; j < channels; j++) {
128 *output++ = *input[j]++;
133 static void ac3_5p1_mux(
short *output,
short *input1,
short *input2,
int n)
138 for (i = 0; i < n; i++) {
142 *output++ = (l / 2) + (r / 2);
151 int output_rate,
int input_rate,
155 int linear,
double cutoff)
161 "Resampling with input channels greater than %d is unsupported.\n",
165 if (output_channels != input_channels &&
166 (input_channels > 2 ||
167 output_channels > 2 &&
168 !(output_channels == 6 && input_channels == 2))) {
170 "Resampling output channel count must be 1 or 2 for mono input; 1, 2 or 6 for stereo input; or N for N channel input.\n");
180 s->
ratio = (float)output_rate / (
float)input_rate;
198 "Cannot convert %s sample format to s16 sample format\n",
209 "Cannot convert s16 sample format to %s sample format\n",
218 filter_length, log2_phase_count,
234 short *output_bak =
NULL;
239 memcpy(output, input, nb_samples * s->
input_channels *
sizeof(
short));
245 int ostride[1] = { 2 };
246 const void *ibuf[1] = { input };
265 "Audio sample format conversion failed\n");
272 lenout = 4 * nb_samples * s->
ratio + 16;
293 memcpy(bufin[i], s->
temp[i], s->
temp_len *
sizeof(
short));
294 buftmp2[i] = bufin[i] + s->
temp_len;
295 bufout[i] =
av_malloc(lenout *
sizeof(
short));
302 buftmp3[0] = bufout[0];
303 memcpy(buftmp2[0], input, nb_samples *
sizeof(
short));
306 buftmp3[i] = bufout[i];
311 memcpy(buftmp2[0], input, nb_samples *
sizeof(
short));
323 &consumed, nb_samples, lenout, is_last);
324 s->
temp_len = nb_samples - consumed;
326 memcpy(s->
temp[i], bufin[i] + consumed, s->
temp_len *
sizeof(
short));
332 ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
338 int istride[1] = { 2 };
340 const void *ibuf[1] = { output };
341 void *obuf[1] = { output_bak };
346 "Audio sample format convertion failed\n");
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVAudioConvert * convert_ctx[2]
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
static void interleave(short *output, short **input, int channels, int samples)
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.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
void av_resample_close(struct AVResampleContext *c)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
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.
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 AVOption options[]
static void deinterleave(short **output, short *input, int channels, int samples)
static const char * context_to_name(void *ptr)
static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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
void audio_resample_close(ReSampleContext *s)
Free resample context.
void av_log(void *avcl, int level, const char *fmt,...)
short * buffer[2]
buffers used for conversion to S16
unsigned buffer_size[2]
sizes of allocated buffers
short * temp[MAX_CHANNELS]
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.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
unsigned sample_size[2]
size of one sample in sample_fmt
Audio format conversion routines.
static void mono_to_stereo(short *output, short *input, int n1)
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.
AVSampleFormat
all in native-endian format
struct AVResampleContext * resample_context
static void stereo_to_mono(short *output, short *input, int n1)
void av_audio_convert_free(AVAudioConvert *ctx)
Free audio sample format converter context.