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.

82 lines
1.8KB

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