2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "audio_analysis.h"
34 AudioPoint::AudioPoint ()
36 for (int i = 0; i < COUNT; ++i) {
41 AudioPoint::AudioPoint (istream& s)
43 for (int i = 0; i < COUNT; ++i) {
49 AudioPoint::write (ostream& s) const
51 for (int i = 0; i < COUNT; ++i) {
52 s << _data[i] << "\n";
57 AudioAnalysis::AudioAnalysis (int channels)
59 _data.resize (channels);
62 AudioAnalysis::AudioAnalysis (string filename)
64 ifstream f (filename.c_str ());
68 _data.resize (channels);
70 for (int i = 0; i < channels; ++i) {
73 for (int j = 0; j < points; ++j) {
74 _data[i].push_back (AudioPoint (f));
80 AudioAnalysis::add_point (int c, AudioPoint const & p)
82 assert (c < int (_data.size ()));
83 _data[c].push_back (p);
87 AudioAnalysis::get_point (int c, int p) const
89 assert (c < int (_data.size ()));
90 assert (p < int (_data[c].size ()));
95 AudioAnalysis::points (int c) const
97 assert (c < int (_data.size ()));
98 return _data[c].size ();
102 AudioAnalysis::write (string filename)
104 ofstream f (filename.c_str ());
105 f << _data.size() << "\n";
106 for (vector<vector<AudioPoint> >::iterator i = _data.begin(); i != _data.end(); ++i) {
107 f << i->size () << "\n";
108 for (vector<AudioPoint>::iterator j = i->begin(); j != i->end(); ++j) {