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 24 // TODO #include "flowgraph/FlowGraph.h" 25 #include "oboe/Oboe.h" 26 27 #include "analyzer/PeakDetector.h" 28 #include "FormatConverterBox.h" 29 #include "MultiChannelRecording.h" 30 #include "OboeTesterStreamCallback.h" 31 32 class InputStreamCallbackAnalyzer : public OboeTesterStreamCallback { 33 public: 34 reset()35 void reset() { 36 for (int iChannel = 0; iChannel < mNumChannels; iChannel++) { 37 mPeakDetectors[iChannel].reset(); 38 } 39 OboeTesterStreamCallback::reset(); 40 } 41 setup(int32_t maxFramesPerCallback,int32_t channelCount,oboe::AudioFormat inputFormat)42 void setup(int32_t maxFramesPerCallback, 43 int32_t channelCount, 44 oboe::AudioFormat inputFormat) { 45 mNumChannels = channelCount; 46 mPeakDetectors = std::make_unique<PeakDetector[]>(channelCount); 47 int32_t bufferSize = maxFramesPerCallback * channelCount; 48 mInputConverter = std::make_unique<FormatConverterBox>(bufferSize, 49 inputFormat, 50 oboe::AudioFormat::Float); 51 } 52 53 /** 54 * Called by Oboe when the stream is ready to process audio. 55 */ 56 oboe::DataCallbackResult onAudioReady( 57 oboe::AudioStream *audioStream, 58 void *audioData, 59 int numFrames) override; 60 setRecording(MultiChannelRecording * recording)61 void setRecording(MultiChannelRecording *recording) { 62 mRecording = recording; 63 } 64 65 double getPeakLevel(int index); 66 setMinimumFramesBeforeRead(int32_t numFrames)67 void setMinimumFramesBeforeRead(int32_t numFrames) { 68 mMinimumFramesBeforeRead = numFrames; 69 } 70 getMinimumFramesBeforeRead()71 int32_t getMinimumFramesBeforeRead() { 72 return mMinimumFramesBeforeRead; 73 } 74 75 public: 76 int32_t mNumChannels = 0; 77 std::unique_ptr<PeakDetector[]> mPeakDetectors; 78 MultiChannelRecording *mRecording = nullptr; 79 80 private: 81 std::unique_ptr<FormatConverterBox> mInputConverter; 82 int32_t mMinimumFramesBeforeRead = 0; 83 }; 84 85 #endif //NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H 86