FFmpeg
Macros | Functions | Variables
avf_showcqt.c File Reference
#include "config.h"
#include "libavutil/mem.h"
#include "libavutil/tx.h"
#include "libavutil/channel_layout.h"
#include "libavutil/opt.h"
#include "libavutil/xga_font_data.h"
#include "libavutil/eval.h"
#include "libavutil/pixdesc.h"
#include "libavutil/time.h"
#include "audio.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "lavfutils.h"
#include "lswsutils.h"
#include "video.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 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 doublecreate_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 (AVComplexFloat *dst, const AVComplexFloat *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 AVComplexFloat *v, float g, int len, float cscheme[6])
 
static void yuv_from_cqt (ColorFloat *c, const AVComplexFloat *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 (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
static int config_output (AVFilterLink *outlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *insamples)
 
static int activate (AVFilterContext *ctx)
 

Variables

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

Macro Definition Documentation

◆ BASEFREQ

#define BASEFREQ   20.01523126408007475

Definition at line 49 of file avf_showcqt.c.

◆ ENDFREQ

#define ENDFREQ   20495.59681441799654

Definition at line 50 of file avf_showcqt.c.

◆ TLENGTH

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

Definition at line 51 of file avf_showcqt.c.

◆ TLENGTH_MIN

#define TLENGTH_MIN   0.001

Definition at line 52 of file avf_showcqt.c.

◆ VOLUME_MAX

#define VOLUME_MAX   100.0

Definition at line 53 of file avf_showcqt.c.

◆ 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 54 of file avf_showcqt.c.

◆ CSCHEME

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

Definition at line 57 of file avf_showcqt.c.

◆ OFFSET

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

Definition at line 59 of file avf_showcqt.c.

◆ FLAGS

Definition at line 60 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)

Definition at line 786 of file avf_showcqt.c.

◆ 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)

Definition at line 801 of file avf_showcqt.c.

◆ 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)

Definition at line 892 of file avf_showcqt.c.

◆ 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)

Definition at line 912 of file avf_showcqt.c.

◆ 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)

Definition at line 926 of file avf_showcqt.c.

◆ 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)

Definition at line 943 of file avf_showcqt.c.

◆ UPDATE_TIME

#define UPDATE_TIME (   t)
Value:
cur_time = av_gettime_relative(); \
t += cur_time - last_time; \
last_time = cur_time

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( showcqt  )

◆ common_uninit()

static void common_uninit ( ShowCQTContext s)
static

Definition at line 110 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 167 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 187 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 208 of file avf_showcqt.c.

Referenced by init_volume().

◆ b_weighting()

static double b_weighting ( void *  p,
double  f 
)
static

Definition at line 216 of file avf_showcqt.c.

Referenced by init_volume().

◆ c_weighting()

static double c_weighting ( void *  p,
double  f 
)
static

Definition at line 223 of file avf_showcqt.c.

Referenced by init_volume().

◆ init_volume()

static int init_volume ( ShowCQTContext s)
static

Definition at line 230 of file avf_showcqt.c.

Referenced by config_output().

◆ cqt_calc()

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

Definition at line 272 of file avf_showcqt.c.

Referenced by config_output().

◆ init_cqt()

static int init_cqt ( ShowCQTContext s)
static

Definition at line 299 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 361 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 387 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 398 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 405 of file avf_showcqt.c.

Referenced by config_output().

◆ midi()

static double midi ( void *  p,
double  f 
)
static

Definition at line 437 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ r_func()

static double r_func ( void *  p,
double  x 
)
static

Definition at line 442 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ g_func()

static double g_func ( void *  p,
double  x 
)
static

Definition at line 448 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ b_func()

static double b_func ( void *  p,
double  x 
)
static

Definition at line 454 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 460 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 507 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 591 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 655 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 681 of file avf_showcqt.c.

Referenced by config_output().

◆ calculate_gamma()

static float calculate_gamma ( float  v,
float  g 
)
static

Definition at line 722 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 AVComplexFloat v,
float  g,
int  len,
float  cscheme[6] 
)
static

Definition at line 735 of file avf_showcqt.c.

Referenced by process_cqt().

◆ yuv_from_cqt()

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

Definition at line 745 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 759 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 812 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 863 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 965 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 1030 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 1055 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 1067 of file avf_showcqt.c.

Referenced by config_output().

◆ process_cqt()

static void process_cqt ( ShowCQTContext s)
static

Definition at line 1086 of file avf_showcqt.c.

Referenced by plot_cqt().

◆ plot_cqt()

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

Definition at line 1132 of file avf_showcqt.c.

Referenced by filter_frame().

◆ init_colormatrix()

static void init_colormatrix ( ShowCQTContext s)
static

Definition at line 1198 of file avf_showcqt.c.

Referenced by init().

◆ init_cscheme()

static int init_cscheme ( ShowCQTContext s)
static

Definition at line 1233 of file avf_showcqt.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 1255 of file avf_showcqt.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 1312 of file avf_showcqt.c.

◆ query_formats()

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

Definition at line 1317 of file avf_showcqt.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 1348 of file avf_showcqt.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 1479 of file avf_showcqt.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 1561 of file avf_showcqt.c.

Variable Documentation

◆ showcqt_options

const AVOption showcqt_options[]
static

Definition at line 62 of file avf_showcqt.c.

◆ showcqt_outputs

const AVFilterPad showcqt_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
}

Definition at line 1593 of file avf_showcqt.c.

◆ ff_avf_showcqt

const 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,
.activate = activate,
.uninit = uninit,
.priv_size = sizeof(ShowCQTContext),
.priv_class = &showcqt_class,
}

Definition at line 1601 of file avf_showcqt.c.

av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
b
#define b
Definition: input.c:41
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: avf_showcqt.c:1317
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showcqt.c:1312
a2
static double a2(void *priv, double x, double y)
Definition: vf_xfade.c:2030
ShowCQTContext
Definition: avf_showcqt.h:45
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showcqt.c:1255
a3
static double a3(void *priv, double x, double y)
Definition: vf_xfade.c:2031
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:34
c
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
Definition: undefined.txt:32
f
f
Definition: af_crystalizer.c:122
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
showcqt_outputs
static const AVFilterPad showcqt_outputs[]
Definition: avf_showcqt.c:1593
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
a0
static double a0(void *priv, double x, double y)
Definition: vf_xfade.c:2028
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showcqt.c:1561
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showcqt.c:1348
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
a1
static double a1(void *priv, double x, double y)
Definition: vf_xfade.c:2029
h
h
Definition: vp9dsp_template.c:2070