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 "FlowGraphNode.h" 25 26 namespace FLOWGRAPH_OUTER_NAMESPACE { 27 namespace flowgraph { 28 29 // This is 3 dB, (10^(3/20)), to match the maximum headroom in AudioTrack for float data. 30 // It is designed to allow occasional transient peaks. 31 constexpr float kDefaultMaxHeadroom = 1.41253754f; 32 constexpr float kDefaultMinHeadroom = -kDefaultMaxHeadroom; 33 34 class ClipToRange : public FlowGraphFilter { 35 public: 36 explicit ClipToRange(int32_t channelCount); 37 38 virtual ~ClipToRange() = default; 39 40 int32_t onProcess(int32_t numFrames) override; 41 setMinimum(float min)42 void setMinimum(float min) { 43 mMinimum = min; 44 } 45 getMinimum()46 float getMinimum() const { 47 return mMinimum; 48 } 49 setMaximum(float min)50 void setMaximum(float min) { 51 mMaximum = min; 52 } 53 getMaximum()54 float getMaximum() const { 55 return mMaximum; 56 } 57 getName()58 const char *getName() override { 59 return "ClipToRange"; 60 } 61 62 private: 63 float mMinimum = kDefaultMinHeadroom; 64 float mMaximum = kDefaultMaxHeadroom; 65 }; 66 67 } /* namespace flowgraph */ 68 } /* namespace FLOWGRAPH_OUTER_NAMESPACE */ 69 70 #endif //FLOWGRAPH_CLIP_TO_RANGE_H 71