• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 OBOE_LIVEEFFECTENGINE_H
18 #define OBOE_LIVEEFFECTENGINE_H
19 
20 #include <jni.h>
21 #include <oboe/Oboe.h>
22 #include <string>
23 #include <thread>
24 #include "FullDuplexPass.h"
25 
26 class LiveEffectEngine : public oboe::AudioStreamCallback {
27    public:
28     LiveEffectEngine();
29     ~LiveEffectEngine();
30     void setRecordingDeviceId(int32_t deviceId);
31     void setPlaybackDeviceId(int32_t deviceId);
32     /**
33      * @param isOn
34      * @return true if it succeeds
35      */
36     bool setEffectOn(bool isOn);
37 
38     /*
39      * oboe::AudioStreamCallback interface implementation
40      */
41     oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream,
42                                           void *audioData, int32_t numFrames) override;
43     void onErrorBeforeClose(oboe::AudioStream *oboeStream, oboe::Result error) override;
44     void onErrorAfterClose(oboe::AudioStream *oboeStream, oboe::Result error) override;
45 
46     bool setAudioApi(oboe::AudioApi);
47     bool isAAudioSupported(void);
48 
49    private:
50     FullDuplexPass mFullDuplexPass;
51     bool mIsEffectOn = false;
52     int32_t mRecordingDeviceId = oboe::kUnspecified;
53     int32_t mPlaybackDeviceId = oboe::kUnspecified;
54     oboe::AudioFormat mFormat = oboe::AudioFormat::I16;
55     int32_t mSampleRate = oboe::kUnspecified;
56     int32_t mInputChannelCount = oboe::ChannelCount::Stereo;
57     int32_t mOutputChannelCount = oboe::ChannelCount::Stereo;
58 
59     std::shared_ptr<oboe::AudioStream> mRecordingStream;
60     std::shared_ptr<oboe::AudioStream> mPlayStream;
61 
62     oboe::AudioApi mAudioApi = oboe::AudioApi::AAudio;
63 
64     oboe::Result openStreams();
65     void closeStream(std::shared_ptr<oboe::AudioStream> &stream);
66 
67     oboe::AudioStreamBuilder *setupCommonStreamParameters(
68         oboe::AudioStreamBuilder *builder);
69     oboe::AudioStreamBuilder *setupRecordingStreamParameters(
70         oboe::AudioStreamBuilder *builder);
71     oboe::AudioStreamBuilder *setupPlaybackStreamParameters(
72         oboe::AudioStreamBuilder *builder);
73     void warnIfNotLowLatency(std::shared_ptr<oboe::AudioStream> &stream);
74 };
75 
76 #endif  // OBOE_LIVEEFFECTENGINE_H
77