Go to the documentation of this file.
71 #define OFFSET(x) offsetof(SpectrumSynthContext, x)
72 #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
73 #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
161 "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
163 ctx->inputs[1]->w,
ctx->inputs[1]->h);
165 }
else if (
av_cmp_q(time_base,
ctx->inputs[1]->time_base) != 0) {
167 "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
168 time_base.
num, time_base.
den,
169 ctx->inputs[1]->time_base.num,
170 ctx->inputs[1]->time_base.den);
172 }
else if (
av_cmp_q(frame_rate,
ctx->inputs[1]->frame_rate) != 0) {
174 "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
175 frame_rate.
num, frame_rate.
den,
176 ctx->inputs[1]->frame_rate.num,
177 ctx->inputs[1]->frame_rate.den);
184 for (fft_bits = 1; 1 << fft_bits < 2 *
s->size; fft_bits++);
186 s->win_size = 1 << fft_bits;
187 s->nb_freq = 1 << (fft_bits - 1);
192 "The window size might be too high.\n");
195 s->fft_data =
av_calloc(
s->channels,
sizeof(*
s->fft_data));
198 for (ch = 0; ch <
s->channels; ch++) {
199 s->fft_data[ch] =
av_calloc(
s->win_size,
sizeof(**
s->fft_data));
200 if (!
s->fft_data[ch])
210 sizeof(*
s->window_func_lut));
211 if (!
s->window_func_lut)
215 s->overlap = overlap;
216 s->hop_size = (1 -
s->overlap) *
s->win_size;
218 factor +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
220 s->factor = (
factor /
s->win_size) /
FFMAX(1 / (1 -
s->overlap) - 1, 1);
245 int x,
int y,
int f,
int ch)
247 const int m_linesize =
s->magnitude->linesize[0];
248 const int p_linesize =
s->phase->linesize[0];
249 const uint16_t *m = (uint16_t *)(
s->magnitude->data[0] + y * m_linesize);
250 const uint16_t *p = (uint16_t *)(
s->phase->data[0] + y * p_linesize);
251 float magnitude, phase;
255 magnitude = m[x] / (double)UINT16_MAX;
258 magnitude =
ff_exp10(((m[x] / (
double)UINT16_MAX) - 1.) * 6.);
263 phase = ((p[x] / (double)UINT16_MAX) * 2. - 1.) *
M_PI;
265 s->fft_data[ch][
f].re = magnitude * cos(phase);
266 s->fft_data[ch][
f].im = magnitude * sin(phase);
270 int x,
int y,
int f,
int ch)
272 const int m_linesize =
s->magnitude->linesize[0];
273 const int p_linesize =
s->phase->linesize[0];
274 const uint8_t *m = (
uint8_t *)(
s->magnitude->data[0] + y * m_linesize);
276 float magnitude, phase;
280 magnitude = m[x] / (double)UINT8_MAX;
283 magnitude =
ff_exp10(((m[x] / (
double)UINT8_MAX) - 1.) * 6.);
288 phase = ((p[x] / (double)UINT8_MAX) * 2. - 1.) *
M_PI;
290 s->fft_data[ch][
f].re = magnitude * cos(phase);
291 s->fft_data[ch][
f].im = magnitude * sin(phase);
298 int start =
h * (
s->channels - ch) - 1;
299 int end =
h * (
s->channels - ch - 1);
302 switch (
s->orientation) {
307 for (y = start,
f = 0; y >=
end; y--,
f++) {
314 for (y = start,
f = 0; y >=
end; y--,
f++) {
324 for (y =
end,
f = 0; y <= start; y++,
f++) {
331 for (y =
end,
f = 0; y <= start; y++,
f++) {
343 const int h =
s->size;
344 int nb =
s->win_size;
347 for (ch = 0; ch <
s->channels; ch++) {
350 for (y =
h; y <=
s->nb_freq; y++) {
351 s->fft_data[ch][y].re = 0;
352 s->fft_data[ch][y].im = 0;
355 for (y =
s->nb_freq + 1,
f =
s->nb_freq - 1; y < nb; y++,
f--) {
356 s->fft_data[ch][y].re =
s->fft_data[ch][
f].re;
357 s->fft_data[ch][y].im = -
s->fft_data[ch][
f].im;
369 const float factor =
s->factor;
376 for (ch = 0; ch <
s->channels; ch++) {
377 float *buf = (
float *)
s->buffer->extended_data[ch];
383 for (
i = 0, j = start; j < k &&
i <
s->win_size;
i++, j++) {
384 buf[j] +=
s->fft_data[ch][
i].re;
387 for (;
i <
s->win_size;
i++, j++) {
388 buf[j] =
s->fft_data[ch][
i].re;
391 start +=
s->hop_size;
394 if (start >=
s->win_size) {
395 start -=
s->win_size;
398 if (ch ==
s->channels - 1) {
410 s->pts +=
s->win_size;
411 for (
c = 0;
c <
s->channels;
c++) {
412 dst = (
float *)
out->extended_data[
c];
413 buf = (
float *)
s->buffer->extended_data[
c];
415 for (n = 0; n <
s->win_size; n++) {
418 memmove(buf, buf +
s->win_size,
s->win_size * 4);
439 if (!(
s->magnitude &&
s->phase))
442 switch (
s->sliding) {
446 if (
s->xpos >=
s->xend)
450 s->xpos =
s->xend - 1;
458 for (x = 0; x <
s->xend; x++) {
478 s->magnitude = magnitude;
501 for (
i = 0;
i <
s->channels;
i++)
535 .
name =
"spectrumsynth",
542 .priv_class = &spectrumsynth_class,
av_cold void av_fft_end(FFTContext *s)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
A list of supported channel layouts.
static int try_push_frames(AVFilterContext *ctx)
AVPixelFormat
Pixel format.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
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
struct AVFilterChannelLayouts * in_channel_layouts
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_cold int end(AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
static int request_frame(AVFilterLink *outlink)
const char * name
Filter name.
A link between two filters.
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
static int filter_frame_phase(AVFilterLink *inlink, AVFrame *phase)
static int config_output(AVFilterLink *outlink)
AVFILTER_DEFINE_CLASS(spectrumsynth)
#define AV_PIX_FMT_GRAY16
float * window_func_lut
Window function LUT.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int fft_bits
number of bits (FFT window size = 1<<fft_bits)
#define AV_PIX_FMT_YUV444P16
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
static void synth_window(AVFilterContext *ctx, int x)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define av_realloc_f(p, o, n)
AVFilter ff_vaf_spectrumsynth
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
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
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int try_push_frame(AVFilterContext *ctx, int x)
static const AVFilterPad spectrumsynth_outputs[]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVFilterPad spectrumsynth_inputs[]
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
FFTComplex ** fft_data
bins holder for each (displayed) channels
AVFilterContext * src
source filter
AVFilterFormats * out_formats
static void read16_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
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 layout
int sample_rate
samples per second
#define i(width, name, range_min, range_max)
AVSampleFormat
Audio sample formats.
static int filter_frame_magnitude(AVFilterLink *inlink, AVFrame *magnitude)
const char * name
Pad name.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
static int query_formats(AVFilterContext *ctx)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static const AVOption spectrumsynth_options[]
static void read8_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
FFTContext * fft
Fast Fourier Transform context.
static const int factor[16]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
static av_cold void uninit(AVFilterContext *ctx)