blob: 22b780496e91c271875ad2bf5b406bac357fbcaf [file] [log] [blame]
Phil Burk64dce362018-03-28 15:30:39 -07001/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef FLOWGRAPH_CLIP_TO_RANGE_H
18#define FLOWGRAPH_CLIP_TO_RANGE_H
19
20#include <atomic>
21#include <unistd.h>
22#include <sys/types.h>
23
Robert Wu057f0832021-12-03 20:41:07 +000024#include "FlowGraphNode.h"
Phil Burk64dce362018-03-28 15:30:39 -070025
26namespace flowgraph {
27
28// This is 3 dB, (10^(3/20)), to match the maximum headroom in AudioTrack for float data.
29// It is designed to allow occasional transient peaks.
30constexpr float kDefaultMaxHeadroom = 1.41253754f;
31constexpr float kDefaultMinHeadroom = -kDefaultMaxHeadroom;
32
Robert Wu057f0832021-12-03 20:41:07 +000033class ClipToRange : public FlowGraphFilter {
Phil Burk64dce362018-03-28 15:30:39 -070034public:
35 explicit ClipToRange(int32_t channelCount);
36
37 virtual ~ClipToRange() = default;
38
Robert Wu057f0832021-12-03 20:41:07 +000039 int32_t onProcess(int32_t numFrames) override;
Phil Burk64dce362018-03-28 15:30:39 -070040
41 void setMinimum(float min) {
42 mMinimum = min;
43 }
44
45 float getMinimum() const {
46 return mMinimum;
47 }
48
49 void setMaximum(float min) {
50 mMaximum = min;
51 }
52
53 float getMaximum() const {
54 return mMaximum;
55 }
56
Robert Wu057f0832021-12-03 20:41:07 +000057 const char *getName() override {
58 return "ClipToRange";
59 }
Phil Burk64dce362018-03-28 15:30:39 -070060
61private:
62 float mMinimum = kDefaultMinHeadroom;
63 float mMaximum = kDefaultMaxHeadroom;
64};
65
66} /* namespace flowgraph */
67
68#endif //FLOWGRAPH_CLIP_TO_RANGE_H