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
392392 }
393393
394394 if (s->stop) {
395− double theta, phi, psi, a, b, S, c;
395+ float theta, phi, psi, a, b, S, c;
396396 FFTComplex *g = s->fft_data[ch];
397397 FFTComplex *h = s->fft_scratch[ch];
398398 int L = s->buf_size;
399399 int N = s->win_size;
400400 int M = s->win_size / 2;
401401
402− phi = 2.0 * M_PI * (s->stop - s->start) / (double)inlink->sample_rate / (M - 1);
403− theta = 2.0 * M_PI * s->start / (double)inlink->sample_rate;
402+ phi = 2.f * M_PI * (s->stop - s->start) / (float)inlink->sample_rate / (M - 1);
403+ theta = 2.f * M_PI * s->start / (float)inlink->sample_rate;
404404
405405 for (int n = 0; n < M; n++) {
406− h[n].re = cos(n * n / 2.0 * phi);
407− h[n].im = sin(n * n / 2.0 * phi);
406+ h[n].re = cosf(n * n / 2.f * phi);
407+ h[n].im = sinf(n * n / 2.f * phi);
408408 }
409409
410410 for (int n = M; n < L; n++) {
411− h[n].re = 0.0;
412− h[n].im = 0.0;
411+ h[n].re = 0.f;
412+ h[n].im = 0.f;
413413 }
414414
415415 for (int n = L - N; n < L; n++) {
416− h[n].re = cos((L - n) * (L - n) / 2.0 * phi);
417− h[n].im = sin((L - n) * (L - n) / 2.0 * phi);
416+ h[n].re = cosf((L - n) * (L - n) / 2.f * phi);
417+ h[n].im = sinf((L - n) * (L - n) / 2.f * phi);
418418 }
419419
420420 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
423423 }
424424
425425 for (int n = N; n < L; n++) {
426− g[n].re = 0.;
427− g[n].im = 0.;
426+ g[n].re = 0.f;
427+ g[n].im = 0.f;
428428 }
429429
430430 for (int n = 0; n < N; n++) {
431− psi = n * theta + n * n / 2.0 * phi;
432− c = cos(psi);
433− S = -sin(psi);
431+ psi = n * theta + n * n / 2.f * phi;
432+ c = cosf(psi);
433+ S = -sinf(psi);
434434 a = c * g[n].re - S * g[n].im;
435435 b = S * g[n].re + c * g[n].im;
436436 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
457457 av_fft_calc(s->ifft[ch], g);
458458
459459 for (int k = 0; k < M; k++) {
460− psi = k * k / 2.0 * phi;
461− c = cos(psi);
462− S = -sin(psi);
460+ psi = k * k / 2.f * phi;
461+ c = cosf(psi);
462+ S = -sinf(psi);
463463 a = c * g[k].re - S * g[k].im;
464464 b = S * g[k].re + c * g[k].im;
465465 s->fft_data[ch][k].re = a;
@@ -555,15 +555,15 @@ static void color_range(ShowSpectrumContext *s, int ch, · 89 unmodified lines
555555
556556 if (s->color_mode == CHANNEL) {
557557 if (s->nb_display_channels > 1) {
558− *uf *= 0.5 * sin((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);
558+ *uf *= 0.5f * sinf((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);
560560 } else {
561− *uf *= 0.5 * sin(M_PI * s->rotation);
562− *vf *= 0.5 * cos(M_PI * s->rotation + M_PI_2);
561+ *uf *= 0.5f * sinf(M_PI * s->rotation);
562+ *vf *= 0.5f * cosf(M_PI * s->rotation + M_PI_2);
563563 }
564564 } else {
565− *uf += *uf * sin(M_PI * s->rotation);
566− *vf += *vf * cos(M_PI * s->rotation + M_PI_2);
565+ *uf += *uf * sinf(M_PI * s->rotation);
566+ *vf += *vf * cosf(M_PI * s->rotation + M_PI_2);
567567 }
568568
569569 *uf *= s->saturation;
@@ -854,7 +854,7 @@ static int draw_legend(AVFilterContext *ctx, int samples) · 284 unmodified lines
854854 }
855855
856856 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);
858858 char *text;
859859
860860 if (value < -120)
@@ -896,19 +896,19 @@ static float get_value(AVFilterContext *ctx, int ch, int y) · 35 unmodified lines
896896 a = av_clipf(a, 0, 1);
897897 break;
898898 case SQRT:
899− a = av_clipf(sqrt(a), 0, 1);
899+ a = av_clipf(sqrtf(a), 0, 1);
900900 break;
901901 case CBRT:
902− a = av_clipf(cbrt(a), 0, 1);
902+ a = av_clipf(cbrtf(a), 0, 1);
903903 break;
904904 case FOURTHRT:
905− a = av_clipf(sqrt(sqrt(a)), 0, 1);
905+ a = av_clipf(sqrtf(sqrtf(a)), 0, 1);
906906 break;
907907 case FIFTHRT:
908− a = av_clipf(pow(a, 0.20), 0, 1);
908+ a = av_clipf(powf(a, 0.20), 0, 1);
909909 break;
910910 case LOG:
911− a = 1 + log10(av_clipd(a, 1e-6, 1)) / 6; // zero = -120dBFS
911+ a = 1.f + log10f(av_clipf(a, 1e-6, 1)) / 6.f; // zero = -120dBFS
912912 break;
913913 default:
914914 av_assert0(0);
@@ -1128,7 +1128,7 @@ static int config_output(AVFilterLink *outlink) · 213 unmodified lines
11281128 generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
11291129 if (s->overlap == 1)
11301130 s->overlap = overlap;
1131− s->hop_size = (1. - s->overlap) * s->win_size;
1131+ s->hop_size = (1.f - s->overlap) * s->win_size;
11321132 if (s->hop_size < 1) {
11331133 av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
11341134 return AVERROR(EINVAL);
@@ -1137,7 +1137,7 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
11371137 for (s->win_scale = 0, i = 0; i < s->win_size; i++) {
11381138 s->win_scale += s->window_func_lut[i] * s->window_func_lut[i];
11391139 }
1140− s->win_scale = 1. / sqrt(s->win_scale);
1140+ s->win_scale = 1.f / sqrtf(s->win_scale);
11411141
11421142 /* prepare the initial picref buffer (black frame) */
11431143 av_frame_free(&s->outpicref);
@@ -1198,8 +1198,8 @@ static int config_output(AVFilterLink *outlink) · 54 unmodified lines
11981198
11991199 #define RE(y, ch) s->fft_data[ch][y].re
12001200 #define IM(y, ch) s->fft_data[ch][y].im
1201−#define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
1202−#define PHASE(y, ch) atan2(IM(y, ch), RE(y, ch))
1201+#define MAGNITUDE(y, ch) hypotf(RE(y, ch), IM(y, ch))
1202+#define PHASE(y, ch) atan2f(IM(y, ch), RE(y, ch))
12031203
12041204 static int calc_channel_magnitudes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
12051205 {
@@ -1639,7 +1639,7 @@ static int showspectrumpic_request_frame(AVFilterLink *outlink) · 433 unmodified lines
16391639 if (consumed >= spb) {
16401640 int h = s->orientation == VERTICAL ? s->h : s->w;
16411641
1642− scale_magnitudes(s, 1. / (consumed / spf));
1642+ scale_magnitudes(s, 1.f / (consumed / spf));
16431643 plot_spectrum_column(inlink, fin);
16441644 consumed = 0;
16451645 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