Some missing copy constructors / operator= / noncopyable.
[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         AudioBuffers & operator= (AudioBuffers const &);
34
35         void ensure_size (int);
36
37         float** data () const {
38                 return _data;
39         }
40         
41         float* data (int) const;
42
43         int channels () const {
44                 return _channels;
45         }
46
47         int frames () const {
48                 return _frames;
49         }
50
51         void set_frames (int f);
52
53         void make_silent ();
54         void make_silent (int c);
55         void make_silent (int from, int frames);
56
57         void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
58         void move (int from, int to, int frames);
59         void accumulate_channel (AudioBuffers const *, int, int);
60         void accumulate_frames (AudioBuffers const *, int read_offset, int write_offset, int frames);
61
62 private:
63         void allocate (int, int);
64         void deallocate ();
65         
66         /** Number of channels */
67         int _channels;
68         /** Number of frames (where a frame is one sample across all channels) */
69         int _frames;
70         /** Number of frames that _data can hold */
71         int _allocated_frames;
72         /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
73         float** _data;
74 };