Hand-apply d849d411cff28ef5453085791d0b4d7cd73bd070 from master; replace all assert...
[dcpomatic.git] / src / lib / audio_analysis.cc
index 46477950c90b7617abecee43565d90716dccbf1d..597c04a222cd278ebfd95ccab5b54a2bc246c7d7 100644 (file)
 
 */
 
+#include "audio_analysis.h"
+#include "dcpomatic_assert.h"
+#include "cross.h"
+#include <boost/filesystem.hpp>
 #include <stdint.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;
@@ -44,7 +45,10 @@ AudioPoint::AudioPoint ()
 AudioPoint::AudioPoint (FILE* f)
 {
        for (int i = 0; i < COUNT; ++i) {
-               fscanf (f, "%f", &_data[i]);
+               int n = fscanf (f, "%f", &_data[i]);
+               if (n != 1) {
+                       _data[i] = 0;
+               }
        }
 }
 
@@ -87,7 +91,7 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
 {
        FILE* f = fopen_boost (filename, "r");
 
-       int channels;
+       int channels = 0;
        fscanf (f, "%d", &channels);
        _data.resize (channels);
 
@@ -114,14 +118,14 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
 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];
 }
 
@@ -134,7 +138,7 @@ AudioAnalysis::channels () const
 int
 AudioAnalysis::points (int c) const
 {
-       assert (c < channels ());
+       DCPOMATIC_ASSERT (c < channels ());
        return _data[c].size ();
 }