avfilter/avf_showspectrum: add option to set gain for calculating color intensity
Inspired by Sonic Visualizer. Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
1cb2331eca
commit
6defda1cdb
@ -14688,6 +14688,10 @@ Set orientation of time vs frequency axis. Can be @code{vertical} or
|
|||||||
Set ratio of overlap window. Default value is @code{0}.
|
Set ratio of overlap window. Default value is @code{0}.
|
||||||
When value is @code{1} overlap is set to recommended size for specific
|
When value is @code{1} overlap is set to recommended size for specific
|
||||||
window function currently used.
|
window function currently used.
|
||||||
|
|
||||||
|
@item gain
|
||||||
|
Set scale gain for calculating intensity color values.
|
||||||
|
Default value is @code{1}.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
The usage is very similar to the showwaves filter; see the examples in that
|
The usage is very similar to the showwaves filter; see the examples in that
|
||||||
@ -14809,6 +14813,10 @@ Default value is @code{hann}.
|
|||||||
@item orientation
|
@item orientation
|
||||||
Set orientation of time vs frequency axis. Can be @code{vertical} or
|
Set orientation of time vs frequency axis. Can be @code{vertical} or
|
||||||
@code{horizontal}. Default is @code{vertical}.
|
@code{horizontal}. Default is @code{vertical}.
|
||||||
|
|
||||||
|
@item gain
|
||||||
|
Set scale gain for calculating intensity color values.
|
||||||
|
Default value is @code{1}.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@subsection Examples
|
@subsection Examples
|
||||||
|
|||||||
@ -68,6 +68,7 @@ typedef struct {
|
|||||||
int win_size;
|
int win_size;
|
||||||
double win_scale;
|
double win_scale;
|
||||||
float overlap;
|
float overlap;
|
||||||
|
float gain;
|
||||||
int skip_samples;
|
int skip_samples;
|
||||||
float *combine_buffer; ///< color combining buffer (3 * h items)
|
float *combine_buffer; ///< color combining buffer (3 * h items)
|
||||||
AVAudioFifo *fifo;
|
AVAudioFifo *fifo;
|
||||||
@ -125,6 +126,7 @@ static const AVOption showspectrum_options[] = {
|
|||||||
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, FLAGS, "orientation" },
|
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, FLAGS, "orientation" },
|
||||||
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
|
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
|
||||||
{ "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, 1, FLAGS },
|
{ "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, 1, FLAGS },
|
||||||
|
{ "gain", "set scale gain", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 128, FLAGS },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -497,6 +499,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
ShowSpectrumContext *s = ctx->priv;
|
ShowSpectrumContext *s = ctx->priv;
|
||||||
AVFrame *outpicref = s->outpicref;
|
AVFrame *outpicref = s->outpicref;
|
||||||
const double w = s->win_scale;
|
const double w = s->win_scale;
|
||||||
|
const float g = s->gain;
|
||||||
int h = s->orientation == VERTICAL ? s->channel_height : s->channel_width;
|
int h = s->orientation == VERTICAL ? s->channel_height : s->channel_width;
|
||||||
|
|
||||||
int ch, plane, x, y;
|
int ch, plane, x, y;
|
||||||
@ -562,7 +565,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
float *out = &s->combine_buffer[3 * row];
|
float *out = &s->combine_buffer[3 * row];
|
||||||
|
|
||||||
/* get magnitude */
|
/* get magnitude */
|
||||||
float a = w * magnitudes[y];
|
float a = g * w * magnitudes[y];
|
||||||
|
|
||||||
/* apply scale */
|
/* apply scale */
|
||||||
switch (s->scale) {
|
switch (s->scale) {
|
||||||
@ -814,6 +817,7 @@ static const AVOption showspectrumpic_options[] = {
|
|||||||
{ "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
|
{ "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
|
||||||
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, FLAGS, "orientation" },
|
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, FLAGS, "orientation" },
|
||||||
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
|
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
|
||||||
|
{ "gain", "set scale gain", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 128, FLAGS },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user