• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "MultiChannelRecording.h"
27 #include "OboeTesterStreamCallback.h"
28 #include "analyzer/PeakDetector.h"
29 
30 constexpr int kMaxInputChannels = 8;
31 
32 class InputStreamCallbackAnalyzer : public OboeTesterStreamCallback {
33 public:
34 
reset()35     void reset() {
36         for (auto detector : mPeakDetectors) {
37             detector.reset();
38         }
39         OboeTesterStreamCallback::reset();
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 
setRecording(MultiChannelRecording * recording)50     void setRecording(MultiChannelRecording *recording) {
51         mRecording = recording;
52     }
53 
getPeakLevel(int index)54     double getPeakLevel(int index) {
55         return mPeakDetectors[index].getLevel();
56     }
57 
setMinimumFramesBeforeRead(int32_t numFrames)58     void setMinimumFramesBeforeRead(int32_t numFrames) {
59         mMinimumFramesBeforeRead = numFrames;
60     }
61 
getMinimumFramesBeforeRead()62     int32_t getMinimumFramesBeforeRead() {
63         return mMinimumFramesBeforeRead;
64     }
65 
66 public:
67     PeakDetector            mPeakDetectors[kMaxInputChannels];
68     MultiChannelRecording  *mRecording = nullptr;
69 
70 private:
71     int32_t                 mMinimumFramesBeforeRead = 0;
72 };
73 
74 #endif //NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H
75