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