Merge.
[dcpomatic.git] / src / lib / audio_buffers.h
1 /*
2     Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <boost/shared_ptr.hpp>
21
22 /** @class AudioBuffers
23  *  @brief A class to hold multi-channel audio data in float format.
24  */
25 class AudioBuffers
26 {
27 public:
28         AudioBuffers (int channels, int frames);
29         AudioBuffers (AudioBuffers const &);
30         AudioBuffers (boost::shared_ptr<const AudioBuffers>);
31         ~AudioBuffers ();
32
33         void ensure_size (int);
34
35         float** data () const {
36                 return _data;
37         }
38         
39         float* data (int) const;
40
41         int channels () const {
42                 return _channels;
43         }
44
45         int frames () const {
46                 return _frames;
47         }
48
49         void set_frames (int f);
50
51         void make_silent ();
52         void make_silent (int c);
53
54         void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
55         void move (int from, int to, int frames);
56         void accumulate_channel (AudioBuffers const *, int, int);
57         void accumulate_frames (AudioBuffers const *, int read_offset, int write_offset, int frames);
58
59 private:
60         /** Number of channels */
61         int _channels;
62         /** Number of frames (where a frame is one sample across all channels) */
63         int _frames;
64         /** Number of frames that _data can hold */
65         int _allocated_frames;
66         /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
67         float** _data;
68 };