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 SOUNDBOARD_ENGINE_H 18 #define SOUNDBOARD_ENGINE_H 19 20 21 #include <oboe/Oboe.h> 22 #include <vector> 23 24 #include "Synth.h" 25 #include <DefaultDataCallback.h> 26 #include <TappableAudioSource.h> 27 #include <IRestartable.h> 28 #include <DefaultErrorCallback.h> 29 30 using namespace oboe; 31 32 class SoundBoardEngine : public IRestartable { 33 34 public: 35 SoundBoardEngine(int32_t numSignals); 36 37 virtual ~SoundBoardEngine(); 38 39 void noteOff(int32_t noteIndex); 40 41 void noteOn(int32_t noteIndex); 42 43 void tap(bool isDown); 44 45 // from IRestartable 46 virtual void restart() override; 47 48 bool start(); 49 bool stop(); 50 51 private: 52 int32_t mNumSignals; 53 54 std::shared_ptr<AudioStream> mStream; 55 std::shared_ptr<Synth> mSynth; 56 std::shared_ptr<DefaultDataCallback> mDataCallback; 57 std::shared_ptr<DefaultErrorCallback> mErrorCallback; 58 59 bool attemptStart(); 60 oboe::Result createPlaybackStream(); 61 void createCallback(int32_t numSignals); 62 }; 63 64 65 #endif //SOUNDBOARD_ENGINE_H 66