Phil Burk | 64dce36 | 2018-03-28 15:30:39 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 24 | #include "AudioProcessorBase.h" |
| 25 | |
| 26 | namespace 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. |
| 30 | constexpr float kDefaultMaxHeadroom = 1.41253754f; |
| 31 | constexpr float kDefaultMinHeadroom = -kDefaultMaxHeadroom; |
| 32 | |
| 33 | class ClipToRange : public AudioProcessorBase { |
| 34 | public: |
| 35 | explicit ClipToRange(int32_t channelCount); |
| 36 | |
| 37 | virtual ~ClipToRange() = default; |
| 38 | |
| 39 | int32_t onProcess(int64_t framePosition, int32_t numFrames) override; |
| 40 | |
| 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 | |
| 57 | AudioFloatInputPort input; |
| 58 | AudioFloatOutputPort output; |
| 59 | |
| 60 | private: |
| 61 | float mMinimum = kDefaultMinHeadroom; |
| 62 | float mMaximum = kDefaultMaxHeadroom; |
| 63 | }; |
| 64 | |
| 65 | } /* namespace flowgraph */ |
| 66 | |
| 67 | #endif //FLOWGRAPH_CLIP_TO_RANGE_H |