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
158 if (width != ctx->
inputs[1]->
w ||
161 "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
167 "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
168 time_base.
num, time_base.
den,
174 "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
175 frame_rate.
num, frame_rate.
den,
184 for (fft_bits = 1; 1 << fft_bits < 2 * s->
size; fft_bits++);
187 s->
nb_freq = 1 << (fft_bits - 1);
192 "The window size might be too high.\n");
198 for (ch = 0; ch < s->
channels; ch++) {
245 int x,
int y,
int f,
int ch)
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)
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);
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;
347 for (ch = 0; ch < s->
channels; ch++) {
350 for (y = h; y <= s->
nb_freq; y++) {
376 for (ch = 0; ch < s->
channels; ch++) {
383 for (i = 0, j = start; j < k && i < s->
win_size; i++, j++) {
456 for (x = 0; x < s->
xend; x++) {
533 .
name =
"spectrumsynth",
538 .
inputs = spectrumsynth_inputs,
539 .
outputs = spectrumsynth_outputs,
540 .priv_class = &spectrumsynth_class,
#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)
Main libavfilter public API header.
int h
agreed upon image height
AVFILTER_DEFINE_CLASS(spectrumsynth)
static enum AVSampleFormat formats[]
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
static const AVOption spectrumsynth_options[]
struct AVFilterChannelLayouts * in_channel_layouts
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 av_cold int end(AVCodecContext *avctx)
static int query_formats(AVFilterContext *ctx)
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
A filter pad used for either input or output.
A link between two filters.
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.
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
static const int sample_rates[]
int w
agreed upon image width
FFTContext * fft
Fast Fourier Transform context.
audio channel layout utility functions
#define AV_PIX_FMT_GRAY16
static int filter_frame_magnitude(AVFilterLink *inlink, AVFrame *magnitude)
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)
static const AVFilterPad inputs[]
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
AVSampleFormat
Audio sample formats.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Describe the class of an AVClass context structure.
void ff_generate_window_func(float *lut, int N, int win_func, float *overlap)
rational number numerator/denominator
int fft_bits
number of bits (FFT window size = 1<<fft_bits)
static const int factor[16]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int request_frame(AVFilterLink *outlink)
internal math functions header
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static int try_push_frame(AVFilterContext *ctx, int x)
AVFilter ff_vaf_spectrumsynth
AVFilterContext * dst
dest filter
static enum AVSampleFormat sample_fmts[]
static int filter_frame_phase(AVFilterLink *inlink, AVFrame *phase)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
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.
AVFilterFormats * out_formats