*/
+#include "audio_analysis.h"
+#include "dcpomatic_assert.h"
+#include "cross.h"
+#include <boost/filesystem.hpp>
#include <stdint.h>
+#include <inttypes.h>
#include <cmath>
#include <cassert>
#include <cstdio>
#include <iostream>
-#include <boost/filesystem.hpp>
-#include "audio_analysis.h"
-#include "cross.h"
using std::ostream;
using std::istream;
AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
{
FILE* f = fopen_boost (filename, "r");
+ if (!f) {
+ throw OpenFileError (filename);
+ }
int channels = 0;
fscanf (f, "%d", &channels);
}
}
+ /* These may not exist in old analysis files, so be careful
+ about reading them.
+ */
+
+ float peak;
+ DCPTime::Type peak_time;
+ if (fscanf (f, "%f%" SCNd64, &peak, &peak_time) == 2) {
+ _peak = peak;
+ _peak_time = DCPTime (peak_time);
+ }
+
fclose (f);
}
void
AudioAnalysis::add_point (int c, AudioPoint const & p)
{
- assert (c < channels ());
+ DCPOMATIC_ASSERT (c < channels ());
_data[c].push_back (p);
}
AudioPoint
AudioAnalysis::get_point (int c, int p) const
{
- assert (p < points (c));
+ DCPOMATIC_ASSERT (p < points (c));
return _data[c][p];
}
int
AudioAnalysis::points (int c) const
{
- assert (c < channels ());
+ DCPOMATIC_ASSERT (c < channels ());
return _data[c].size ();
}
tmp.replace_extension (".tmp");
FILE* f = fopen_boost (tmp, "w");
+ if (!f) {
+ throw OpenFileError (tmp);
+ }
fprintf (f, "%ld\n", _data.size ());
for (vector<vector<AudioPoint> >::iterator i = _data.begin(); i != _data.end(); ++i) {
}
}
+ if (_peak) {
+ fprintf (f, "%f%" PRId64, _peak.get (), _peak_time.get().get ());
+ }
+
fclose (f);
boost::filesystem::rename (tmp, filename);
}