71 #define OFFSET(x) offsetof(CompandContext, x) 72 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 75 {
"attacks",
"set time over which increase of volume is determined",
OFFSET(attacks),
AV_OPT_TYPE_STRING, { .str =
"0" }, 0, 0,
A },
76 {
"decays",
"set time over which decrease of volume is determined",
OFFSET(decays),
AV_OPT_TYPE_STRING, { .str =
"0.8" }, 0, 0,
A },
77 {
"points",
"set points of transfer function",
OFFSET(points),
AV_OPT_TYPE_STRING, { .str =
"-70/-70|-60/-20|1/0" }, 0, 0,
A },
81 {
"delay",
"set delay for samples before sending them to volume adjuster",
OFFSET(delay),
AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, 20,
A },
138 for (p = item_str; *p; p++) {
139 if (*p ==
' ' || *p ==
'|')
157 double in_log, out_log;
160 if (in_lin < s->in_min_lin)
163 in_log = log(in_lin);
166 if (in_log <= s->segments[i].x)
170 out_log = cs->
y + in_log * (cs->
a * in_log + cs->
b);
201 for (chan = 0; chan <
channels; chan++) {
206 for (i = 0; i < nb_samples; i++) {
213 if (frame != out_frame)
219 #define MOD(a, b) (((a) >= (b)) ? (a) - (b) : (a)) 237 for (chan = 0; chan <
channels; chan++) {
246 for (i = 0, oindex = 0; i < nb_samples; i++) {
247 const double in = src[
i];
310 for (chan = 0; chan <
channels; chan++) {
334 char *p, *saveptr =
NULL;
336 int nb_attacks, nb_decays, nb_points;
337 int new_nb_items, num;
351 if (nb_attacks > channels || nb_decays > channels) {
353 "Number of attacks/decays bigger than number of channels. Ignoring rest of entries.\n");
354 nb_attacks =
FFMIN(nb_attacks, channels);
355 nb_decays =
FFMIN(nb_decays, channels);
370 for (i = 0, new_nb_items = 0; i < nb_attacks; i++) {
371 char *tstr =
av_strtok(p,
" |", &saveptr);
383 nb_attacks = new_nb_items;
386 for (i = 0, new_nb_items = 0; i < nb_decays; i++) {
387 char *tstr =
av_strtok(p,
" |", &saveptr);
393 new_nb_items += sscanf(tstr,
"%lf", &s->
channels[i].
decay) == 1;
399 nb_decays = new_nb_items;
401 if (nb_attacks != nb_decays) {
403 "Number of attacks %d differs from number of decays %d.\n",
404 nb_attacks, nb_decays);
409 for (i = nb_decays; i <
channels; i++) {
414 #define S(x) s->segments[2 * ((x) + 1)] 416 for (i = 0, new_nb_items = 0; i < nb_points; i++) {
417 char *tstr =
av_strtok(p,
" |", &saveptr);
419 if (!tstr || sscanf(tstr,
"%lf/%lf", &
S(i).x, &
S(i).y) != 2) {
421 "Invalid and/or missing input/output value.\n");
425 if (i &&
S(i - 1).x >
S(i).x) {
427 "Transfer function input values must be increasing.\n");
438 if (num == 0 ||
S(num - 1).x)
442 #define S(x) s->segments[2 * (x)] 449 for (i = 2; i < num; i++) {
450 double g1 = (
S(i - 1).y -
S(i - 2).y) * (
S(i - 0).x -
S(i - 1).x);
451 double g2 = (
S(i - 0).y -
S(i - 1).y) * (
S(i - 1).x -
S(i - 2).x);
457 for (j = --i; j < num; j++)
467 #define L(x) s->segments[i - (x)] 469 double x, y, cx, cy, in1, in2, out1, out2, theta,
len,
r;
472 L(4).b = (
L(2).y -
L(4).y) / (
L(2).x -
L(4).x);
475 L(2).b = (
L(0).y -
L(2).y) / (
L(0).x -
L(2).x);
477 theta = atan2(
L(2).y -
L(4).y,
L(2).x -
L(4).x);
478 len =
hypot(
L(2).x -
L(4).x,
L(2).y -
L(4).y);
479 r =
FFMIN(radius, len);
480 L(3).x =
L(2).x - r * cos(theta);
481 L(3).y =
L(2).y - r * sin(theta);
483 theta = atan2(
L(0).y -
L(2).y,
L(0).x -
L(2).x);
484 len =
hypot(
L(0).x -
L(2).x,
L(0).y -
L(2).y);
485 r =
FFMIN(radius, len / 2);
486 x =
L(2).x + r * cos(theta);
487 y =
L(2).y + r * sin(theta);
489 cx = (
L(3).x +
L(2).x + x) / 3;
490 cy = (
L(3).y +
L(2).y + y) / 3;
497 in2 =
L(2).x -
L(3).x;
498 out2 =
L(2).y -
L(3).y;
499 L(3).a = (out2 / in2 - out1 / in1) / (in2 - in1);
500 L(3).b = out1 / in1 -
L(3).a * in1;
511 if (cp->
attack > 1.0 / sample_rate)
515 if (cp->
decay > 1.0 / sample_rate)
591 "Compress or expand audio dynamic range."),
594 .priv_class = &compand_class,
static const AVFilterPad compand_inputs[]
This structure describes decoded (raw) audio or video data.
static const AVOption compand_options[]
#define AV_LOG_WARNING
Something somehow does not look correct.
static double get_volume(CompandContext *s, double in_lin)
Main libavfilter public API header.
AVFILTER_DEFINE_CLASS(compand)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static const AVFilterPad compand_outputs[]
static void update_volume(ChanParam *cp, double in)
int is_disabled
the enabled state from the last expression evaluation
static av_cold int init(AVFilterContext *ctx)
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.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int compand_delay(AVFilterContext *ctx, AVFrame *frame)
static int query_formats(AVFilterContext *ctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AVERROR_EOF
End of file.
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 compand_nodelay(AVFilterContext *ctx, AVFrame *frame)
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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 __device__ float fabs(float a)
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. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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().
uint64_t channel_layout
Channel layout of the audio data.
static int request_frame(AVFilterLink *outlink)
static av_const double hypot(double x, double y)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int(* compand)(AVFilterContext *ctx, AVFrame *frame)
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 For filters that do not use the this method is called when a frame is wanted on an output For a 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 or at least make progress towards producing a frame
CompandSegment * segments
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
int format
agreed upon media format
A list of supported channel layouts.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
AVSampleFormat
Audio sample formats.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
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 inputs
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=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;}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_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);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_log(ac->avr, AV_LOG_TRACE,"%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-> in
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
static av_cold void uninit(AVFilterContext *ctx)
internal math functions header
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int channels
Number of channels.
static int config_output(AVFilterLink *outlink)
static int compand_drain(AVFilterLink *outlink)
AVFilterContext * dst
dest filter
static void count_items(char *item_str, int *nb_items)
static enum AVSampleFormat sample_fmts[]
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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.Frame references ownership and permissions
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz_array(size_t nmemb, size_t size)