72 #define OFFSET(x) offsetof(SpectrumSynthContext, x) 73 #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM 74 #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 159 if (width != ctx->
inputs[1]->
w ||
162 "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
168 "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
169 time_base.
num, time_base.
den,
175 "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
176 frame_rate.
num, frame_rate.
den,
185 for (fft_bits = 1; 1 << fft_bits < 2 * s->
size; fft_bits++);
188 s->
nb_freq = 1 << (fft_bits - 1);
193 "The window size might be too high.\n");
199 for (ch = 0; ch < s->
channels; ch++) {
227 int x,
int y,
int f,
int ch)
231 const uint16_t *m = (uint16_t *)(s->
magnitude->
data[0] + y * m_linesize);
232 const uint16_t *p = (uint16_t *)(s->
phase->
data[0] + y * p_linesize);
237 magnitude = m[x] / (double)UINT16_MAX;
240 magnitude =
ff_exp10(((m[x] / (
double)UINT16_MAX) - 1.) * 6.);
245 phase = ((p[x] / (double)UINT16_MAX) * 2. - 1.) *
M_PI;
252 int x,
int y,
int f,
int ch)
262 magnitude = m[x] / (double)UINT8_MAX;
265 magnitude =
ff_exp10(((m[x] / (
double)UINT8_MAX) - 1.) * 6.);
270 phase = ((p[x] / (double)UINT8_MAX) * 2. - 1.) *
M_PI;
289 for (y = start, f = 0; y >=
end; y--, f++) {
296 for (y = start, f = 0; y >=
end; y--, f++) {
306 for (y = end, f = 0; y <=
start; y++, f++) {
313 for (y = end, f = 0; y <=
start; y++, f++) {
325 const int h = s->
size;
329 for (ch = 0; ch < s->
channels; ch++) {
332 for (y = h; y <= s->
nb_freq; y++) {
358 for (ch = 0; ch < s->
channels; ch++) {
365 for (i = 0, j = start; j < k && i < s->
win_size; i++, j++) {
440 for (x = 0; x < s->
xend; x++) {
464 for (i = 0; i < 2; i++) {
476 for (i = 0; i < 2; i++) {
485 for (i = 0; i < 2; i++) {
533 .
name =
"spectrumsynth",
539 .
inputs = spectrumsynth_inputs,
540 .
outputs = spectrumsynth_outputs,
541 .priv_class = &spectrumsynth_class,
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_realloc_f(p, o, n)
This structure describes decoded (raw) audio or video data.
av_cold void av_fft_end(FFTContext *s)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Main libavfilter public API header.
int h
agreed upon image height
AVFILTER_DEFINE_CLASS(spectrumsynth)
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
static const AVOption spectrumsynth_options[]
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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.
float * window_func_lut
Window function LUT.
FFTComplex ** fft_data
bins holder for each (displayed) channels
static int query_formats(AVFilterContext *ctx)
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
static const AVFilterPad spectrumsynth_outputs[]
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static int try_push_frames(AVFilterContext *ctx)
static void read16_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
#define AV_PIX_FMT_YUV444P16
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function.If this function returns true
A filter pad used for either input or output.
A link between two filters.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
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.
static void read8_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
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.
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
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static const AVFilterPad spectrumsynth_inputs[]
simple assert() macros that are a bit more flexible than ISO C assert().
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
static int activate(AVFilterContext *ctx)
int w
agreed upon image width
FFTContext * fft
Fast Fourier Transform context.
audio channel layout utility functions
#define AV_PIX_FMT_GRAY16
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
int format
agreed upon media format
A list of supported channel layouts.
static av_cold void uninit(AVFilterContext *ctx)
AVSampleFormat
Audio sample formats.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
int fft_bits
number of bits (FFT window size = 1<<fft_bits)
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
internal math functions header
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
static int try_push_frame(AVFilterContext *ctx, int x)
AVFilter ff_vaf_spectrumsynth
static enum AVSampleFormat sample_fmts[]
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.
static int config_output(AVFilterLink *outlink)
static void synth_window(AVFilterContext *ctx, int x)
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
AVPixelFormat
Pixel format.
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