tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

channel_buffer.cc (2231B)


      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 "common_audio/channel_buffer.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 
     16 #include "common_audio/include/audio_util.h"
     17 #include "rtc_base/checks.h"
     18 
     19 namespace webrtc {
     20 
     21 IFChannelBuffer::IFChannelBuffer(size_t num_frames,
     22                                 size_t num_channels,
     23                                 size_t num_bands)
     24    : ivalid_(true),
     25      ibuf_(num_frames, num_channels, num_bands),
     26      fvalid_(true),
     27      fbuf_(num_frames, num_channels, num_bands) {}
     28 
     29 IFChannelBuffer::~IFChannelBuffer() = default;
     30 
     31 ChannelBuffer<int16_t>* IFChannelBuffer::ibuf() {
     32  RefreshI();
     33  fvalid_ = false;
     34  return &ibuf_;
     35 }
     36 
     37 ChannelBuffer<float>* IFChannelBuffer::fbuf() {
     38  RefreshF();
     39  ivalid_ = false;
     40  return &fbuf_;
     41 }
     42 
     43 const ChannelBuffer<int16_t>* IFChannelBuffer::ibuf_const() const {
     44  RefreshI();
     45  return &ibuf_;
     46 }
     47 
     48 const ChannelBuffer<float>* IFChannelBuffer::fbuf_const() const {
     49  RefreshF();
     50  return &fbuf_;
     51 }
     52 
     53 void IFChannelBuffer::RefreshF() const {
     54  if (!fvalid_) {
     55    RTC_DCHECK(ivalid_);
     56    fbuf_.set_num_channels(ibuf_.num_channels());
     57    const int16_t* const* int_channels = ibuf_.channels();
     58    float* const* float_channels = fbuf_.channels();
     59    for (size_t i = 0; i < ibuf_.num_channels(); ++i) {
     60      for (size_t j = 0; j < ibuf_.num_frames(); ++j) {
     61        float_channels[i][j] = int_channels[i][j];
     62      }
     63    }
     64    fvalid_ = true;
     65  }
     66 }
     67 
     68 void IFChannelBuffer::RefreshI() const {
     69  if (!ivalid_) {
     70    RTC_DCHECK(fvalid_);
     71    int16_t* const* int_channels = ibuf_.channels();
     72    ibuf_.set_num_channels(fbuf_.num_channels());
     73    const float* const* float_channels = fbuf_.channels();
     74    for (size_t i = 0; i < fbuf_.num_channels(); ++i) {
     75      FloatS16ToS16(float_channels[i], ibuf_.num_frames(), int_channels[i]);
     76    }
     77    ivalid_ = true;
     78  }
     79 }
     80 
     81 }  // namespace webrtc