X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Faudio_plot.cc;h=2a6210164e3a23f66076fc7f1fe063d8ffda7c00;hb=147cca5876dfbdf56e21289c3a36bec4b4850191;hp=23cbabcdc0ee218e337fcb167cf5edf81ce6127b;hpb=d0d93259d096faa0d410a27450445a3a1a16c430;p=dcpomatic.git diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index 23cbabcdc..2a6210164 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -21,7 +21,6 @@ #include #include #include "audio_plot.h" -#include "lib/decoder_factory.h" #include "lib/audio_decoder.h" #include "lib/audio_analysis.h" #include "wx/wx_util.h" @@ -115,7 +114,7 @@ AudioPlot::paint (wxPaintEvent &) wxDouble db_label_height; wxDouble db_label_descent; wxDouble db_label_leading; - gc->GetTextExtent (_("-80dB"), &_db_label_width, &db_label_height, &db_label_descent, &db_label_leading); + gc->GetTextExtent (wxT ("-80dB"), &_db_label_width, &db_label_height, &db_label_descent, &db_label_leading); _db_label_width += 8; @@ -146,7 +145,11 @@ AudioPlot::paint (wxPaintEvent &) plot_peak (p, c); } wxColour const col = _colours[c]; - gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (col.Red(), col.Green(), col.Blue(), col.Alpha() / 2))); +#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9 + gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (col.Red(), col.Green(), col.Blue(), col.Alpha() / 2), 1, wxPENSTYLE_SOLID)); +#else + gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (col.Red(), col.Green(), col.Blue(), col.Alpha() / 2), 1, wxSOLID)); +#endif gc->StrokePath (p); } } @@ -158,7 +161,11 @@ AudioPlot::paint (wxPaintEvent &) plot_rms (p, c); } wxColour const col = _colours[c]; - gc->SetPen (*wxThePenList->FindOrCreatePen (col)); +#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9 + gc->SetPen (*wxThePenList->FindOrCreatePen (col, 1, wxPENSTYLE_SOLID)); +#else + gc->SetPen (*wxThePenList->FindOrCreatePen (col, 1, wxSOLID)); +#endif gc->StrokePath (p); } } @@ -205,21 +212,46 @@ AudioPlot::plot_rms (wxGraphicsPath& path, int channel) const path.MoveToPoint (_db_label_width, y_for_linear (_analysis->get_point(channel, 0)[AudioPoint::RMS])); list smoothing; + int const N = _analysis->points(channel); + + float const first = _analysis->get_point(channel, 0)[AudioPoint::RMS]; + float const last = _analysis->get_point(channel, N - 1)[AudioPoint::RMS]; + + int const before = _smoothing / 2; + int const after = _smoothing - before; + + /* Pre-load the smoothing list */ + for (int i = 0; i < before; ++i) { + smoothing.push_back (first); + } + for (int i = 0; i < after; ++i) { + if (i < N) { + smoothing.push_back (_analysis->get_point(channel, i)[AudioPoint::RMS]); + } else { + smoothing.push_back (last); + } + } + for (int i = 0; i < N; ++i) { - smoothing.push_back (_analysis->get_point(channel, i)[AudioPoint::RMS]); - if (int(smoothing.size()) > _smoothing) { - smoothing.pop_front (); + int const next_for_window = i + after; + + if (next_for_window < N) { + smoothing.push_back (_analysis->get_point(channel, i)[AudioPoint::RMS]); + } else { + smoothing.push_back (last); } + smoothing.pop_front (); + float p = 0; for (list::const_iterator j = smoothing.begin(); j != smoothing.end(); ++j) { p += pow (*j, 2); } p = sqrt (p / smoothing.size ()); - + path.AddLineToPoint (_db_label_width + i * _x_scale, y_for_linear (p)); } }