Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AlsaEngine.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. AlsaEngine.h - ALSA Driver
  4. Copyright 2009, Alan Calvert
  5. 2014, Mark McCurry
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef ALSA_ENGINE_H
  18. #define ALSA_ENGINE_H
  19. #include <pthread.h>
  20. #include <string>
  21. #include <alsa/asoundlib.h>
  22. #include <queue>
  23. #include "AudioOut.h"
  24. #include "MidiIn.h"
  25. #include "OutMgr.h"
  26. #include "../Misc/Stereo.h"
  27. class AlsaEngine:public AudioOut, MidiIn
  28. {
  29. public:
  30. AlsaEngine(const SYNTH_T &synth);
  31. ~AlsaEngine();
  32. bool Start();
  33. void Stop();
  34. void setAudioEn(bool nval);
  35. bool getAudioEn() const;
  36. void setMidiEn(bool nval);
  37. bool getMidiEn() const;
  38. protected:
  39. void *AudioThread();
  40. static void *_AudioThread(void *arg);
  41. void *MidiThread();
  42. static void *_MidiThread(void *arg);
  43. private:
  44. bool openMidi();
  45. void stopMidi();
  46. bool openAudio();
  47. void stopAudio();
  48. short *interleave(const Stereo<float *> &smps);
  49. struct {
  50. std::string device;
  51. snd_seq_t *handle;
  52. int alsaId;
  53. pthread_t pThread;
  54. } midi;
  55. struct {
  56. snd_pcm_t *handle;
  57. snd_pcm_hw_params_t *params;
  58. unsigned int sampleRate;
  59. snd_pcm_uframes_t frames;
  60. unsigned int periods;
  61. short *buffer;
  62. pthread_t pThread;
  63. } audio;
  64. void *processAudio();
  65. };
  66. #endif