xref: /aosp_15_r20/external/oboe/apps/OboeTester/app/src/main/cpp/FullDuplexEcho.h (revision 05767d913155b055644481607e6fa1e35e2fe72c)
1 /*
2  * Copyright 2019 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 OBOETESTER_FULL_DUPLEX_ECHO_H
18 #define OBOETESTER_FULL_DUPLEX_ECHO_H
19 
20 #include <unistd.h>
21 #include <sys/types.h>
22 
23 #include "oboe/Oboe.h"
24 #include "analyzer/LatencyAnalyzer.h"
25 #include "FullDuplexStreamWithConversion.h"
26 #include "InterpolatingDelayLine.h"
27 
28 class FullDuplexEcho : public FullDuplexStreamWithConversion {
29 public:
FullDuplexEcho()30     FullDuplexEcho() {
31         setNumInputBurstsCushion(0);
32     }
33 
34     /**
35      * Called when data is available on both streams.
36      * Caller should override this method.
37      */
38     oboe::DataCallbackResult onBothStreamsReadyFloat(
39             const float *inputData,
40             int   numInputFrames,
41             float *outputData,
42             int   numOutputFrames
43     ) override;
44 
45     oboe::Result start() override;
46 
47     double getPeakLevel(int index);
48 
setDelayTime(double delayTimeSeconds)49     void setDelayTime(double delayTimeSeconds) {
50         mDelayTimeSeconds = delayTimeSeconds;
51     }
52 
53 private:
54     std::unique_ptr<InterpolatingDelayLine> mDelayLine;
55     static constexpr double kMaxDelayTimeSeconds = 4.0;
56     double mDelayTimeSeconds = kMaxDelayTimeSeconds;
57     std::atomic<int32_t> mNumChannels{0};
58     std::unique_ptr<PeakDetector[]> mPeakDetectors;
59 
60 };
61 
62 
63 #endif //OBOETESTER_FULL_DUPLEX_ECHO_H
64