blob: ef3a1cf8ea408de4d1c7dd7d15fd97d976f4f591 [file] [log] [blame]
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ4_AUDIO_MULTI_VECTOR_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_AUDIO_MULTI_VECTOR_H_
13
pbos@webrtc.org3f45c2e2013-08-05 16:22:53 +000014#include <string.h> // Access to size_t.
15
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000016#include <vector>
17
18#include "webrtc/modules/audio_coding/neteq4/audio_vector.h"
19#include "webrtc/system_wrappers/interface/constructor_magic.h"
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000020#include "webrtc/typedefs.h"
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000021
22namespace webrtc {
23
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000024class AudioMultiVector {
25 public:
26 // Creates an empty AudioMultiVector with |N| audio channels. |N| must be
27 // larger than 0.
28 explicit AudioMultiVector(size_t N);
29
30 // Creates an AudioMultiVector with |N| audio channels, each channel having
31 // an initial size. |N| must be larger than 0.
32 AudioMultiVector(size_t N, size_t initial_size);
33
34 virtual ~AudioMultiVector();
35
36 // Deletes all values and make the vector empty.
37 virtual void Clear();
38
39 // Clears the vector and inserts |length| zeros into each channel.
40 virtual void Zeros(size_t length);
41
42 // Copies all values from this vector to |copy_to|. Any contents in |copy_to|
43 // are deleted. After the operation is done, |copy_to| will be an exact
44 // replica of this object. The source and the destination must have the same
45 // number of channels.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000046 virtual void CopyFrom(AudioMultiVector* copy_to) const;
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000047
48 // Appends the contents of array |append_this| to the end of this
49 // object. The array is assumed to be channel-interleaved. |length| must be
50 // an even multiple of this object's number of channels.
51 // The length of this object is increased with the |length| divided by the
52 // number of channels.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000053 virtual void PushBackInterleaved(const int16_t* append_this, size_t length);
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000054
55 // Appends the contents of AudioMultiVector |append_this| to this object. The
56 // length of this object is increased with the length of |append_this|.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000057 virtual void PushBack(const AudioMultiVector& append_this);
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000058
59 // Appends the contents of AudioMultiVector |append_this| to this object,
60 // taken from |index| up until the end of |append_this|. The length of this
61 // object is increased.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000062 virtual void PushBackFromIndex(const AudioMultiVector& append_this,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000063 size_t index);
64
65 // Removes |length| elements from the beginning of this object, from each
66 // channel.
67 virtual void PopFront(size_t length);
68
69 // Removes |length| elements from the end of this object, from each
70 // channel.
71 virtual void PopBack(size_t length);
72
73 // Reads |length| samples from each channel and writes them interleaved to
74 // |destination|. The total number of elements written to |destination| is
75 // returned, i.e., |length| * number of channels. If the AudioMultiVector
76 // contains less than |length| samples per channel, this is reflected in the
77 // return value.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000078 virtual size_t ReadInterleaved(size_t length, int16_t* destination) const;
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000079
80 // Like ReadInterleaved() above, but reads from |start_index| instead of from
81 // the beginning.
82 virtual size_t ReadInterleavedFromIndex(size_t start_index,
83 size_t length,
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000084 int16_t* destination) const;
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000085
86 // Like ReadInterleaved() above, but reads from the end instead of from
87 // the beginning.
88 virtual size_t ReadInterleavedFromEnd(size_t length,
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000089 int16_t* destination) const;
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000090
91 // Overwrites each channel in this AudioMultiVector with values taken from
92 // |insert_this|. The values are taken from the beginning of |insert_this| and
93 // are inserted starting at |position|. |length| values are written into each
94 // channel. If |length| and |position| are selected such that the new data
95 // extends beyond the end of the current AudioVector, the vector is extended
96 // to accommodate the new data. |length| is limited to the length of
97 // |insert_this|.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000098 virtual void OverwriteAt(const AudioMultiVector& insert_this,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000099 size_t length,
100 size_t position);
101
102 // Appends |append_this| to the end of the current vector. Lets the two
103 // vectors overlap by |fade_length| samples (per channel), and cross-fade
104 // linearly in this region.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +0000105 virtual void CrossFade(const AudioMultiVector& append_this,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +0000106 size_t fade_length);
107
108 // Returns the number of channels.
109 virtual size_t Channels() const { return channels_.size(); }
110
111 // Returns the number of elements per channel in this AudioMultiVector.
112 virtual size_t Size() const;
113
114 // Verify that each channel can hold at least |required_size| elements. If
115 // not, extend accordingly.
116 virtual void AssertSize(size_t required_size);
117
118 virtual bool Empty() const;
119
120 // Accesses and modifies a channel (i.e., an AudioVector object) of this
121 // AudioMultiVector.
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +0000122 const AudioVector<int16_t>& operator[](size_t index) const;
123 AudioVector<int16_t>& operator[](size_t index);
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +0000124
125 protected:
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +0000126 std::vector<AudioVector<int16_t>*> channels_;
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +0000127
128 private:
129 DISALLOW_COPY_AND_ASSIGN(AudioMultiVector);
130};
131
132} // namespace webrtc
133#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_AUDIO_MULTI_VECTOR_H_