FFmpeg
Loading...
Searching...
No Matches
avf_showcqt.c File Reference
#include "config.h"
#include "libavutil/attributes.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)
 
#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 FFFilter ff_avf_showcqt
 

Macro Definition Documentation

◆ BASEFREQ

#define BASEFREQ   20.01523126408007475

Definition at line 50 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ ENDFREQ

#define ENDFREQ   20495.59681441799654

Definition at line 51 of file avf_showcqt.c.

Referenced by init_axis_color().

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

Referenced by init_cqt().

◆ VOLUME_MAX

#define VOLUME_MAX   100.0

Definition at line 54 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 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)
Value:

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)
#define lrintf(x)
Definition libm_mips.h:72
static double c[64]

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

Definition at line 801 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)
int a

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

Definition at line 912 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 b
Definition input.c:43
static double a0(void *priv, double x, double y)
Definition vf_xfade.c:2028
static double a1(void *priv, double x, double y)
Definition vf_xfade.c:2029

Definition at line 926 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)
static double a3(void *priv, double x, double y)
Definition vf_xfade.c:2031
static double a2(void *priv, double x, double y)
Definition vf_xfade.c:2030

Definition at line 943 of file avf_showcqt.c.

Referenced by draw_axis_yuv().

◆ UPDATE_TIME

#define UPDATE_TIME ( t)
Value:
cur_time = av_gettime_relative(); \
t += cur_time - last_time; \
last_time = cur_time
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57

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

Referenced by init_axis_color().

◆ r_func()

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

Definition at line 441 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ g_func()

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

Definition at line 447 of file avf_showcqt.c.

Referenced by init_axis_color().

◆ b_func()

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

Definition at line 453 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 459 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 506 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 590 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 654 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 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 ( const AVFilterContext * ctx,
AVFilterFormatsConfig ** cfg_in,
AVFilterFormatsConfig ** cfg_out )
static

Definition at line 1318 of file avf_showcqt.c.

◆ config_output()

static int config_output ( AVFilterLink * outlink)
static

Definition at line 1349 of file avf_showcqt.c.

◆ filter_frame()

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

Definition at line 1480 of file avf_showcqt.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext * ctx)
static

Definition at line 1562 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,
},
}
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int config_output(AVBitStreamFilterLink *outlink)

Definition at line 1594 of file avf_showcqt.c.

◆ ff_avf_showcqt

const FFFilter ff_avf_showcqt
Initial value:
= {
.p.name = "showcqt",
.p.description = NULL_IF_CONFIG_SMALL("Convert input audio to a CQT (Constant/Clamped Q Transform) spectrum video output."),
.p.priv_class = &showcqt_class,
.init = init,
.activate = activate,
.uninit = uninit,
.priv_size = sizeof(ShowCQTContext),
}
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
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
static const AVFilterPad showcqt_outputs[]
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88

Definition at line 1602 of file avf_showcqt.c.