• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2014 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 #include "webrtc/common_audio/channel_buffer.h"
12 
13 namespace webrtc {
14 
IFChannelBuffer(size_t num_frames,size_t num_channels,size_t num_bands)15 IFChannelBuffer::IFChannelBuffer(size_t num_frames,
16                                  size_t num_channels,
17                                  size_t num_bands)
18     : ivalid_(true),
19       ibuf_(num_frames, num_channels, num_bands),
20       fvalid_(true),
21       fbuf_(num_frames, num_channels, num_bands) {}
22 
ibuf()23 ChannelBuffer<int16_t>* IFChannelBuffer::ibuf() {
24   RefreshI();
25   fvalid_ = false;
26   return &ibuf_;
27 }
28 
fbuf()29 ChannelBuffer<float>* IFChannelBuffer::fbuf() {
30   RefreshF();
31   ivalid_ = false;
32   return &fbuf_;
33 }
34 
ibuf_const() const35 const ChannelBuffer<int16_t>* IFChannelBuffer::ibuf_const() const {
36   RefreshI();
37   return &ibuf_;
38 }
39 
fbuf_const() const40 const ChannelBuffer<float>* IFChannelBuffer::fbuf_const() const {
41   RefreshF();
42   return &fbuf_;
43 }
44 
RefreshF() const45 void IFChannelBuffer::RefreshF() const {
46   if (!fvalid_) {
47     assert(ivalid_);
48     const int16_t* const* int_channels = ibuf_.channels();
49     float* const* float_channels = fbuf_.channels();
50     for (size_t i = 0; i < ibuf_.num_channels(); ++i) {
51       for (size_t j = 0; j < ibuf_.num_frames(); ++j) {
52         float_channels[i][j] = int_channels[i][j];
53       }
54     }
55     fvalid_ = true;
56   }
57 }
58 
RefreshI() const59 void IFChannelBuffer::RefreshI() const {
60   if (!ivalid_) {
61     assert(fvalid_);
62     int16_t* const* int_channels = ibuf_.channels();
63     const float* const* float_channels = fbuf_.channels();
64     for (size_t i = 0; i < ibuf_.num_channels(); ++i) {
65       FloatS16ToS16(float_channels[i],
66                     ibuf_.num_frames(),
67                     int_channels[i]);
68     }
69     ivalid_ = true;
70   }
71 }
72 
73 }  // namespace webrtc
74