1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
// An object to hold and pass around audio samples internally.
#pragma once
#include "audio.hpp"
#include <vector>
#include <array>
namespace VideoStitch {
namespace Audio {
/** \class AudioTrack
* \brief An object for holding and passing around audio data
* An audio channel holds the samples from a single track.
*/
class AudioTrack : public std::vector<audioSample_t> {
public:
/**
* @brief Constructs a track with the given channel type
* @param c Channel type
*/
explicit AudioTrack(ChannelMap c = NO_SPEAKER);
~AudioTrack();
AudioTrack& operator=(AudioTrack&&);
AudioTrack(AudioTrack&&);
/**
* @brief Returns the channel type
* @return The channel type of the corresponding track
*/
ChannelMap channel() const;
/**
* @brief Sets the channel type
* @param Channel type to set
* @return void
*/
void setChannel(ChannelMap);
// XXX TODO FIXME temporary
AudioTrack clone() const {
AudioTrack myclone = *this;
return myclone;
}
private:
friend class AudioBlock;
AudioTrack& operator=(const AudioTrack&) = default;
AudioTrack(const AudioTrack&) = default;
ChannelMap channel_;
};
/// \class AudioBlock
/// \brief An object for holding and passing around audio data
/// An AudioBlock is a sequence of audio channels.
class VS_EXPORT AudioBlock {
public:
typedef AudioTrack value_type;
typedef AudioTrack& reference;
typedef const AudioTrack& const_reference;
typedef std::ptrdiff_t difference_type;
typedef channel_t size_type;
typedef std::array<AudioTrack, MAX_AUDIO_CHANNELS> data_buffer_t;
explicit AudioBlock(ChannelLayout layout = UNKNOWN, mtime_t timestamp = 0);
explicit AudioBlock(unsigned char nbTracks, mtime_t timestamp = 0);
// AudioBlock(const AudioBlock&) = delete;
// AudioBlock& operator=(const AudioBlock&) = delete;
AudioBlock(AudioBlock&& o);
AudioBlock& operator=(AudioBlock&& o);
~AudioBlock();
/// \fn void setChannelLayout(const ChannelLayout layout)
/// \param layout The new channel layout
void setChannelLayout(const ChannelLayout layout);
/// \fn void setTimestamp(mtime_t time)
/// \param time The new timestamp, in microseconds
void setTimestamp(mtime_t time);
/// \fn void getTimestamp()
/// \return The object's timestamp, in microseconds
mtime_t getTimestamp() const;
/// \fn void getLayout()
/// \return The channel layout
ChannelLayout getLayout() const;
/// \fn void clear()
/// \brief Clear all audio data
void clear();
/// \fn void swap()
/// \brief swap an audio block with an other
void swap(AudioBlock&);
/// \fn size_type size()
/// \return return the number of tracks in the audio block
size_type size();
/// \fn void swap()
/// \brief swap an audio block with an other
size_type max_size();
/// \fn bool empty()
/// \return true if the container is empty, false otherwise
bool empty() const;
/// \fn void resize()
/// \brief resize all tracks of the audio block
/// \param size in samples
void resize(size_t n);
/// \fn void assign()
/// \brief assign nSamples at the value val
/// \param size in samples
/// \param value to set the samples
void assign(size_t nSamples, audioSample_t val);
/// \fn void numSamples()
/// \return return number of samples in the block
size_t numSamples() const;
class iterator;
/// \class AudioBlock::iterator
/// \brief Iterator on the different channels of the AudioBlock (immutable version)
class const_iterator {
public:
typedef std::ptrdiff_t difference_type;
typedef const AudioTrack value_type;
typedef const AudioTrack& const_reference;
typedef data_buffer_t::const_iterator const_pointer;
typedef std::random_access_iterator_tag iterator_category;
const_iterator();
const_iterator(ChannelLayout, std::array<AudioTrack, MAX_AUDIO_CHANNELS>::iterator);
const_iterator(const const_iterator&);
explicit const_iterator(const iterator&);
~const_iterator();
channel_t channel() const;
const_iterator& operator=(const const_iterator&);
bool operator==(const const_iterator&) const;
bool operator!=(const const_iterator&) const;
const_iterator& operator++();
const_reference operator*() const;
const_pointer operator->() const;
const_reference operator[](size_type) const;
protected:
void advance();
int64_t mask_ = 1;
ChannelLayout layout_;
std::array<AudioTrack, MAX_AUDIO_CHANNELS>::iterator ptr_;
};
/// \class AudioBlock::iterator
/// \brief Iterator on the different channels of the AudioBlock (mutable version)
class iterator : public const_iterator {
public:
typedef std::ptrdiff_t difference_type;
typedef AudioTrack value_type;
typedef AudioTrack& reference;
typedef data_buffer_t::iterator pointer;
typedef std::random_access_iterator_tag iterator_category;
iterator();
iterator(ChannelLayout, data_buffer_t::iterator);
iterator(const iterator&);
~iterator();
iterator& operator=(const iterator&);
bool operator==(const iterator&) const;
bool operator!=(const iterator&) const;
iterator& operator++();
reference operator*() const;
pointer operator->() const;
reference operator[](size_type) const;
};
iterator begin();
const_iterator begin() const;
const_iterator cbegin() const;
iterator end();
const_iterator end() const;
const_iterator cend() const;
reference operator[](size_type);
const_reference operator[](size_type) const;
reference at(size_type);
const_reference at(size_type) const;
AudioBlock& operator+=(const AudioBlock& rhs);
friend AudioBlock operator+(AudioBlock& lhs, const AudioBlock& rhs) {
lhs += rhs;
return lhs;
}
// XXX TODO FIXME temporary
AudioBlock clone() const {
AudioBlock myclone = *this;
return myclone;
}
private:
AudioBlock(const AudioBlock& o); // XXX TODO FIXME delete me
AudioBlock& operator=(const AudioBlock&) = default;
ChannelLayout layout_;
mtime_t timestamp_;
data_buffer_t data_;
};
} // namespace Audio
} // namespace VideoStitch