blob: 86e593a9f09836d07158b100d24026d12eec8ee0 [file] [log] [blame]
Alex Loikoe36e8bb2018-02-16 11:54:07 +01001/*
2 * Copyright (c) 2018 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 MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_FRAME_VIEW_H_
12#define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_FRAME_VIEW_H_
13
14#include "api/array_view.h"
15
16// Class to pass audio data in T** format, where T is a numeric type.
17template <class T>
18class AudioFrameView {
19 public:
20 // |num_channels| and |channel_size| describe the T**
21 // |audio_samples|. |audio_samples| is assumed to point to a
22 // two-dimensional |num_channels * channel_size| array of floats.
23 AudioFrameView(T* const* audio_samples,
24 size_t num_channels,
25 size_t channel_size)
26 : audio_samples_(audio_samples),
27 num_channels_(num_channels),
28 channel_size_(channel_size) {}
29
30 AudioFrameView() = delete;
31
32 size_t num_channels() const { return num_channels_; }
33
34 size_t samples_per_channel() const { return channel_size_; }
35
36 rtc::ArrayView<T> channel(size_t idx) {
37 RTC_DCHECK_LE(0, idx);
38 RTC_DCHECK_LE(idx, num_channels_);
39 return rtc::ArrayView<T>(audio_samples_[idx], channel_size_);
40 }
41
42 rtc::ArrayView<const T> channel(size_t idx) const {
43 RTC_DCHECK_LE(0, idx);
44 RTC_DCHECK_LE(idx, num_channels_);
45 return rtc::ArrayView<const T>(audio_samples_[idx], channel_size_);
46 }
47
48 private:
49 T* const* audio_samples_;
50 size_t num_channels_;
51 size_t channel_size_;
52};
53
54#endif // MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_FRAME_VIEW_H_