Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 18 | #ifndef NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H |
| 19 | #define NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H |
| 20 | |
| 21 | #include <unistd.h> |
| 22 | #include <sys/types.h> |
| 23 | |
Phil Burk | 328860f | 2019-11-04 18:43:40 -0800 | [diff] [blame] | 24 | // TODO #include "flowgraph/FlowGraph.h" |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 25 | #include "oboe/Oboe.h" |
| 26 | #include "MultiChannelRecording.h" |
Phil Burk | 73bb292 | 2020-09-02 11:00:23 -0700 | [diff] [blame] | 27 | #include "OboeTesterStreamCallback.h" |
Phil Burk | 98b6d1f | 2019-11-05 16:33:13 -0800 | [diff] [blame] | 28 | #include "analyzer/PeakDetector.h" |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 29 | |
| 30 | constexpr int kMaxInputChannels = 8; |
| 31 | |
Phil Burk | 73bb292 | 2020-09-02 11:00:23 -0700 | [diff] [blame] | 32 | class InputStreamCallbackAnalyzer : public OboeTesterStreamCallback { |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 33 | public: |
| 34 | |
| 35 | void reset() { |
| 36 | for (auto detector : mPeakDetectors) { |
| 37 | detector.reset(); |
| 38 | } |
Phil Burk | 73bb292 | 2020-09-02 11:00:23 -0700 | [diff] [blame] | 39 | OboeTesterStreamCallback::reset(); |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Called by Oboe when the stream is ready to process audio. |
| 44 | */ |
| 45 | oboe::DataCallbackResult onAudioReady( |
| 46 | oboe::AudioStream *audioStream, |
| 47 | void *audioData, |
| 48 | int numFrames) override; |
| 49 | |
| 50 | void setRecording(MultiChannelRecording *recording) { |
| 51 | mRecording = recording; |
| 52 | } |
| 53 | |
| 54 | double getPeakLevel(int index) { |
| 55 | return mPeakDetectors[index].getLevel(); |
| 56 | } |
| 57 | |
Phil Burk | bbde5bb | 2019-09-02 16:00:18 -0700 | [diff] [blame] | 58 | void setMinimumFramesBeforeRead(int32_t numFrames) { |
| 59 | mMinimumFramesBeforeRead = numFrames; |
| 60 | } |
| 61 | |
| 62 | int32_t getMinimumFramesBeforeRead() { |
| 63 | return mMinimumFramesBeforeRead; |
| 64 | } |
| 65 | |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 66 | public: |
| 67 | PeakDetector mPeakDetectors[kMaxInputChannels]; |
| 68 | MultiChannelRecording *mRecording = nullptr; |
Phil Burk | bbde5bb | 2019-09-02 16:00:18 -0700 | [diff] [blame] | 69 | |
| 70 | private: |
| 71 | int32_t mMinimumFramesBeforeRead = 0; |
Phil Burk | 0433d8f | 2018-11-21 16:41:25 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | #endif //NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H |