diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-02-24 22:15:50 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-02-24 22:15:50 +0000 |
| commit | cf1e212c30ec7419b96388e4f78b44cb55bf34c5 (patch) | |
| tree | bef5e7ceb56f8df18af94bd5987b7119b4c40c53 /src/lib/audio_analysis.cc | |
| parent | bbd352c3a0acf312e66b8be0d8bfb475275102d6 (diff) | |
Basic stuff to analyse audio (job).
Diffstat (limited to 'src/lib/audio_analysis.cc')
| -rw-r--r-- | src/lib/audio_analysis.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc new file mode 100644 index 000000000..4a710f4c1 --- /dev/null +++ b/src/lib/audio_analysis.cc @@ -0,0 +1,69 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <stdint.h> +#include <cassert> +#include <fstream> +#include "audio_analysis.h" + +using std::ostream; +using std::string; +using std::ofstream; +using std::vector; + +AudioPoint::AudioPoint () +{ + for (int i = 0; i < COUNT; ++i) { + _data[i] = 0; + } +} + +void +AudioPoint::write (ostream& s) const +{ + for (int i = 0; i < COUNT; ++i) { + s << _data[i] << "\n"; + } +} + + +AudioAnalysis::AudioAnalysis (int channels) +{ + _data.resize (channels); +} + +void +AudioAnalysis::add_point (int c, AudioPoint const & p) +{ + assert (c < int (_data.size ())); + _data[c].push_back (p); +} + +void +AudioAnalysis::write (string filename) +{ + ofstream f (filename.c_str ()); + f << _data.size() << "\n"; + for (vector<vector<AudioPoint> >::iterator i = _data.begin(); i != _data.end(); ++i) { + f << i->size () << "\n"; + for (vector<AudioPoint>::iterator j = i->begin(); j != i->end(); ++j) { + j->write (f); + } + } +} |
