1 /* 2 * Copyright 2019 Google LLC 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 * https://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 EFFECTS_APP_DUPLEXSTREAM_H 18 #define EFFECTS_APP_DUPLEXSTREAM_H 19 20 #include <array> 21 #include <algorithm> 22 #include <variant> 23 24 #include <oboe/Oboe.h> 25 #include "FunctionList.h" 26 #include "DuplexCallback.h" 27 28 29 class DuplexEngine { 30 public: 31 DuplexEngine(); 32 33 void beginStreams(); 34 35 virtual ~DuplexEngine() = default; 36 37 oboe::Result startStreams(); 38 39 oboe::Result stopStreams(); 40 41 42 std::variant<FunctionList<int16_t *>, FunctionList<float *>> functionList{ 43 std::in_place_type<FunctionList<int16_t *>>}; 44 45 private: 46 47 void openInStream(); 48 49 void openOutStream(); 50 51 static oboe::AudioStreamBuilder defaultBuilder(); 52 53 template<class numeric> 54 void createCallback(); 55 56 oboe::ManagedStream inStream; 57 std::unique_ptr<oboe::AudioStreamCallback> mCallback; 58 oboe::ManagedStream outStream; 59 60 61 }; 62 63 64 #endif //EFFECTS_APP_DUPLEXSTREAM_H 65