FFmpeg
Loading...
Searching...
No Matches
avf_showspectrum.c File Reference

audio to spectrum (video) transmedia filter, based on ffplay rdft showmode (by Michael Niedermayer) and lavfi/avf_showwaves (by Stefano Sabatini). More...

#include "config_components.h"
#include <float.h>
#include <math.h>
#include <stdio.h>
#include "libavutil/mem.h"
#include "libavutil/tx.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/cpu.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/xga_font_data.h"
#include "audio.h"
#include "formats.h"
#include "video.h"
#include "avfilter.h"
#include "filters.h"
#include "window_func.h"

Go to the source code of this file.

Data Structures

struct  ShowSpectrumContext
 
struct  ColorTable
 

Macros

#define DEFAULT_LENGTH   300
 
#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define RE(y, ch)
 
#define IM(y, ch)
 
#define MAGNITUDE(y, ch)
 
#define PHASE(y, ch)
 

Enumerations

enum  DisplayMode { COMBINED , SEPARATE , NB_MODES }
 
enum  DataMode { D_MAGNITUDE , D_PHASE , D_UPHASE , NB_DMODES }
 
enum  FrequencyScale { F_LINEAR , F_LOG , NB_FSCALES }
 
enum  DisplayScale {
  LINEAR , SQRT , CBRT , LOG ,
  FOURTHRT , FIFTHRT , NB_SCALES
}
 
enum  ColorMode {
  CHANNEL , INTENSITY , RAINBOW , MORELAND ,
  NEBULAE , FIRE , FIERY , FRUIT ,
  COOL , MAGMA , GREEN , VIRIDIS ,
  PLASMA , CIVIDIS , TERRAIN , NB_CLMODES
}
 
enum  SlideMode {
  REPLACE , SCROLL , FULLFRAME , RSCROLL ,
  LREPLACE , NB_SLIDES
}
 
enum  Orientation { VERTICAL , HORIZONTAL , NB_ORIENTATIONS }
 

Functions

 AVFILTER_DEFINE_CLASS (showspectrum)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
static int run_channel_fft (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static void drawtext (AVFrame *pic, int x, int y, const char *txt, int o)
 
static void color_range (ShowSpectrumContext *s, int ch, float *yf, float *uf, float *vf)
 
static void pick_color (ShowSpectrumContext *s, float yf, float uf, float vf, float a, float *out)
 
static char * get_time (AVFilterContext *ctx, float seconds, int x)
 
static float log_scale (const float bin, const float bmin, const float bmax, const float min, const float max)
 
static float get_hz (const float bin, const float bmax, const float min, const float max, int fscale)
 
static float inv_log_scale (float bin, float bmin, float bmax, float min, float max)
 
static float bin_pos (const int bin, const int num_bins, const float min, const float max)
 
static float get_scale (AVFilterContext *ctx, int scale, float a)
 
static float get_iscale (AVFilterContext *ctx, int scale, float a)
 
static int draw_legend (AVFilterContext *ctx, uint64_t samples)
 
static float get_value (AVFilterContext *ctx, int ch, int y)
 
static int plot_channel_lin (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int plot_channel_log (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int config_output (AVFilterLink *outlink)
 
static int calc_channel_magnitudes (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int calc_channel_phases (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static void unwrap (float *x, int N, float tol, float *mi, float *ma)
 
static int calc_channel_uphases (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static void acalc_magnitudes (ShowSpectrumContext *s)
 
static void scale_magnitudes (ShowSpectrumContext *s, float scale)
 
static void clear_combine_buffer (ShowSpectrumContext *s, int size)
 
static int plot_spectrum_column (AVFilterLink *inlink, AVFrame *insamples)
 

Variables

static const AVOption showspectrum_options []
 
static const struct ColorTable color_table [][8]
 

Detailed Description

audio to spectrum (video) transmedia filter, based on ffplay rdft showmode (by Michael Niedermayer) and lavfi/avf_showwaves (by Stefano Sabatini).

Definition in file avf_showspectrum.c.

Macro Definition Documentation

◆ DEFAULT_LENGTH

#define DEFAULT_LENGTH   300

Definition at line 59 of file avf_showspectrum.c.

Referenced by config_output(), and init().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 123 of file avf_showspectrum.c.

◆ FLAGS

Definition at line 124 of file avf_showspectrum.c.

◆ RE

#define RE ( y,
ch )
Value:
s->fft_data[ch][y].re
#define s(width, name)
Definition cbs_vp9.c:198

Definition at line 1304 of file avf_showspectrum.c.

◆ IM

#define IM ( y,
ch )
Value:
s->fft_data[ch][y].im

Definition at line 1305 of file avf_showspectrum.c.

◆ MAGNITUDE

#define MAGNITUDE ( y,
ch )
Value:
hypotf(RE(y, ch), IM(y, ch))
#define IM(x, ch)
#define RE(x, ch)

Definition at line 1306 of file avf_showspectrum.c.

Referenced by acalc_magnitudes(), calc_channel_magnitudes(), plot_freqs(), and query_formats().

◆ PHASE

#define PHASE ( y,
ch )
Value:
atan2f(IM(y, ch), RE(y, ch))
#define atan2f(y, x)
Definition libm.h:47

Definition at line 1307 of file avf_showspectrum.c.

Referenced by calc_channel_phases(), calc_channel_uphases(), plot_freqs(), and query_formats().

Enumeration Type Documentation

◆ DisplayMode

Enumerator
COMBINED 
SEPARATE 
NB_MODES 

Definition at line 51 of file avf_showspectrum.c.

◆ DataMode

enum DataMode
Enumerator
D_MAGNITUDE 
D_PHASE 
D_UPHASE 
NB_DMODES 

Definition at line 52 of file avf_showspectrum.c.

◆ FrequencyScale

Enumerator
F_LINEAR 
F_LOG 
NB_FSCALES 

Definition at line 53 of file avf_showspectrum.c.

◆ DisplayScale

Enumerator
LINEAR 
SQRT 
CBRT 
LOG 
FOURTHRT 
FIFTHRT 
NB_SCALES 

Definition at line 54 of file avf_showspectrum.c.

◆ ColorMode

enum ColorMode
Enumerator
CHANNEL 
INTENSITY 
RAINBOW 
MORELAND 
NEBULAE 
FIRE 
FIERY 
FRUIT 
COOL 
MAGMA 
GREEN 
VIRIDIS 
PLASMA 
CIVIDIS 
TERRAIN 
NB_CLMODES 

Definition at line 55 of file avf_showspectrum.c.

◆ SlideMode

enum SlideMode
Enumerator
REPLACE 
SCROLL 
FULLFRAME 
RSCROLL 
LREPLACE 
NB_SLIDES 

Definition at line 56 of file avf_showspectrum.c.

◆ Orientation

Enumerator
VERTICAL 
HORIZONTAL 
NB_ORIENTATIONS 

Definition at line 57 of file avf_showspectrum.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( showspectrum )

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 304 of file avf_showspectrum.c.

◆ query_formats()

static int query_formats ( const AVFilterContext * ctx,
AVFilterFormatsConfig ** cfg_in,
AVFilterFormatsConfig ** cfg_out )
static

Definition at line 362 of file avf_showspectrum.c.

◆ run_channel_fft()

static int run_channel_fft ( AVFilterContext * ctx,
void * arg,
int jobnr,
int nb_jobs )
static

Definition at line 384 of file avf_showspectrum.c.

◆ drawtext()

static void drawtext ( AVFrame * pic,
int x,
int y,
const char * txt,
int o )
static

Definition at line 491 of file avf_showspectrum.c.

Referenced by draw_legend(), and plot_spectrum_column().

◆ color_range()

static void color_range ( ShowSpectrumContext * s,
int ch,
float * yf,
float * uf,
float * vf )
static

Definition at line 546 of file avf_showspectrum.c.

◆ pick_color()

static void pick_color ( ShowSpectrumContext * s,
float yf,
float uf,
float vf,
float a,
float * out )
static

Definition at line 608 of file avf_showspectrum.c.

Referenced by draw_legend(), plot_channel_lin(), and plot_channel_log().

◆ get_time()

static char * get_time ( AVFilterContext * ctx,
float seconds,
int x )
static

Definition at line 656 of file avf_showspectrum.c.

Referenced by draw_legend(), and plot_spectrum_column().

◆ log_scale()

static float log_scale ( const float bin,
const float bmin,
const float bmax,
const float min,
const float max )
static

Definition at line 671 of file avf_showspectrum.c.

Referenced by get_hz().

◆ get_hz()

static float get_hz ( const float bin,
const float bmax,
const float min,
const float max,
int fscale )
static

Definition at line 678 of file avf_showspectrum.c.

Referenced by draw_legend().

◆ inv_log_scale()

static float inv_log_scale ( float bin,
float bmin,
float bmax,
float min,
float max )
static

Definition at line 692 of file avf_showspectrum.c.

Referenced by bin_pos().

◆ bin_pos()

static float bin_pos ( const int bin,
const int num_bins,
const float min,
const float max )
static

Definition at line 699 of file avf_showspectrum.c.

Referenced by plot_channel_log().

◆ get_scale()

static float get_scale ( AVFilterContext * ctx,
int scale,
float a )
static

Definition at line 704 of file avf_showspectrum.c.

Referenced by get_value().

◆ get_iscale()

static float get_iscale ( AVFilterContext * ctx,
int scale,
float a )
static

Definition at line 739 of file avf_showspectrum.c.

Referenced by draw_legend().

◆ draw_legend()

static int draw_legend ( AVFilterContext * ctx,
uint64_t samples )
static

Definition at line 773 of file avf_showspectrum.c.

Referenced by config_output().

◆ get_value()

static float get_value ( AVFilterContext * ctx,
int ch,
int y )
static

Definition at line 971 of file avf_showspectrum.c.

Referenced by plot_channel_lin(), and plot_channel_log().

◆ plot_channel_lin()

static int plot_channel_lin ( AVFilterContext * ctx,
void * arg,
int jobnr,
int nb_jobs )
static

Definition at line 995 of file avf_showspectrum.c.

Referenced by config_output().

◆ plot_channel_log()

static int plot_channel_log ( AVFilterContext * ctx,
void * arg,
int jobnr,
int nb_jobs )
static

Definition at line 1018 of file avf_showspectrum.c.

Referenced by config_output().

◆ config_output()

static int config_output ( AVFilterLink * outlink)
static

Definition at line 1049 of file avf_showspectrum.c.

◆ calc_channel_magnitudes()

static int calc_channel_magnitudes ( AVFilterContext * ctx,
void * arg,
int jobnr,
int nb_jobs )
static

Definition at line 1309 of file avf_showspectrum.c.

◆ calc_channel_phases()

static int calc_channel_phases ( AVFilterContext * ctx,
void * arg,
int jobnr,
int nb_jobs )
static

Definition at line 1324 of file avf_showspectrum.c.

◆ unwrap()

static void unwrap ( float * x,
int N,
float tol,
float * mi,
float * ma )
static

Definition at line 1338 of file avf_showspectrum.c.

Referenced by calc_channel_uphases().

◆ calc_channel_uphases()

static int calc_channel_uphases ( AVFilterContext * ctx,
void * arg,
int jobnr,
int nb_jobs )
static

Definition at line 1359 of file avf_showspectrum.c.

◆ acalc_magnitudes()

static void acalc_magnitudes ( ShowSpectrumContext * s)
static

Definition at line 1378 of file avf_showspectrum.c.

◆ scale_magnitudes()

static void scale_magnitudes ( ShowSpectrumContext * s,
float scale )
static

Definition at line 1392 of file avf_showspectrum.c.

◆ clear_combine_buffer()

static void clear_combine_buffer ( ShowSpectrumContext * s,
int size )
static

Definition at line 1404 of file avf_showspectrum.c.

Referenced by plot_spectrum_column().

◆ plot_spectrum_column()

static int plot_spectrum_column ( AVFilterLink * inlink,
AVFrame * insamples )
static

Definition at line 1416 of file avf_showspectrum.c.

Variable Documentation

◆ showspectrum_options

const AVOption showspectrum_options[]
static

Definition at line 126 of file avf_showspectrum.c.

◆ color_table

const struct ColorTable color_table[][8]
static