_current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], fabsf (s));
if ((_done % _samples_per_point) == 0) {
- _current[j][AudioPoint::RMS] = 20 * log10 (sqrt (_current[j][AudioPoint::RMS] / _samples_per_point));
- _current[j][AudioPoint::PEAK] = 20 * log10 (_current[j][AudioPoint::PEAK]);
+ _current[j][AudioPoint::RMS] = sqrt (_current[j][AudioPoint::RMS] / _samples_per_point);
_analysis->add_point (j, _current[j]);
_current[j] = AudioPoint ();
using std::ifstream;
using std::vector;
using std::cout;
+using std::max;
+using std::list;
AudioPoint::AudioPoint ()
{
f.close ();
boost::filesystem::rename (tmp, filename);
}
+
+float
+AudioAnalysis::smooth (list<float> const & data, AudioPoint::Type t)
+{
+ float val;
+
+ switch (t) {
+ case AudioPoint::PEAK:
+ /* XXX: fall-off, or something...? */
+ val = -200;
+ for (list<float>::const_iterator i = data.begin(); i != data.end(); ++i) {
+ val = max (val, *i);
+ }
+ return val;
+ case AudioPoint::RMS:
+ val = 0;
+ for (list<float>::const_iterator i = data.begin(); i != data.end(); ++i) {
+ val += pow (*i, 2);
+ }
+ return sqrt (val / data.size());
+ default:
+ assert (false);
+ }
+
+ return 0;
+}
#include <iostream>
#include <vector>
+#include <list>
class AudioPoint
{
void write (std::string);
+ static float smooth (std::list<float> const &, AudioPoint::Type);
private:
std::vector<std::vector<AudioPoint> > _data;
_type_checkbox[i]->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (AudioDialog::type_clicked), 0, this);
}
+ _smoothing = new wxSlider (this, wxID_ANY, 1, 1, 128);
+ _smoothing->Connect (wxID_ANY, wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler (AudioDialog::smoothing_changed), 0, this);
+ table->Add (_smoothing, 1, wxEXPAND);
+ table->AddSpacer (0);
+
sizer->Add (table, 0, wxALL, 12);
SetSizer (sizer);
_plot->set_type_visible (t, _type_checkbox[t]->GetValue ());
}
+
+void
+AudioDialog::smoothing_changed (wxScrollEvent &)
+{
+ _plot->set_smoothing (_smoothing->GetValue ());
+}
void film_changed (Film::Property);
void channel_clicked (wxCommandEvent &);
void type_clicked (wxCommandEvent &);
+ void smoothing_changed (wxScrollEvent &);
void try_to_load_analysis ();
void setup_channels ();
AudioPlot* _plot;
wxCheckBox* _channel_checkbox[MAX_AUDIO_CHANNELS];
wxCheckBox* _type_checkbox[AudioPoint::COUNT];
+ wxSlider* _smoothing;
boost::signals2::scoped_connection _film_changed_connection;
boost::signals2::scoped_connection _film_audio_analysis_finished_connection;
};
using std::cout;
using std::vector;
+using std::list;
using std::max;
using std::min;
using boost::bind;
AudioPlot::AudioPlot (wxWindow* parent)
: wxPanel (parent)
, _gain (0)
+ , _smoothing (1)
{
SetDoubleBuffered (true);
}
path[i] = gc->CreatePath ();
+
+ float const val = 20 * log10 (_analysis->get_point(c, 0)[i]);
+
path[i].MoveToPoint (
db_label_width,
- height - (max (_analysis->get_point(c, 0)[i], float (_minimum)) - _minimum + _gain) * ys - yo
+ height - (max (val, float (_minimum)) - _minimum + _gain) * ys - yo
);
}
+ list<float> smoothing[AudioPoint::COUNT];
+
for (int i = 0; i < _analysis->points(c); ++i) {
for (int j = 0; j < AudioPoint::COUNT; ++j) {
if (!_type_visible[j]) {
continue;
}
+
+ smoothing[j].push_back (_analysis->get_point(c, i)[j]);
+ if (int(smoothing[j].size()) > _smoothing) {
+ smoothing[j].pop_front ();
+ }
+
+ float const val = 20 * log10 (_analysis->smooth (smoothing[j], static_cast<AudioPoint::Type> (j)));
path[j].AddLineToPoint (
i * xs + db_label_width,
- height - (max (_analysis->get_point(c, i)[j], float (_minimum)) - _minimum + _gain) * ys - yo
+ height - (max (val, float (_minimum)) - _minimum + _gain) * ys - yo
);
}
}
_gain = g;
Refresh ();
}
+
+void
+AudioPlot::set_smoothing (int s)
+{
+ _smoothing = s;
+ Refresh ();
+}
void set_channel_visible (int c, bool v);
void set_type_visible (int t, bool v);
void set_gain (float);
+ void set_smoothing (int);
private:
void paint (wxPaintEvent &);
bool _type_visible[AudioPoint::COUNT];
/** gain to apply in dB */
float _gain;
+ int _smoothing;
std::vector<wxColour> _colours;