2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 /** @file src/lib/audio_buffers.h
23 * @brief AudioBuffers class.
27 #ifndef DCPOMATIC_AUDIO_BUFFERS_H
28 #define DCPOMATIC_AUDIO_BUFFERS_H
35 /** @class AudioBuffers
36 * @brief A class to hold multi-channel audio data in float format.
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);
46 AudioBuffers & operator= (AudioBuffers const &);
48 std::shared_ptr<AudioBuffers> clone () const;
49 std::shared_ptr<AudioBuffers> channel (int) const;
51 float* const* data () const {
52 return _data_pointers.data();
55 float const* data (int) const;
58 int channels () const {
63 return _data.empty() ? 0 : _data[0].size();
66 void set_frames (int f);
68 void set_channels(int new_channels);
71 void make_silent (int channel);
72 void make_silent (int from, int frames);
74 void apply_gain (float);
76 void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
77 void copy_channel_from (AudioBuffers const * from, int from_channel, int to_channel);
78 void move (int frames, int from, int to);
79 void accumulate_channel (AudioBuffers const * from, int from_channel, int to_channel, float gain = 1);
80 void accumulate_frames (AudioBuffers const * from, int frames, int read_offset, int write_offset);
81 void append (std::shared_ptr<const AudioBuffers> other);
82 void trim_start (int frames);
85 void allocate (int channels, int frames);
86 void update_data_pointers ();
88 /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
89 std::vector<std::vector<float>> _data;
90 /** Pointers to the data of each vector in _data */
91 std::vector<float*> _data_pointers;