Logging improvements to allow prettier displays in the server GUI.
[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 #include <stdint.h>
29
30 /** @class AudioBuffers
31  *  @brief A class to hold multi-channel audio data in float format.
32  *
33  *  The use of int32_t for frame counts in this class is due to the
34  *  round-up to the next power-of-2 code in ::ensure_size; if that
35  *  were changed the frame count could use any integer type.
36  */
37 class AudioBuffers
38 {
39 public:
40         AudioBuffers (int channels, int32_t frames);
41         AudioBuffers (AudioBuffers const &);
42         AudioBuffers (boost::shared_ptr<const AudioBuffers>);
43         ~AudioBuffers ();
44
45         AudioBuffers & operator= (AudioBuffers const &);
46
47         boost::shared_ptr<AudioBuffers> clone () const;
48         boost::shared_ptr<AudioBuffers> channel (int) const;
49
50         void ensure_size (int32_t);
51
52         float** data () const {
53                 return _data;
54         }
55
56         float* data (int) const;
57
58         int channels () const {
59                 return _channels;
60         }
61
62         int frames () const {
63                 return _frames;
64         }
65
66         void set_frames (int32_t f);
67
68         void make_silent ();
69         void make_silent (int c);
70         void make_silent (int32_t from, int32_t frames);
71
72         void apply_gain (float);
73
74         void copy_from (AudioBuffers const * from, int32_t frames_to_copy, int32_t read_offset, int32_t write_offset);
75         void copy_channel_from (AudioBuffers const * from, int from_channel, int to_channel);
76         void move (int32_t from, int32_t to, int32_t frames);
77         void accumulate_channel (AudioBuffers const * from, int from_channel, int to_channel, float gain = 1);
78         void accumulate_frames (AudioBuffers const *, int32_t read_offset, int32_t write_offset, int32_t frames);
79
80 private:
81         void allocate (int channels, int32_t frames);
82         void deallocate ();
83
84         /** Number of channels */
85         int _channels;
86         /** Number of frames (where a frame is one sample across all channels) */
87         int32_t _frames;
88         /** Number of frames that _data can hold */
89         int32_t _allocated_frames;
90         /** Audio data (so that, e.g. _data[2][6] is channel 2, sample 6) */
91         float** _data;
92 };
93
94 #endif