Supporters update.
[dcpomatic.git] / src / lib / audio_buffers.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  src/lib/audio_buffers.h
23  *  @brief AudioBuffers class.
24  */
25
26
27 #ifndef DCPOMATIC_AUDIO_BUFFERS_H
28 #define DCPOMATIC_AUDIO_BUFFERS_H
29
30
31 #include <memory>
32 #include <vector>
33
34
35 /** @class AudioBuffers
36  *  @brief A class to hold multi-channel audio data in float format.
37  */
38 class AudioBuffers
39 {
40 public:
41         AudioBuffers (int channels, int frames);
42         AudioBuffers (AudioBuffers const &);
43         explicit AudioBuffers (std::shared_ptr<const AudioBuffers>);
44         AudioBuffers (std::shared_ptr<const AudioBuffers> other, int frames_to_copy, int read_offset);
45
46         AudioBuffers & operator= (AudioBuffers const &);
47
48         std::shared_ptr<AudioBuffers> clone () const;
49         std::shared_ptr<AudioBuffers> channel (int) const;
50
51         float* const* data () const {
52                 return _data_pointers.data();
53         }
54
55         float const* data (int) const;
56         float* data (int);
57
58         int channels () const {
59                 return _data.size();
60         }
61
62         int frames () const {
63                 return _data[0].size();
64         }
65
66         void set_frames (int f);
67
68         void make_silent ();
69         void make_silent (int channel);
70         void make_silent (int from, int frames);
71
72         void apply_gain (float);
73
74         void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
75         void copy_channel_from (AudioBuffers const * from, int from_channel, int to_channel);
76         void move (int frames, int from, int to);
77         void accumulate_channel (AudioBuffers const * from, int from_channel, int to_channel, float gain = 1);
78         void accumulate_frames (AudioBuffers const * from, int frames, int read_offset, int write_offset);
79         void append (std::shared_ptr<const AudioBuffers> other);
80         void trim_start (int frames);
81
82 private:
83         void allocate (int channels, int frames);
84         void update_data_pointers ();
85
86         /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
87         std::vector<std::vector<float>> _data;
88         /** Pointers to the data of each vector in _data */
89         std::vector<float*> _data_pointers;
90 };
91
92
93 #endif