tor-browser

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

audio_frame_manipulator_unittest.cc (2387B)


      1 /*
      2 *  Copyright (c) 2016 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 "modules/audio_mixer/audio_frame_manipulator.h"
     12 
     13 #include <algorithm>
     14 #include <cstddef>
     15 #include <cstdint>
     16 
     17 #include "api/audio/audio_frame.h"
     18 #include "test/gtest.h"
     19 
     20 namespace webrtc {
     21 namespace {
     22 
     23 void FillFrameWithConstants(size_t samples_per_channel,
     24                            size_t number_of_channels,
     25                            int16_t value,
     26                            AudioFrame* frame) {
     27  frame->num_channels_ = number_of_channels;
     28  frame->samples_per_channel_ = samples_per_channel;
     29  int16_t* frame_data = frame->mutable_data();
     30  std::fill(frame_data, frame_data + samples_per_channel * number_of_channels,
     31            value);
     32 }
     33 }  // namespace
     34 
     35 TEST(AudioFrameManipulator, CompareForwardRampWithExpectedResultStereo) {
     36  constexpr int kSamplesPerChannel = 5;
     37  constexpr int kNumberOfChannels = 2;
     38 
     39  // Create a frame with values 5, 5, 5, ... and channels & samples as above.
     40  AudioFrame frame;
     41  FillFrameWithConstants(kSamplesPerChannel, kNumberOfChannels, 5, &frame);
     42 
     43  Ramp(0.0f, 1.0f, &frame);
     44 
     45  const int total_samples = kSamplesPerChannel * kNumberOfChannels;
     46  const int16_t expected_result[total_samples] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4};
     47  const int16_t* frame_data = frame.data();
     48  EXPECT_TRUE(
     49      std::equal(frame_data, frame_data + total_samples, expected_result));
     50 }
     51 
     52 TEST(AudioFrameManipulator, CompareBackwardRampWithExpectedResultMono) {
     53  constexpr int kSamplesPerChannel = 5;
     54  constexpr int kNumberOfChannels = 1;
     55 
     56  // Create a frame with values 5, 5, 5, ... and channels & samples as above.
     57  AudioFrame frame;
     58  FillFrameWithConstants(kSamplesPerChannel, kNumberOfChannels, 5, &frame);
     59 
     60  Ramp(1.0f, 0.0f, &frame);
     61 
     62  const int total_samples = kSamplesPerChannel * kNumberOfChannels;
     63  const int16_t expected_result[total_samples] = {5, 4, 3, 2, 1};
     64  const int16_t* frame_data = frame.data();
     65  EXPECT_TRUE(
     66      std::equal(frame_data, frame_data + total_samples, expected_result));
     67 }
     68 
     69 }  // namespace webrtc