History

avfilter/avf_showspectrum: convert some doubles to floats

Paul B Mahol committed 7 years ago

Commit 5a39b791 parent d0e4d041 file · +34 −34Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/avf_showspectrum.c+34−34
@@ -392,29 +392,29 @@ static int run_channel_fft(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 391 unmodified lines
392 }392 }
393 393
394 if (s->stop) {394 if (s->stop) {
395 double theta, phi, psi, a, b, S, c;395 float theta, phi, psi, a, b, S, c;
396 FFTComplex *g = s->fft_data[ch];396 FFTComplex *g = s->fft_data[ch];
397 FFTComplex *h = s->fft_scratch[ch];397 FFTComplex *h = s->fft_scratch[ch];
398 int L = s->buf_size;398 int L = s->buf_size;
399 int N = s->win_size;399 int N = s->win_size;
400 int M = s->win_size / 2;400 int M = s->win_size / 2;
401 401
402 phi = 2.0 * M_PI * (s->stop - s->start) / (double)inlink->sample_rate / (M - 1);402 phi = 2.f * M_PI * (s->stop - s->start) / (float)inlink->sample_rate / (M - 1);
403 theta = 2.0 * M_PI * s->start / (double)inlink->sample_rate;403 theta = 2.f * M_PI * s->start / (float)inlink->sample_rate;
404 404
405 for (int n = 0; n < M; n++) {405 for (int n = 0; n < M; n++) {
406 h[n].re = cos(n * n / 2.0 * phi);406 h[n].re = cosf(n * n / 2.f * phi);
407 h[n].im = sin(n * n / 2.0 * phi);407 h[n].im = sinf(n * n / 2.f * phi);
408 }408 }
409 409
410 for (int n = M; n < L; n++) {410 for (int n = M; n < L; n++) {
411 h[n].re = 0.0;411 h[n].re = 0.f;
412 h[n].im = 0.0;412 h[n].im = 0.f;
413 }413 }
414 414
415 for (int n = L - N; n < L; n++) {415 for (int n = L - N; n < L; n++) {
416 h[n].re = cos((L - n) * (L - n) / 2.0 * phi);416 h[n].re = cosf((L - n) * (L - n) / 2.f * phi);
417 h[n].im = sin((L - n) * (L - n) / 2.0 * phi);417 h[n].im = sinf((L - n) * (L - n) / 2.f * phi);
418 }418 }
419 419
420 for (int n = 0; n < N; n++) {420 for (int n = 0; n < N; n++) {
@@ -423,14 +423,14 @@ static int run_channel_fft(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 2 unmodified lines
423 }423 }
424 424
425 for (int n = N; n < L; n++) {425 for (int n = N; n < L; n++) {
426 g[n].re = 0.;426 g[n].re = 0.f;
427 g[n].im = 0.;427 g[n].im = 0.f;
428 }428 }
429 429
430 for (int n = 0; n < N; n++) {430 for (int n = 0; n < N; n++) {
431 psi = n * theta + n * n / 2.0 * phi;431 psi = n * theta + n * n / 2.f * phi;
432 c = cos(psi);432 c = cosf(psi);
433 S = -sin(psi);433 S = -sinf(psi);
434 a = c * g[n].re - S * g[n].im;434 a = c * g[n].re - S * g[n].im;
435 b = S * g[n].re + c * g[n].im;435 b = S * g[n].re + c * g[n].im;
436 g[n].re = a;436 g[n].re = a;
@@ -457,9 +457,9 @@ static int run_channel_fft(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 20 unmodified lines
457 av_fft_calc(s->ifft[ch], g);457 av_fft_calc(s->ifft[ch], g);
458 458
459 for (int k = 0; k < M; k++) {459 for (int k = 0; k < M; k++) {
460 psi = k * k / 2.0 * phi;460 psi = k * k / 2.f * phi;
461 c = cos(psi);461 c = cosf(psi);
462 S = -sin(psi);462 S = -sinf(psi);
463 a = c * g[k].re - S * g[k].im;463 a = c * g[k].re - S * g[k].im;
464 b = S * g[k].re + c * g[k].im;464 b = S * g[k].re + c * g[k].im;
465 s->fft_data[ch][k].re = a;465 s->fft_data[ch][k].re = a;
@@ -555,15 +555,15 @@ static void color_range(ShowSpectrumContext *s, int ch, · 89 unmodified lines
555 555
556 if (s->color_mode == CHANNEL) {556 if (s->color_mode == CHANNEL) {
557 if (s->nb_display_channels > 1) {557 if (s->nb_display_channels > 1) {
558 *uf *= 0.5 * sin((2 * M_PI * ch) / s->nb_display_channels + M_PI * s->rotation);558 *uf *= 0.5f * sinf((2 * M_PI * ch) / s->nb_display_channels + M_PI * s->rotation);
559 *vf *= 0.5 * cos((2 * M_PI * ch) / s->nb_display_channels + M_PI * s->rotation);559 *vf *= 0.5f * cosf((2 * M_PI * ch) / s->nb_display_channels + M_PI * s->rotation);
560 } else {560 } else {
561 *uf *= 0.5 * sin(M_PI * s->rotation);561 *uf *= 0.5f * sinf(M_PI * s->rotation);
562 *vf *= 0.5 * cos(M_PI * s->rotation + M_PI_2);562 *vf *= 0.5f * cosf(M_PI * s->rotation + M_PI_2);
563 }563 }
564 } else {564 } else {
565 *uf += *uf * sin(M_PI * s->rotation);565 *uf += *uf * sinf(M_PI * s->rotation);
566 *vf += *vf * cos(M_PI * s->rotation + M_PI_2);566 *vf += *vf * cosf(M_PI * s->rotation + M_PI_2);
567 }567 }
568 568
569 *uf *= s->saturation;569 *uf *= s->saturation;
@@ -854,7 +854,7 @@ static int draw_legend(AVFilterContext *ctx, int samples) · 284 unmodified lines
854 }854 }
855 855
856 for (y = 0; ch == 0 && y < h; y += h / 10) {856 for (y = 0; ch == 0 && y < h; y += h / 10) {
857 float value = 120.0 * log10(1. - y / (float)h);857 float value = 120.f * log10f(1.f - y / (float)h);
858 char *text;858 char *text;
859 859
860 if (value < -120)860 if (value < -120)
@@ -896,19 +896,19 @@ static float get_value(AVFilterContext *ctx, int ch, int y) · 35 unmodified lines
896 a = av_clipf(a, 0, 1);896 a = av_clipf(a, 0, 1);
897 break;897 break;
898 case SQRT:898 case SQRT:
899 a = av_clipf(sqrt(a), 0, 1);899 a = av_clipf(sqrtf(a), 0, 1);
900 break;900 break;
901 case CBRT:901 case CBRT:
902 a = av_clipf(cbrt(a), 0, 1);902 a = av_clipf(cbrtf(a), 0, 1);
903 break;903 break;
904 case FOURTHRT:904 case FOURTHRT:
905 a = av_clipf(sqrt(sqrt(a)), 0, 1);905 a = av_clipf(sqrtf(sqrtf(a)), 0, 1);
906 break;906 break;
907 case FIFTHRT:907 case FIFTHRT:
908 a = av_clipf(pow(a, 0.20), 0, 1);908 a = av_clipf(powf(a, 0.20), 0, 1);
909 break;909 break;
910 case LOG:910 case LOG:
911 a = 1 + log10(av_clipd(a, 1e-6, 1)) / 6; // zero = -120dBFS911 a = 1.f + log10f(av_clipf(a, 1e-6, 1)) / 6.f; // zero = -120dBFS
912 break;912 break;
913 default:913 default:
914 av_assert0(0);914 av_assert0(0);
@@ -1128,7 +1128,7 @@ static int config_output(AVFilterLink *outlink) · 213 unmodified lines
1128 generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);1128 generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
1129 if (s->overlap == 1)1129 if (s->overlap == 1)
1130 s->overlap = overlap;1130 s->overlap = overlap;
1131 s->hop_size = (1. - s->overlap) * s->win_size;1131 s->hop_size = (1.f - s->overlap) * s->win_size;
1132 if (s->hop_size < 1) {1132 if (s->hop_size < 1) {
1133 av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);1133 av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
1134 return AVERROR(EINVAL);1134 return AVERROR(EINVAL);
@@ -1137,7 +1137,7 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
1137 for (s->win_scale = 0, i = 0; i < s->win_size; i++) {1137 for (s->win_scale = 0, i = 0; i < s->win_size; i++) {
1138 s->win_scale += s->window_func_lut[i] * s->window_func_lut[i];1138 s->win_scale += s->window_func_lut[i] * s->window_func_lut[i];
1139 }1139 }
1140 s->win_scale = 1. / sqrt(s->win_scale);1140 s->win_scale = 1.f / sqrtf(s->win_scale);
1141 1141
1142 /* prepare the initial picref buffer (black frame) */1142 /* prepare the initial picref buffer (black frame) */
1143 av_frame_free(&s->outpicref);1143 av_frame_free(&s->outpicref);
@@ -1198,8 +1198,8 @@ static int config_output(AVFilterLink *outlink) · 54 unmodified lines
1198 1198
1199#define RE(y, ch) s->fft_data[ch][y].re1199#define RE(y, ch) s->fft_data[ch][y].re
1200#define IM(y, ch) s->fft_data[ch][y].im1200#define IM(y, ch) s->fft_data[ch][y].im
1201#define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))1201#define MAGNITUDE(y, ch) hypotf(RE(y, ch), IM(y, ch))
1202#define PHASE(y, ch) atan2(IM(y, ch), RE(y, ch))1202#define PHASE(y, ch) atan2f(IM(y, ch), RE(y, ch))
1203 1203
1204static int calc_channel_magnitudes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)1204static int calc_channel_magnitudes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1205{1205{
@@ -1639,7 +1639,7 @@ static int showspectrumpic_request_frame(AVFilterLink *outlink) · 433 unmodified lines
1639 if (consumed >= spb) {1639 if (consumed >= spb) {
1640 int h = s->orientation == VERTICAL ? s->h : s->w;1640 int h = s->orientation == VERTICAL ? s->h : s->w;
1641 1641
1642 scale_magnitudes(s, 1. / (consumed / spf));1642 scale_magnitudes(s, 1.f / (consumed / spf));
1643 plot_spectrum_column(inlink, fin);1643 plot_spectrum_column(inlink, fin);
1644 consumed = 0;1644 consumed = 0;
1645 x++;1645 x++;

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