SpectMorph
smwavdata.hh
1 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html
2 
3 #ifndef SPECTMORPH_WAVE_DATA_HH
4 #define SPECTMORPH_WAVE_DATA_HH
5 
6 #include "smutils.hh"
7 
8 #include <vector>
9 #include <functional>
10 
11 #include <sndfile.h>
12 
13 namespace SpectMorph
14 {
15 
16 class WavData
17 {
18 public:
19  enum class OutFormat { WAV, FLAC };
20 
21 private:
22  std::vector<float> m_samples;
23  float m_mix_freq;
24  int m_n_channels;
25  int m_bit_depth;
26  std::string m_error_blurb;
27 
28  bool save (std::function<SNDFILE* (SF_INFO *)> open_func, OutFormat out_format);
29  bool load (std::function<SNDFILE* (SF_INFO *)> open_func);
30 
31 public:
32  WavData();
33  WavData (const std::vector<float>& samples, int n_channels, float mix_freq, int bit_depth);
34 
35  bool load (const std::vector<unsigned char>& in);
36  bool load (const std::string& filename);
37  bool load_mono (const std::string& filename);
38 
39  void load (const std::vector<float>& samples, int n_channels, float mix_freq, int bit_depth);
40 
41  bool save (const std::string& filename, OutFormat out_format = OutFormat::WAV);
42  bool save (std::vector<unsigned char>& out, OutFormat out_format = OutFormat::WAV);
43 
44  void clear();
45  void prepend (const std::vector<float>& samples);
46 
47  float mix_freq() const;
48  int n_channels() const;
49  size_t n_values() const;
50  int bit_depth() const;
51  const std::vector<float>& samples() const;
52  const char *error_blurb() const;
53 
54  float operator[] (size_t pos) const;
55 };
56 
57 }
58 
59 #endif /* SPECTMORPH_WAVE_DATA_HH */
Definition: smwavdata.hh:17