History

avfilter/af_aiir: calculate group delay too

Paul B Mahol committed 7 years ago

Commit 80dacbe1 parent 18c808f2 files · +31 −4Browse files

Unified · Split

2 files
  1. doc/filters.texi +1 −1
  2. libavfilter/af_aiir.c +30 −3
doc/filters.texi+1−1
@@ -1397,7 +1397,7 @@ How much to use filtered signal in output. Default is 1. · 1396 unmodified lines
1397Range is between 0 and 1.1397Range is between 0 and 1.
1398 1398
1399@item response1399@item response
1400Show IR frequency response, magnitude and phase in additional video stream.1400Show IR frequency response, magnitude(magenta), phase(green) and group delay(yellow) in additional video stream.
1401By default it is disabled.1401By default it is disabled.
1402 1402
1403@item channel1403@item channel
libavfilter/af_aiir.c+30−3
@@ -721,8 +721,9 @@ static void draw_line(AVFrame *out, int x0, int y0, int x1, int y1, uint32_t col · 720 unmodified lines
721static void draw_response(AVFilterContext *ctx, AVFrame *out)721static void draw_response(AVFilterContext *ctx, AVFrame *out)
722{722{
723 AudioIIRContext *s = ctx->priv;723 AudioIIRContext *s = ctx->priv;
724 float *mag, *phase, min = FLT_MAX, max = FLT_MIN;724 float *mag, *phase, *delay, min = FLT_MAX, max = FLT_MIN;
725 int prev_ymag = -1, prev_yphase = -1;725 float min_delay = FLT_MAX, max_delay = FLT_MIN;
726 int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
726 char text[32];727 char text[32];
727 int ch, i, x;728 int ch, i, x;
728 729
@@ -730,7 +731,8 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out) · 1 unmodified line
730 731
731 phase = av_malloc_array(s->w, sizeof(*phase));732 phase = av_malloc_array(s->w, sizeof(*phase));
732 mag = av_malloc_array(s->w, sizeof(*mag));733 mag = av_malloc_array(s->w, sizeof(*mag));
733 if (!mag || !phase)734 delay = av_malloc_array(s->w, sizeof(*delay));
735 if (!mag || !phase || !delay)
734 goto end;736 goto end;
735 737
736 ch = av_clip(s->ir_channel, 0, s->channels - 1);738 ch = av_clip(s->ir_channel, 0, s->channels - 1);
@@ -795,23 +797,39 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out) · 58 unmodified lines
795 max = fmaxf(max, mag[i]);797 max = fmaxf(max, mag[i]);
796 }798 }
797 799
800 for (i = 0; i < s->w - 1; i++) {
801 float dw = M_PI / (s->w - 1);
802
803 delay[i] = -(phase[i + 1] - phase[i]) / dw;
804 min_delay = fminf(min_delay, delay[i]);
805 max_delay = fmaxf(max_delay, delay[i]);
806 }
807
808 delay[i] = delay[i - 1];
809
798 for (i = 0; i < s->w; i++) {810 for (i = 0; i < s->w; i++) {
799 int ymag = mag[i] / max * (s->h - 1);811 int ymag = mag[i] / max * (s->h - 1);
812 int ydelay = (delay[i] - min_delay) / (max_delay - min_delay) * (s->h - 1);
800 int yphase = (0.5 * (1. + phase[i] / M_PI)) * (s->h - 1);813 int yphase = (0.5 * (1. + phase[i] / M_PI)) * (s->h - 1);
801 814
802 ymag = s->h - 1 - av_clip(ymag, 0, s->h - 1);815 ymag = s->h - 1 - av_clip(ymag, 0, s->h - 1);
803 yphase = s->h - 1 - av_clip(yphase, 0, s->h - 1);816 yphase = s->h - 1 - av_clip(yphase, 0, s->h - 1);
817 ydelay = s->h - 1 - av_clip(ydelay, 0, s->h - 1);
804 818
805 if (prev_ymag < 0)819 if (prev_ymag < 0)
806 prev_ymag = ymag;820 prev_ymag = ymag;
807 if (prev_yphase < 0)821 if (prev_yphase < 0)
808 prev_yphase = yphase;822 prev_yphase = yphase;
823 if (prev_ydelay < 0)
824 prev_ydelay = ydelay;
809 825
810 draw_line(out, i, ymag, FFMAX(i - 1, 0), prev_ymag, 0xFFFF00FF);826 draw_line(out, i, ymag, FFMAX(i - 1, 0), prev_ymag, 0xFFFF00FF);
811 draw_line(out, i, yphase, FFMAX(i - 1, 0), prev_yphase, 0xFF00FF00);827 draw_line(out, i, yphase, FFMAX(i - 1, 0), prev_yphase, 0xFF00FF00);
828 draw_line(out, i, ydelay, FFMAX(i - 1, 0), prev_ydelay, 0xFF00FFFF);
812 829
813 prev_ymag = ymag;830 prev_ymag = ymag;
814 prev_yphase = yphase;831 prev_yphase = yphase;
832 prev_ydelay = ydelay;
815 }833 }
816 834
817 if (s->w > 400 && s->h > 100) {835 if (s->w > 400 && s->h > 100) {
@@ -822,9 +840,18 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out) · 4 unmodified lines
822 drawtext(out, 2, 12, "Min Magnitude:", 0xDDDDDDDD);840 drawtext(out, 2, 12, "Min Magnitude:", 0xDDDDDDDD);
823 snprintf(text, sizeof(text), "%.2f", min);841 snprintf(text, sizeof(text), "%.2f", min);
824 drawtext(out, 15 * 8 + 2, 12, text, 0xDDDDDDDD);842 drawtext(out, 15 * 8 + 2, 12, text, 0xDDDDDDDD);
843
844 drawtext(out, 2, 22, "Max Delay:", 0xDDDDDDDD);
845 snprintf(text, sizeof(text), "%.2f", max_delay);
846 drawtext(out, 11 * 8 + 2, 22, text, 0xDDDDDDDD);
847
848 drawtext(out, 2, 32, "Min Delay:", 0xDDDDDDDD);
849 snprintf(text, sizeof(text), "%.2f", min_delay);
850 drawtext(out, 11 * 8 + 2, 32, text, 0xDDDDDDDD);
825 }851 }
826 852
827end:853end:
854 av_free(delay);
828 av_free(phase);855 av_free(phase);
829 av_free(mag);856 av_free(mag);
830}857}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t