FFmpeg  4.0
Macros | Functions | Variables
avf_showcqt.c File Reference
#include "config.h"
#include "libavcodec/avfft.h"
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavutil/xga_font_data.h"
#include "libavutil/eval.h"
#include "libavutil/pixdesc.h"
#include "libavutil/time.h"
#include "avfilter.h"
#include "internal.h"
#include "lavfutils.h"
#include "lswsutils.h"
#include "avf_showcqt.h"

Go to the source code of this file.

Macros

#define BASEFREQ   20.01523126408007475
 
#define ENDFREQ   20495.59681441799654
 
#define TLENGTH   "384*tc/(384+tc*f)"
 
#define TLENGTH_MIN   0.001
 
#define VOLUME_MAX   100.0
 
#define FONTCOLOR
 
#define CSCHEME   "1|0.5|0|0|0.5|1"
 
#define PTS_STEP   10
 
#define PTS_TOLERANCE   1
 
#define OFFSET(x)   offsetof(ShowCQTContext, x)
 
#define FLAGS   (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
 
#define DRAW_BAR_WITH_CHROMA(x)
 
#define DRAW_BAR_WITHOUT_CHROMA(x)
 
#define BLEND_WITH_CHROMA(c)
 
#define BLEND_WITHOUT_CHROMA(c, alpha_inc)
 
#define BLEND_CHROMA2(c)
 
#define BLEND_CHROMA2x2(c)
 
#define UPDATE_TIME(t)
 

Functions

 AVFILTER_DEFINE_CLASS (showcqt)
 
static void common_uninit (ShowCQTContext *s)
 
static double * create_freq_table (double base, double end, int n)
 
static double clip_with_log (void *log_ctx, const char *name, double val, double min, double max, double nan_replace, int idx)
 
static double a_weighting (void *p, double f)
 
static double b_weighting (void *p, double f)
 
static double c_weighting (void *p, double f)
 
static int init_volume (ShowCQTContext *s)
 
static void cqt_calc (FFTComplex *dst, const FFTComplex *src, const Coeffs *coeffs, int len, int fft_len)
 
static int init_cqt (ShowCQTContext *s)
 
static AVFramealloc_frame_empty (enum AVPixelFormat format, int w, int h)
 
static enum AVPixelFormat convert_axis_pixel_format (enum AVPixelFormat format)
 
static int init_axis_empty (ShowCQTContext *s)
 
static int init_axis_from_file (ShowCQTContext *s)
 
static double midi (void *p, double f)
 
static double r_func (void *p, double x)
 
static double g_func (void *p, double x)
 
static double b_func (void *p, double x)
 
static int init_axis_color (ShowCQTContext *s, AVFrame *tmp, int half)
 
static int render_freetype (ShowCQTContext *s, AVFrame *tmp, char *fontfile)
 
static int render_fontconfig (ShowCQTContext *s, AVFrame *tmp, char *font)
 
static int render_default_font (AVFrame *tmp)
 
static int init_axis_from_font (ShowCQTContext *s)
 
static float calculate_gamma (float v, float g)
 
static void rgb_from_cqt (ColorFloat *c, const FFTComplex *v, float g, int len, float cscheme[6])
 
static void yuv_from_cqt (ColorFloat *c, const FFTComplex *v, float gamma, int len, float cm[3][3], float cscheme[6])
 
static void draw_bar_rgb (AVFrame *out, const float *h, const float *rcp_h, const ColorFloat *c, int bar_h, float bar_t)
 
static void draw_bar_yuv (AVFrame *out, const float *h, const float *rcp_h, const ColorFloat *c, int bar_h, float bar_t)
 
static void draw_axis_rgb (AVFrame *out, AVFrame *axis, const ColorFloat *c, int off)
 
static void draw_axis_yuv (AVFrame *out, AVFrame *axis, const ColorFloat *c, int off)
 
static void draw_sono (AVFrame *out, AVFrame *sono, int off, int idx)
 
static void update_sono_rgb (AVFrame *sono, const ColorFloat *c, int idx)
 
static void update_sono_yuv (AVFrame *sono, const ColorFloat *c, int idx)
 
static void process_cqt (ShowCQTContext *s)
 
static int plot_cqt (AVFilterContext *ctx, AVFrame **frameout)
 
static void init_colormatrix (ShowCQTContext *s)
 
static int init_cscheme (ShowCQTContext *s)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_output (AVFilterLink *outlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *insamples)
 
static int request_frame (AVFilterLink *outlink)
 

Variables

static const AVOption showcqt_options []
 
static const AVFilterPad showcqt_inputs []
 
static const AVFilterPad showcqt_outputs []
 
AVFilter ff_avf_showcqt
 

Macro Definition Documentation

◆ BASEFREQ

#define BASEFREQ   20.01523126408007475

Definition at line 45 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ ENDFREQ

#define ENDFREQ   20495.59681441799654

Definition at line 46 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ TLENGTH

#define TLENGTH   "384*tc/(384+tc*f)"

Definition at line 47 of file avf_showcqt.c.

◆ TLENGTH_MIN

#define TLENGTH_MIN   0.001

Definition at line 48 of file avf_showcqt.c.

Referenced by init_cqt().

◆ VOLUME_MAX

#define VOLUME_MAX   100.0

Definition at line 49 of file avf_showcqt.c.

Referenced by init_volume().

◆ FONTCOLOR

#define FONTCOLOR
Value:
"st(0, (midi(f)-59.5)/12);" \
"st(1, if(between(ld(0),0,1), 0.5-0.5*cos(2*PI*ld(0)), 0));" \
"r(1-ld(1)) + b(ld(1))"

Definition at line 50 of file avf_showcqt.c.

◆ CSCHEME

#define CSCHEME   "1|0.5|0|0|0.5|1"

Definition at line 53 of file avf_showcqt.c.

◆ PTS_STEP

#define PTS_STEP   10

Definition at line 54 of file avf_showcqt.c.

Referenced by config_output(), filter_frame(), and plot_cqt().

◆ PTS_TOLERANCE

#define PTS_TOLERANCE   1

Definition at line 55 of file avf_showcqt.c.

Referenced by filter_frame().

◆ OFFSET

#define OFFSET (   x)    offsetof(ShowCQTContext, x)

Definition at line 57 of file avf_showcqt.c.

◆ FLAGS

Definition at line 58 of file avf_showcqt.c.

◆ DRAW_BAR_WITH_CHROMA

#define DRAW_BAR_WITH_CHROMA (   x)
Value:
do { \
if (h[x] <= ht) { \
*lpy++ = 16; \
*lpu++ = 128; \
*lpv++ = 128; \
} else { \
mul = (h[x] - ht) * rcp_h[x]; \
mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f; \
*lpy++ = lrintf(mul * c[x].yuv.y + 16.0f); \
*lpu++ = lrintf(mul * c[x].yuv.u + 128.0f); \
*lpv++ = lrintf(mul * c[x].yuv.v + 128.0f); \
} \
} while (0)
#define lrintf(x)
Definition: libm_mips.h:70
static double c[64]

Definition at line 784 of file avf_showcqt.c.

Referenced by draw_bar_yuv().

◆ DRAW_BAR_WITHOUT_CHROMA

#define DRAW_BAR_WITHOUT_CHROMA (   x)
Value:
do { \
if (h[x] <= ht) { \
*lpy++ = 16; \
} else { \
mul = (h[x] - ht) * rcp_h[x]; \
mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f; \
*lpy++ = lrintf(mul * c[x].yuv.y + 16.0f); \
} \
} while (0)
#define lrintf(x)
Definition: libm_mips.h:70
static double c[64]

Definition at line 799 of file avf_showcqt.c.

Referenced by draw_bar_yuv().

◆ BLEND_WITH_CHROMA

#define BLEND_WITH_CHROMA (   c)
Value:
do { \
if (!*lpaa) { \
*lpy = lrintf(c.yuv.y + 16.0f); \
*lpu = lrintf(c.yuv.u + 128.0f); \
*lpv = lrintf(c.yuv.v + 128.0f); \
} else if (255 == *lpaa) { \
*lpy = *lpay; \
*lpu = *lpau; \
*lpv = *lpav; \
} else { \
float a = (1.0f/255.0f) * (*lpaa); \
*lpy = lrintf(a * (*lpay) + (1.0f - a) * (c.yuv.y + 16.0f)); \
*lpu = lrintf(a * (*lpau) + (1.0f - a) * (c.yuv.u + 128.0f)); \
*lpv = lrintf(a * (*lpav) + (1.0f - a) * (c.yuv.v + 128.0f)); \
} \
lpy++; lpu++; lpv++; \
lpay++; lpau++; lpav++; lpaa++; \
} while (0)
#define lrintf(x)
Definition: libm_mips.h:70
static double c[64]

Definition at line 890 of file avf_showcqt.c.

Referenced by draw_axis_yuv().

◆ BLEND_WITHOUT_CHROMA

#define BLEND_WITHOUT_CHROMA (   c,
  alpha_inc 
)
Value:
do { \
if (!*lpaa) { \
*lpy = lrintf(c.yuv.y + 16.0f); \
} else if (255 == *lpaa) { \
*lpy = *lpay; \
} else { \
float a = (1.0f/255.0f) * (*lpaa); \
*lpy = lrintf(a * (*lpay) + (1.0f - a) * (c.yuv.y + 16.0f)); \
} \
lpy++; \
lpay++; lpaa += alpha_inc; \
} while (0)
#define lrintf(x)
Definition: libm_mips.h:70
static double c[64]

Definition at line 910 of file avf_showcqt.c.

Referenced by draw_axis_yuv().

◆ BLEND_CHROMA2

#define BLEND_CHROMA2 (   c)
Value:
do { \
if (!lpaa[0] && !lpaa[1]) { \
*lpu = lrintf(c.yuv.u + 128.0f); \
*lpv = lrintf(c.yuv.v + 128.0f); \
} else if (255 == lpaa[0] && 255 == lpaa[1]) { \
*lpu = *lpau; *lpv = *lpav; \
} else { \
float a0 = (0.5f/255.0f) * lpaa[0]; \
float a1 = (0.5f/255.0f) * lpaa[1]; \
float b = 1.0f - a0 - a1; \
*lpu = lrintf(a0 * lpau[0] + a1 * lpau[1] + b * (c.yuv.u + 128.0f)); \
*lpv = lrintf(a0 * lpav[0] + a1 * lpav[1] + b * (c.yuv.v + 128.0f)); \
} \
lpau += 2; lpav += 2; lpaa++; lpu++; lpv++; \
} while (0)
#define a0
Definition: regdef.h:46
const char * b
Definition: vf_curves.c:113
#define a1
Definition: regdef.h:47
#define lrintf(x)
Definition: libm_mips.h:70
static double c[64]

Definition at line 924 of file avf_showcqt.c.

Referenced by draw_axis_yuv().

◆ BLEND_CHROMA2x2

#define BLEND_CHROMA2x2 (   c)
Value:
do { \
if (!lpaa[0] && !lpaa[1] && !lpaa[lsaa] && !lpaa[lsaa+1]) { \
*lpu = lrintf(c.yuv.u + 128.0f); \
*lpv = lrintf(c.yuv.v + 128.0f); \
} else if (255 == lpaa[0] && 255 == lpaa[1] && \
255 == lpaa[lsaa] && 255 == lpaa[lsaa+1]) { \
*lpu = *lpau; *lpv = *lpav; \
} else { \
float a0 = (0.25f/255.0f) * lpaa[0]; \
float a1 = (0.25f/255.0f) * lpaa[1]; \
float a2 = (0.25f/255.0f) * lpaa[lsaa]; \
float a3 = (0.25f/255.0f) * lpaa[lsaa+1]; \
float b = 1.0f - a0 - a1 - a2 - a3; \
*lpu = lrintf(a0 * lpau[0] + a1 * lpau[1] + a2 * lpau[lsau] + a3 * lpau[lsau+1] \
+ b * (c.yuv.u + 128.0f)); \
*lpv = lrintf(a0 * lpav[0] + a1 * lpav[1] + a2 * lpav[lsav] + a3 * lpav[lsav+1] \
+ b * (c.yuv.v + 128.0f)); \
} \
lpau += 2; lpav += 2; lpaa++; lpu++; lpv++; \
} while (0)
#define a0
Definition: regdef.h:46
const char * b
Definition: vf_curves.c:113
#define a1
Definition: regdef.h:47
#define a3
Definition: regdef.h:49
#define lrintf(x)
Definition: libm_mips.h:70
#define a2
Definition: regdef.h:48
static double c[64]

Definition at line 941 of file avf_showcqt.c.

Referenced by draw_axis_yuv().

◆ UPDATE_TIME

#define UPDATE_TIME (   t)
Value:
cur_time = av_gettime(); \
t += cur_time - last_time; \
last_time = cur_time
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39

Referenced by plot_cqt().

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( showcqt  )

◆ common_uninit()

static void common_uninit ( ShowCQTContext s)
static

Definition at line 108 of file avf_showcqt.c.

Referenced by config_output(), and uninit().

◆ create_freq_table()

static double* create_freq_table ( double  base,
double  end,
int  n 
)
static

Definition at line 165 of file avf_showcqt.c.

Referenced by config_output(), and init_axis_color().

◆ clip_with_log()

static double clip_with_log ( void log_ctx,
const char *  name,
double  val,
double  min,
double  max,
double  nan_replace,
int  idx 
)
static

Definition at line 185 of file avf_showcqt.c.

Referenced by init_cqt(), and init_volume().

◆ a_weighting()

static double a_weighting ( void p,
double  f 
)
static

Definition at line 206 of file avf_showcqt.c.

Referenced by init_volume().

◆ b_weighting()

static double b_weighting ( void p,
double  f 
)
static

Definition at line 214 of file avf_showcqt.c.

Referenced by init_volume().

◆ c_weighting()

static double c_weighting ( void p,
double  f 
)
static

Definition at line 221 of file avf_showcqt.c.

Referenced by init_volume().

◆ init_volume()

static int init_volume ( ShowCQTContext s)
static

Definition at line 228 of file avf_showcqt.c.

Referenced by config_output().

◆ cqt_calc()

static void cqt_calc ( FFTComplex dst,
const FFTComplex src,
const Coeffs coeffs,
int  len,
int  fft_len 
)
static

Definition at line 270 of file avf_showcqt.c.

Referenced by config_output().

◆ init_cqt()

static int init_cqt ( ShowCQTContext s)
static

Definition at line 297 of file avf_showcqt.c.

Referenced by config_output().

◆ alloc_frame_empty()

static AVFrame* alloc_frame_empty ( enum AVPixelFormat  format,
int  w,
int  h 
)
static

Definition at line 359 of file avf_showcqt.c.

Referenced by config_output(), init_axis_empty(), and init_axis_from_font().

◆ convert_axis_pixel_format()

static enum AVPixelFormat convert_axis_pixel_format ( enum AVPixelFormat  format)
static

Definition at line 385 of file avf_showcqt.c.

Referenced by init_axis_empty(), init_axis_from_file(), and init_axis_from_font().

◆ init_axis_empty()

static int init_axis_empty ( ShowCQTContext s)
static

Definition at line 396 of file avf_showcqt.c.

Referenced by config_output().

◆ init_axis_from_file()

static int init_axis_from_file ( ShowCQTContext s)
static

Definition at line 403 of file avf_showcqt.c.

Referenced by config_output().

◆ midi()

static double midi ( void p,
double  f 
)
static

Definition at line 435 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ r_func()

static double r_func ( void p,
double  x 
)
static

Definition at line 440 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ g_func()

static double g_func ( void p,
double  x 
)
static

Definition at line 446 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ b_func()

static double b_func ( void p,
double  x 
)
static

Definition at line 452 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ init_axis_color()

static int init_axis_color ( ShowCQTContext s,
AVFrame tmp,
int  half 
)
static

Definition at line 458 of file avf_showcqt.c.

Referenced by init_axis_from_font().

◆ render_freetype()

static int render_freetype ( ShowCQTContext s,
AVFrame tmp,
char *  fontfile 
)
static

Definition at line 505 of file avf_showcqt.c.

Referenced by init_axis_from_font(), and render_fontconfig().

◆ render_fontconfig()

static int render_fontconfig ( ShowCQTContext s,
AVFrame tmp,
char *  font 
)
static

Definition at line 589 of file avf_showcqt.c.

Referenced by init_axis_from_font().

◆ render_default_font()

static int render_default_font ( AVFrame tmp)
static

Definition at line 653 of file avf_showcqt.c.

Referenced by init_axis_from_font().

◆ init_axis_from_font()

static int init_axis_from_font ( ShowCQTContext s)
static

Definition at line 679 of file avf_showcqt.c.

Referenced by config_output().

◆ calculate_gamma()

static float calculate_gamma ( float  v,
float  g 
)
static

Definition at line 720 of file avf_showcqt.c.

Referenced by process_cqt(), rgb_from_cqt(), and yuv_from_cqt().

◆ rgb_from_cqt()

static void rgb_from_cqt ( ColorFloat c,
const FFTComplex v,
float  g,
int  len,
float  cscheme[6] 
)
static

Definition at line 733 of file avf_showcqt.c.

Referenced by process_cqt().

◆ yuv_from_cqt()

static void yuv_from_cqt ( ColorFloat c,
const FFTComplex v,
float  gamma,
int  len,
float  cm[3][3],
float  cscheme[6] 
)
static

Definition at line 743 of file avf_showcqt.c.

Referenced by process_cqt().

◆ draw_bar_rgb()

static void draw_bar_rgb ( AVFrame out,
const float *  h,
const float *  rcp_h,
const ColorFloat c,
int  bar_h,
float  bar_t 
)
static

Definition at line 757 of file avf_showcqt.c.

Referenced by config_output().

◆ draw_bar_yuv()

static void draw_bar_yuv ( AVFrame out,
const float *  h,
const float *  rcp_h,
const ColorFloat c,
int  bar_h,
float  bar_t 
)
static

Definition at line 810 of file avf_showcqt.c.

Referenced by config_output().

◆ draw_axis_rgb()

static void draw_axis_rgb ( AVFrame out,
AVFrame axis,
const ColorFloat c,
int  off 
)
static

Definition at line 861 of file avf_showcqt.c.

Referenced by config_output().

◆ draw_axis_yuv()

static void draw_axis_yuv ( AVFrame out,
AVFrame axis,
const ColorFloat c,
int  off 
)
static

Definition at line 963 of file avf_showcqt.c.

Referenced by config_output().

◆ draw_sono()

static void draw_sono ( AVFrame out,
AVFrame sono,
int  off,
int  idx 
)
static

Definition at line 1028 of file avf_showcqt.c.

Referenced by config_output().

◆ update_sono_rgb()

static void update_sono_rgb ( AVFrame sono,
const ColorFloat c,
int  idx 
)
static

Definition at line 1052 of file avf_showcqt.c.

Referenced by config_output().

◆ update_sono_yuv()

static void update_sono_yuv ( AVFrame sono,
const ColorFloat c,
int  idx 
)
static

Definition at line 1064 of file avf_showcqt.c.

Referenced by config_output().

◆ process_cqt()

static void process_cqt ( ShowCQTContext s)
static

Definition at line 1083 of file avf_showcqt.c.

Referenced by plot_cqt().

◆ plot_cqt()

static int plot_cqt ( AVFilterContext ctx,
AVFrame **  frameout 
)
static

Definition at line 1129 of file avf_showcqt.c.

Referenced by filter_frame().

◆ init_colormatrix()

static void init_colormatrix ( ShowCQTContext s)
static

Definition at line 1199 of file avf_showcqt.c.

Referenced by init().

◆ init_cscheme()

static int init_cscheme ( ShowCQTContext s)
static

Definition at line 1234 of file avf_showcqt.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 1256 of file avf_showcqt.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 1313 of file avf_showcqt.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 1318 of file avf_showcqt.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 1353 of file avf_showcqt.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 1481 of file avf_showcqt.c.

Referenced by request_frame().

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 1562 of file avf_showcqt.c.

Variable Documentation

◆ showcqt_options

const AVOption showcqt_options[]
static

Definition at line 60 of file avf_showcqt.c.

◆ showcqt_inputs

const AVFilterPad showcqt_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: avf_showcqt.c:1481

Definition at line 1573 of file avf_showcqt.c.

◆ showcqt_outputs

const AVFilterPad showcqt_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
.request_frame = request_frame,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int config_output(AVFilterLink *outlink)
Definition: avf_showcqt.c:1353
static int request_frame(AVFilterLink *outlink)
Definition: avf_showcqt.c:1562

Definition at line 1582 of file avf_showcqt.c.

◆ ff_avf_showcqt

AVFilter ff_avf_showcqt
Initial value:
= {
.name = "showcqt",
.description = NULL_IF_CONFIG_SMALL("Convert input audio to a CQT (Constant/Clamped Q Transform) spectrum video output."),
.init = init,
.uninit = uninit,
.query_formats = query_formats,
.priv_size = sizeof(ShowCQTContext),
.priv_class = &showcqt_class,
}
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showcqt.c:1256
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showcqt.c:1313
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static const AVFilterPad showcqt_outputs[]
Definition: avf_showcqt.c:1582
static const AVFilterPad showcqt_inputs[]
Definition: avf_showcqt.c:1573
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static int query_formats(AVFilterContext *ctx)
Definition: avf_showcqt.c:1318

Definition at line 1592 of file avf_showcqt.c.