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.

83 lines
2.0KB

  1. /*
  2. AlsaEngine.h
  3. Copyright 2009, Alan Calvert
  4. 2010, Mark McCurry
  5. This file is part of ZynAddSubFX, which is free software: you can
  6. redistribute it and/or modify it under the terms of the GNU General
  7. Public License as published by the Free Software Foundation, either
  8. version 3 of the License, or (at your option) any later version.
  9. ZynAddSubFX 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 for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with ZynAddSubFX. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef ALSA_ENGINE_H
  17. #define ALSA_ENGINE_H
  18. #include <pthread.h>
  19. #include <string>
  20. #include <alsa/asoundlib.h>
  21. #include <queue>
  22. #include "AudioOut.h"
  23. #include "MidiIn.h"
  24. #include "OutMgr.h"
  25. #include "../Misc/Stereo.h"
  26. class AlsaEngine:public AudioOut, MidiIn
  27. {
  28. public:
  29. AlsaEngine();
  30. ~AlsaEngine();
  31. bool Start();
  32. void Stop();
  33. void setAudioEn(bool nval);
  34. bool getAudioEn() const;
  35. void setMidiEn(bool nval);
  36. bool getMidiEn() const;
  37. protected:
  38. void *AudioThread();
  39. static void *_AudioThread(void *arg);
  40. void *MidiThread();
  41. static void *_MidiThread(void *arg);
  42. private:
  43. bool openMidi();
  44. void stopMidi();
  45. bool openAudio();
  46. void stopAudio();
  47. short *interleave(const Stereo<float *> &smps);
  48. struct {
  49. std::string device;
  50. snd_seq_t *handle;
  51. int alsaId;
  52. pthread_t pThread;
  53. } midi;
  54. struct {
  55. snd_pcm_t *handle;
  56. snd_pcm_hw_params_t *params;
  57. unsigned int sampleRate;
  58. snd_pcm_uframes_t frames;
  59. unsigned int periods;
  60. short *buffer;
  61. pthread_t pThread;
  62. } audio;
  63. void *processAudio();
  64. };
  65. #endif