• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_NETEQ_AUDIO_VECTOR_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_
13 
14 #include <string.h>  // Access to size_t.
15 
16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/typedefs.h"
19 
20 namespace webrtc {
21 
22 class AudioVector {
23  public:
24   // Creates an empty AudioVector.
25   AudioVector();
26 
27   // Creates an AudioVector with an initial size.
28   explicit AudioVector(size_t initial_size);
29 
30   virtual ~AudioVector();
31 
32   // Deletes all values and make the vector empty.
33   virtual void Clear();
34 
35   // Copies all values from this vector to |copy_to|. Any contents in |copy_to|
36   // are deleted before the copy operation. After the operation is done,
37   // |copy_to| will be an exact replica of this object.
38   virtual void CopyTo(AudioVector* copy_to) const;
39 
40   // Prepends the contents of AudioVector |prepend_this| to this object. The
41   // length of this object is increased with the length of |prepend_this|.
42   virtual void PushFront(const AudioVector& prepend_this);
43 
44   // Same as above, but with an array |prepend_this| with |length| elements as
45   // source.
46   virtual void PushFront(const int16_t* prepend_this, size_t length);
47 
48   // Same as PushFront but will append to the end of this object.
49   virtual void PushBack(const AudioVector& append_this);
50 
51   // Same as PushFront but will append to the end of this object.
52   virtual void PushBack(const int16_t* append_this, size_t length);
53 
54   // Removes |length| elements from the beginning of this object.
55   virtual void PopFront(size_t length);
56 
57   // Removes |length| elements from the end of this object.
58   virtual void PopBack(size_t length);
59 
60   // Extends this object with |extra_length| elements at the end. The new
61   // elements are initialized to zero.
62   virtual void Extend(size_t extra_length);
63 
64   // Inserts |length| elements taken from the array |insert_this| and insert
65   // them at |position|. The length of the AudioVector is increased by |length|.
66   // |position| = 0 means that the new values are prepended to the vector.
67   // |position| = Size() means that the new values are appended to the vector.
68   virtual void InsertAt(const int16_t* insert_this, size_t length,
69                         size_t position);
70 
71   // Like InsertAt, but inserts |length| zero elements at |position|.
72   virtual void InsertZerosAt(size_t length, size_t position);
73 
74   // Overwrites |length| elements of this AudioVector with values taken from the
75   // array |insert_this|, starting at |position|. The definition of |position|
76   // is the same as for InsertAt(). If |length| and |position| are selected
77   // such that the new data extends beyond the end of the current AudioVector,
78   // the vector is extended to accommodate the new data.
79   virtual void OverwriteAt(const int16_t* insert_this,
80                            size_t length,
81                            size_t position);
82 
83   // Appends |append_this| to the end of the current vector. Lets the two
84   // vectors overlap by |fade_length| samples, and cross-fade linearly in this
85   // region.
86   virtual void CrossFade(const AudioVector& append_this, size_t fade_length);
87 
88   // Returns the number of elements in this AudioVector.
89   virtual size_t Size() const;
90 
91   // Returns true if this AudioVector is empty.
92   virtual bool Empty() const;
93 
94   // Accesses and modifies an element of AudioVector.
95   const int16_t& operator[](size_t index) const;
96   int16_t& operator[](size_t index);
97 
98  private:
99   static const size_t kDefaultInitialSize = 10;
100 
101   void Reserve(size_t n);
102 
103   rtc::scoped_ptr<int16_t[]> array_;
104   size_t first_free_ix_;  // The first index after the last sample in array_.
105                           // Note that this index may point outside of array_.
106   size_t capacity_;  // Allocated number of samples in the array.
107 
108   RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector);
109 };
110 
111 }  // namespace webrtc
112 #endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_
113