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 #ifndef DVDOMATIC_AUDIO_BUFFERS_H
21 #define DVDOMATIC_AUDIO_BUFFERS_H
22
23 #include <boost/shared_ptr.hpp>
24
25 /** @class AudioBuffers
26  *  @brief A class to hold multi-channel audio data in float format.
27  */
28 class AudioBuffers
29 {
30 public:
31         AudioBuffers (int channels, int frames);
32         AudioBuffers (AudioBuffers const &);
33         AudioBuffers (boost::shared_ptr<const AudioBuffers>);
34         ~AudioBuffers ();
35
36         AudioBuffers & operator= (AudioBuffers const &);
37
38         void ensure_size (int);
39
40         float** data () const {
41                 return _data;
42         }
43         
44         float* data (int) const;
45
46         int channels () const {
47                 return _channels;
48         }
49
50         int frames () const {
51                 return _frames;
52         }
53
54         void set_frames (int f);
55
56         void make_silent ();
57         void make_silent (int c);
58         void make_silent (int from, int frames);
59
60         void apply_gain (float);
61
62         void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
63         void move (int from, int to, int frames);
64         void accumulate_channel (AudioBuffers const *, int, int, float gain = 1);
65         void accumulate_frames (AudioBuffers const *, int read_offset, int write_offset, int frames);
66
67 private:
68         void allocate (int, int);
69         void deallocate ();
70         
71         /** Number of channels */
72         int _channels;
73         /** Number of frames (where a frame is one sample across all channels) */
74         int _frames;
75         /** Number of frames that _data can hold */
76         int _allocated_frames;
77         /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
78         float** _data;
79 };
80
81 #endif