tor-browser

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

audio_frame_operations.h (3268B)


      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 AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_
     12 #define AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 
     17 #include "api/audio/audio_frame.h"
     18 #include "api/audio/audio_view.h"
     19 
     20 namespace webrtc {
     21 
     22 // TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h.
     23 // Change reference parameters to pointers. Consider using a namespace rather
     24 // than a class.
     25 class AudioFrameOperations {
     26 public:
     27  // Downmixes 4 channels `src_audio` to stereo `dst_audio`. This is an in-place
     28  // operation, meaning `src_audio` and `dst_audio` may point to the same
     29  // buffer.
     30  static void QuadToStereo(InterleavedView<const int16_t> src_audio,
     31                           InterleavedView<int16_t> dst_audio);
     32 
     33  // `frame.num_channels_` will be updated. This version checks that
     34  // `num_channels_` is 4 channels.
     35  static int QuadToStereo(AudioFrame* frame);
     36 
     37  // Downmixes `src_channels` `src_audio` to `dst_channels` `dst_audio`.
     38  // This is an in-place operation, meaning `src_audio` and `dst_audio`
     39  // may point to the same buffer. Supported channel combinations are
     40  // Stereo to Mono, Quad to Mono, and Quad to Stereo.
     41  static void DownmixChannels(InterleavedView<const int16_t> src_audio,
     42                              InterleavedView<int16_t> dst_audio);
     43 
     44  // `frame.num_channels_` will be updated. This version checks that
     45  // `num_channels_` and `dst_channels` are valid and performs relevant downmix.
     46  // Supported channel combinations are N channels to Mono, and Quad to Stereo.
     47  static void DownmixChannels(size_t dst_channels, AudioFrame* frame);
     48 
     49  // `frame.num_channels_` will be updated. This version checks that
     50  // `num_channels_` and `dst_channels` are valid and performs relevant
     51  // downmix. Supported channel combinations are Mono to N
     52  // channels. The single channel is replicated.
     53  static void UpmixChannels(size_t target_number_of_channels,
     54                            AudioFrame* frame);
     55 
     56  // Swap the left and right channels of `frame`. Fails silently if `frame` is
     57  // not stereo.
     58  static void SwapStereoChannels(AudioFrame* frame);
     59 
     60  // Conditionally zero out contents of `frame` for implementing audio mute:
     61  //  `previous_frame_muted` &&  `current_frame_muted` - Zero out whole frame.
     62  //  `previous_frame_muted` && !`current_frame_muted` - Fade-in at frame start.
     63  // !`previous_frame_muted` &&  `current_frame_muted` - Fade-out at frame end.
     64  // !`previous_frame_muted` && !`current_frame_muted` - Leave frame untouched.
     65  static void Mute(AudioFrame* frame,
     66                   bool previous_frame_muted,
     67                   bool current_frame_muted);
     68 
     69  // Zero out contents of frame.
     70  static void Mute(AudioFrame* frame);
     71 
     72  static int ScaleWithSat(float scale, AudioFrame* frame);
     73 };
     74 
     75 }  // namespace webrtc
     76 
     77 #endif  // AUDIO_UTILITY_AUDIO_FRAME_OPERATIONS_H_