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 "internal.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 (AVFilterContext *ctx)
 
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 50 of file avf_showcqt.c.

◆ ENDFREQ

#define ENDFREQ   20495.59681441799654

Definition at line 51 of file avf_showcqt.c.

◆ TLENGTH

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

Definition at line 52 of file avf_showcqt.c.

◆ TLENGTH_MIN

#define TLENGTH_MIN   0.001

Definition at line 53 of file avf_showcqt.c.

◆ VOLUME_MAX

#define VOLUME_MAX   100.0

Definition at line 54 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 55 of file avf_showcqt.c.

◆ CSCHEME

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

Definition at line 58 of file avf_showcqt.c.

◆ OFFSET

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

Definition at line 60 of file avf_showcqt.c.

◆ FLAGS

Definition at line 61 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 787 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 802 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 893 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 913 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 927 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 944 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 111 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 168 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 188 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 209 of file avf_showcqt.c.

Referenced by init_volume().

◆ b_weighting()

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

Definition at line 217 of file avf_showcqt.c.

Referenced by init_volume().

◆ c_weighting()

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

Definition at line 224 of file avf_showcqt.c.

Referenced by init_volume().

◆ init_volume()

static int init_volume ( ShowCQTContext s)
static

Definition at line 231 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 273 of file avf_showcqt.c.

Referenced by config_output().

◆ init_cqt()

static int init_cqt ( ShowCQTContext s)
static

Definition at line 300 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 362 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 388 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 399 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 406 of file avf_showcqt.c.

Referenced by config_output().

◆ midi()

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

Definition at line 438 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ r_func()

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

Definition at line 443 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ g_func()

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

Definition at line 449 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ b_func()

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

Definition at line 455 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 461 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 508 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 592 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 656 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 682 of file avf_showcqt.c.

Referenced by config_output().

◆ calculate_gamma()

static float calculate_gamma ( float  v,
float  g 
)
static

Definition at line 723 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 736 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 746 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 760 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 813 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 864 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 966 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 1031 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 1056 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 1068 of file avf_showcqt.c.

Referenced by config_output().

◆ process_cqt()

static void process_cqt ( ShowCQTContext s)
static

Definition at line 1087 of file avf_showcqt.c.

Referenced by plot_cqt().

◆ plot_cqt()

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

Definition at line 1133 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 1354 of file avf_showcqt.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame insamples 
)
static

Definition at line 1484 of file avf_showcqt.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 1566 of file avf_showcqt.c.

Variable Documentation

◆ showcqt_options

const AVOption showcqt_options[]
static

Definition at line 63 of file avf_showcqt.c.

◆ showcqt_outputs

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

Definition at line 1598 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 1606 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
b
#define b
Definition: input.c:41
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showcqt.c:1313
a1
#define a1
Definition: regdef.h:47
ShowCQTContext
Definition: avf_showcqt.h:46
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showcqt.c:1256
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:33
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:121
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:1598
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_showcqt.c:1318
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
#define a0
Definition: regdef.h:46
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
a2
#define a2
Definition: regdef.h:48
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showcqt.c:1566
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showcqt.c:1354
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
h
h
Definition: vp9dsp_template.c:2038
a3
#define a3
Definition: regdef.h:49