audio_mix.c File Reference
#include <stdint.h>
#include "libavutil/common.h"
#include "libavutil/libm.h"
#include "libavutil/samplefmt.h"
#include "avresample.h"
#include "internal.h"
#include "audio_data.h"
#include "audio_mix.h"
Include dependency graph for audio_mix.c:

Go to the source code of this file.

Data Structures

struct  AudioMix
 

Macros

#define MIX_FUNC_NAME(fmt, cfmt)   mix_any_ ## fmt ##_## cfmt ##_c
 
#define MIX_FUNC_GENERIC(fmt, cfmt, stype, ctype, sumtype, expr)
 
#define GET_MATRIX_CONVERT(suffix, scale)
 
#define CONVERT_MATRIX(type, expr)
 

Functions

void ff_audio_mix_set_func (AudioMix *am, enum AVSampleFormat fmt, enum AVMixCoeffType coeff_type, int in_channels, int out_channels, int ptr_align, int samples_align, const char *descr, void *mix_func)
 Set mixing function if the parameters match. More...
 
 MIX_FUNC_GENERIC (S16P, FLT, int16_t, float, float, av_clip_int16(lrintf(sum)))
 
static void mix_2_to_1_s16p_flt_c (int16_t **samples, float **matrix, int len, int out_ch, int in_ch)
 
static void mix_2_to_1_s16p_q8_c (int16_t **samples, int16_t **matrix, int len, int out_ch, int in_ch)
 
static void mix_1_to_2_fltp_flt_c (float **samples, float **matrix, int len, int out_ch, int in_ch)
 
static void mix_6_to_2_fltp_flt_c (float **samples, float **matrix, int len, int out_ch, int in_ch)
 
static void mix_2_to_6_fltp_flt_c (float **samples, float **matrix, int len, int out_ch, int in_ch)
 
static int mix_function_init (AudioMix *am)
 
AudioMixff_audio_mix_alloc (AVAudioResampleContext *avr)
 Allocate and initialize an AudioMix context. More...
 
void ff_audio_mix_free (AudioMix **am_p)
 Free an AudioMix context. More...
 
int ff_audio_mix (AudioMix *am, AudioData *src)
 Apply channel mixing to audio data using the current mixing matrix. More...
 
int ff_audio_mix_get_matrix (AudioMix *am, double *matrix, int stride)
 Get the current mixing matrix. More...
 
static void reduce_matrix (AudioMix *am, const double *matrix, int stride)
 
int ff_audio_mix_set_matrix (AudioMix *am, const double *matrix, int stride)
 Set the current mixing matrix. More...
 

Variables

static const char * coeff_type_names [] = { "q8", "q15", "flt" }
 

Macro Definition Documentation

#define CONVERT_MATRIX (   type,
  expr 
)
Value:
am->matrix_## type[0] = av_mallocz(am->out_matrix_channels * \
am->in_matrix_channels * \
sizeof(*am->matrix_## type[0])); \
if (!am->matrix_## type[0]) \
return AVERROR(ENOMEM); \
for (o = 0, o0 = 0; o < am->out_channels; o++) { \
if (am->output_zero[o] || am->output_skip[o]) \
if (o0 > 0) \
am->matrix_## type[o0] = am->matrix_## type[o0 - 1] + \
am->in_matrix_channels; \
for (i = 0, i0 = 0; i < am->in_channels; i++) { \
double v; \
if (am->input_skip[i]) \
v = matrix[o * stride + i]; \
am->matrix_## type[o0][i0] = expr; \
i0++; \
} \
o0++; \
} \
am->matrix = (void **)am->matrix_## type;
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
float v
int stride
Definition: mace.c:144
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
loc<=1||loc >=hN-1 continue()
synthesis window for stochastic i
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define type
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return it should return
for(j=16;j >0;--j)

Referenced by ff_audio_mix_set_matrix().

#define GET_MATRIX_CONVERT (   suffix,
  scale 
)
Value:
if (!am->matrix_ ## suffix[0]) { \
av_log(am->avr, AV_LOG_ERROR, "matrix is not set\n"); \
return AVERROR(EINVAL); \
} \
for (o = 0, o0 = 0; o < am->out_channels; o++) { \
for (i = 0, i0 = 0; i < am->in_channels; i++) { \
if (am->input_skip[i] || am->output_zero[o]) \
matrix[o * stride + i] = 0.0; \
else \
matrix[o * stride + i] = am->matrix_ ## suffix[o0][i0] * \
(scale); \
if (!am->input_skip[i]) \
i0++; \
} \
if (!am->output_zero[o]) \
o0++; \
}
int stride
Definition: mace.c:144
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
synthesis window for stochastic i
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
Same thing on a dB scale
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return it should return
for(j=16;j >0;--j)

Referenced by ff_audio_mix_get_matrix().

#define MIX_FUNC_GENERIC (   fmt,
  cfmt,
  stype,
  ctype,
  sumtype,
  expr 
)
Value:
static void MIX_FUNC_NAME(fmt, cfmt)(stype **samples, ctype **matrix, \
int len, int out_ch, int in_ch) \
{ \
int i, in, out; \
for (i = 0; i < len; i++) { \
for (out = 0; out < out_ch; out++) { \
sumtype sum = 0; \
for (in = 0; in < in_ch; in++) \
sum += samples[in][i] * matrix[out][in]; \
temp[out] = expr; \
} \
for (out = 0; out < out_ch; out++) \
samples[out][i] = temp[out]; \
} \
}
#define MIX_FUNC_NAME(fmt, cfmt)
Definition: audio_mix.c:99
const char * fmt
Definition: avisynth_c.h:669
else temp
Definition: vf_mcdeint.c:148
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
#define AVRESAMPLE_MAX_CHANNELS
Definition: avresample.h:103
synthesis window for stochastic i
int len
Filter the word “frame” indicates either a video frame or a group of audio samples
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
for(j=16;j >0;--j)

Definition at line 101 of file audio_mix.c.

#define MIX_FUNC_NAME (   fmt,
  cfmt 
)    mix_any_ ## fmt ##_## cfmt ##_c

Definition at line 99 of file audio_mix.c.

Referenced by mix_function_init().

Function Documentation

int ff_audio_mix ( AudioMix am,
AudioData src 
)

Apply channel mixing to audio data using the current mixing matrix.

Definition at line 428 of file audio_mix.c.

Referenced by avresample_convert().

AudioMix* ff_audio_mix_alloc ( AVAudioResampleContext avr)

Allocate and initialize an AudioMix context.

The parameters in the AVAudioResampleContext are used to initialize the AudioMix context.

Parameters
avrAVAudioResampleContext
Returns
newly-allocated AudioMix context.

Definition at line 341 of file audio_mix.c.

Referenced by avresample_open().

void ff_audio_mix_free ( AudioMix **  am_p)

Free an AudioMix context.

Definition at line 409 of file audio_mix.c.

Referenced by avresample_close().

int ff_audio_mix_get_matrix ( AudioMix am,
double *  matrix,
int  stride 
)

Get the current mixing matrix.

Definition at line 483 of file audio_mix.c.

Referenced by avresample_get_matrix().

void ff_audio_mix_set_func ( AudioMix am,
enum AVSampleFormat  fmt,
enum AVMixCoeffType  coeff_type,
int  in_channels,
int  out_channels,
int  ptr_align,
int  samples_align,
const char *  descr,
void mix_func 
)

Set mixing function if the parameters match.

This compares the parameters of the mixing function to the parameters in the AudioMix context. If the parameters do not match, no changes are made to the active functions. If the parameters do match and the alignment is not constrained, the function is set as the generic mixing function. If the parameters match and the alignment is constrained, the function is set as the optimized mixing function.

Parameters
amAudioMix context
fmtinput/output sample format
coeff_typemixing coefficient type
in_channelsnumber of input channels, or 0 for any number of channels
out_channelsnumber of output channels, or 0 for any number of channels
ptr_alignbuffer pointer alignment, in bytes
samples_alignbuffer size alignment, in samples
descrfunction type description (e.g. "C" or "SSE")
mix_funcmixing function pointer

Definition at line 61 of file audio_mix.c.

Referenced by ff_audio_mix_init_x86(), and mix_function_init().

int ff_audio_mix_set_matrix ( AudioMix am,
const double *  matrix,
int  stride 
)

Set the current mixing matrix.

Definition at line 650 of file audio_mix.c.

Referenced by avresample_set_matrix(), and ff_audio_mix_alloc().

static void mix_1_to_2_fltp_flt_c ( float **  samples,
float **  matrix,
int  len,
int  out_ch,
int  in_ch 
)
static

Definition at line 192 of file audio_mix.c.

Referenced by mix_function_init().

static void mix_2_to_1_s16p_flt_c ( int16_t **  samples,
float **  matrix,
int  len,
int  out_ch,
int  in_ch 
)
static

Definition at line 148 of file audio_mix.c.

Referenced by mix_function_init().

static void mix_2_to_1_s16p_q8_c ( int16_t **  samples,
int16_t **  matrix,
int  len,
int  out_ch,
int  in_ch 
)
static

Definition at line 170 of file audio_mix.c.

Referenced by mix_function_init().

static void mix_2_to_6_fltp_flt_c ( float **  samples,
float **  matrix,
int  len,
int  out_ch,
int  in_ch 
)
static

Definition at line 259 of file audio_mix.c.

Referenced by mix_function_init().

static void mix_6_to_2_fltp_flt_c ( float **  samples,
float **  matrix,
int  len,
int  out_ch,
int  in_ch 
)
static

Definition at line 225 of file audio_mix.c.

Referenced by mix_function_init().

MIX_FUNC_GENERIC ( S16P  ,
FLT  ,
int16_t  ,
float  ,
float  ,
av_clip_int16(lrintf(sum))   
)

Definition at line 120 of file audio_mix.c.

static int mix_function_init ( AudioMix am)
static

Definition at line 285 of file audio_mix.c.

Referenced by ff_audio_mix_set_matrix().

static void reduce_matrix ( AudioMix am,
const double *  matrix,
int  stride 
)
static

Definition at line 530 of file audio_mix.c.

Referenced by ff_audio_mix_set_matrix().

Variable Documentation

const char* coeff_type_names[] = { "q8", "q15", "flt" }
static

Definition at line 31 of file audio_mix.c.

Referenced by ff_audio_mix_set_func(), and mix_function_init().