zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

AlsaEngine.h (1808B)


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