libKeyFinder
A small C++11 library for estimating the musical key of digital audio.
audiodata.h
1 /*************************************************************************
2 
3  Copyright 2011-2015 Ibrahim Sha'ath
4 
5  This file is part of LibKeyFinder.
6 
7  LibKeyFinder is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  LibKeyFinder is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with LibKeyFinder. If not, see <http://www.gnu.org/licenses/>.
19 
20 *************************************************************************/
21 
22 #ifndef AUDIOSTREAM_H
23 #define AUDIOSTREAM_H
24 
25 #include "constants.h"
26 
27 namespace KeyFinder {
28 
29  class AudioData {
30  public:
31  AudioData();
32 
33  unsigned int getChannels() const;
34  unsigned int getFrameRate() const;
35  double getSample(unsigned int index) const;
36  double getSampleByFrame(unsigned int frame, unsigned int channel) const;
37  double getSampleAtReadIterator() const;
38  unsigned int getSampleCount() const;
39  unsigned int getFrameCount() const;
40 
41  void setChannels(unsigned int newChannels);
42  void setFrameRate(unsigned int newFrameRate);
43  void setSample(unsigned int index, double value);
44  void setSampleByFrame(unsigned int frame, unsigned int channels, double value);
45  void setSampleAtWriteIterator(double value);
46  void addToSampleCount(unsigned int newSamples);
47  void addToFrameCount(unsigned int newFrames);
48 
49  void advanceReadIterator(unsigned int by = 1);
50  void advanceWriteIterator(unsigned int by = 1);
51  bool readIteratorWithinUpperBound() const;
52  bool writeIteratorWithinUpperBound() const;
53  void resetIterators();
54 
55  void append(const AudioData& that);
56  void prepend(const AudioData& that);
57  void discardFramesFromFront(unsigned int discardFrameCount);
58  void reduceToMono();
59  void downsample(unsigned int factor, bool shortcut = true);
60  AudioData* sliceSamplesFromBack(unsigned int sliceSampleCount);
61 
62  private:
63  std::deque<double> samples;
64  unsigned int channels;
65  unsigned int frameRate;
66  std::deque<double>::const_iterator readIterator;
67  std::deque<double>::iterator writeIterator;
68  };
69 
70 }
71 
72 #endif
Definition: audiodata.h:29