SndioEngine.h (1733B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 SndioEngine.h - SNDIO Driver 5 Copyright (C) 2020 Kinichiro Inoguchi 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 */ 12 13 #ifndef SNDIO_ENGINE_H 14 #define SNDIO_ENGINE_H 15 16 #include <pthread.h> 17 #include <queue> 18 #include <sndio.h> 19 #include <string> 20 21 #include "AudioOut.h" 22 #include "MidiIn.h" 23 #include "OutMgr.h" 24 #include "../Misc/Stereo.h" 25 26 namespace zyn { 27 28 class SndioEngine:public AudioOut, MidiIn 29 { 30 public: 31 SndioEngine(const SYNTH_T &synth); 32 ~SndioEngine(); 33 34 bool Start(); 35 void Stop(); 36 37 void setAudioEn(bool nval); 38 bool getAudioEn() const; 39 void setMidiEn(bool nval); 40 bool getMidiEn() const; 41 42 protected: 43 void *AudioThread(); 44 static void *_AudioThread(void *arg); 45 void *MidiThread(); 46 static void *_MidiThread(void *arg); 47 48 private: 49 bool openAudio(); 50 void stopAudio(); 51 bool openMidi(); 52 void stopMidi(); 53 54 void *processAudio(); 55 void *processMidi(); 56 short *interleave(const Stereo<float *> &smps); 57 void showAudioInfo(struct sio_hdl *handle); 58 59 struct { 60 struct sio_hdl *handle; 61 struct sio_par params; 62 short *buffer; 63 size_t buffer_size; 64 pthread_t pThread; 65 float peaks[1]; 66 } audio; 67 68 struct { 69 std::string device; 70 struct mio_hdl *handle; 71 bool exiting; 72 pthread_t pThread; 73 } midi; 74 }; 75 76 } 77 78 #endif