Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2013 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4682205 to your computer and use it in GitHub Desktop.
Save anonymous/4682205 to your computer and use it in GitHub Desktop.
stdin
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 21c9561..9f67be2 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -39,6 +39,7 @@ typedef struct {
int req_fullfilled;
int nb_display_channels;
int compat; ///< use old up to 2 channels display mode
+ int combined; ///< use old-style combined channel display mode
int sliding; ///< 1 if sliding mode, 0 otherwise
int xpos; ///< x position (current column)
RDFTContext *rdft; ///< Real Discrete Fourier Transform context
@@ -57,6 +58,7 @@ static const AVOption showspectrum_options[] = {
{ "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x480"}, 0, 0, FLAGS },
{ "slide", "set sliding mode", OFFSET(sliding), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
{ "compat", "set compat mode", OFFSET(compat), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
+ { "combined", "set combined mode", OFFSET(combined), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
{ NULL },
};
@@ -133,7 +135,7 @@ static int config_output(AVFilterLink *outlink)
outlink->w = showspectrum->w;
outlink->h = showspectrum->h;
- h = showspectrum->compat ? outlink->h: outlink->h / inlink->channels;
+ h = showspectrum->compat ? outlink->h : showspectrum->combined ? outlink->h : outlink->h / inlink->channels;
/* RDFT window size (precision) according to the requested output frame height */
for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
@@ -290,12 +292,13 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFilterBufferRef *insampl
p[2] = (a + b) / 2;
}
} else {
- int h = outlink->h / showspectrum->nb_display_channels;
+ int h = showspectrum->combined ? outlink->h : outlink->h / showspectrum->nb_display_channels;
- for (ch = 0; ch < showspectrum->nb_display_channels; ch++) {
- for (y = 0; y < h; y++) {
+ for (y = 0; y < h; y++) {
+ for (ch = 0; ch < showspectrum->nb_display_channels; ch++) {
+ int row = showspectrum->combined ? y : ch * h + y;
uint8_t *p = outpicref->data[0] +
- (outlink->h - (ch * h + y) - 1) *
+ (outlink->h - row - 1) *
outpicref->linesize[0];
int a = sqrt(w * MAGNITUDE(RE(ch), IM(ch)));
@@ -306,7 +309,21 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFilterBufferRef *insampl
p += showspectrum->xpos * 3;
}
- p[0] = p[1] = p[2] = a;
+ {
+ int r = (a/2) * (1 + sin((2 * M_PI * ch) / showspectrum->nb_display_channels));
+ int g = (a/2) * (1 + sin((2 * M_PI * ch) / showspectrum->nb_display_channels + 2 * M_PI / 3));
+ int b = (a/2) * (1 + sin((2 * M_PI * ch) / showspectrum->nb_display_channels + 4 * M_PI / 3));
+
+ if (ch == 0 || !showspectrum->combined) {
+ p[0] = r;
+ p[1] = g;
+ p[2] = b;
+ } else {
+ p[0] += r;
+ p[1] += g;
+ p[2] += b;
+ }
+ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment