blob: fc26b1f8c2784a07f4c990fba4741072fdfaad03 [file] [log] [blame]
Phil Burk0433d8f2018-11-21 16:41:25 -08001/*
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 Burk328860f2019-11-04 18:43:40 -080024// TODO #include "flowgraph/FlowGraph.h"
Phil Burk0433d8f2018-11-21 16:41:25 -080025#include "oboe/Oboe.h"
26#include "MultiChannelRecording.h"
Phil Burk73bb2922020-09-02 11:00:23 -070027#include "OboeTesterStreamCallback.h"
Phil Burk98b6d1f2019-11-05 16:33:13 -080028#include "analyzer/PeakDetector.h"
Phil Burk0433d8f2018-11-21 16:41:25 -080029
30constexpr int kMaxInputChannels = 8;
31
Phil Burk73bb2922020-09-02 11:00:23 -070032class InputStreamCallbackAnalyzer : public OboeTesterStreamCallback {
Phil Burk0433d8f2018-11-21 16:41:25 -080033public:
34
35 void reset() {
36 for (auto detector : mPeakDetectors) {
37 detector.reset();
38 }
Phil Burk73bb2922020-09-02 11:00:23 -070039 OboeTesterStreamCallback::reset();
Phil Burk0433d8f2018-11-21 16:41:25 -080040 }
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 Burkbbde5bb2019-09-02 16:00:18 -070058 void setMinimumFramesBeforeRead(int32_t numFrames) {
59 mMinimumFramesBeforeRead = numFrames;
60 }
61
62 int32_t getMinimumFramesBeforeRead() {
63 return mMinimumFramesBeforeRead;
64 }
65
Phil Burk0433d8f2018-11-21 16:41:25 -080066public:
67 PeakDetector mPeakDetectors[kMaxInputChannels];
68 MultiChannelRecording *mRecording = nullptr;
Phil Burkbbde5bb2019-09-02 16:00:18 -070069
70private:
71 int32_t mMinimumFramesBeforeRead = 0;
Phil Burk0433d8f2018-11-21 16:41:25 -080072};
73
74#endif //NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H