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 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. class AlsaEngine:public AudioOut, MidiIn
  22. {
  23. public:
  24. AlsaEngine(const SYNTH_T &synth);
  25. ~AlsaEngine();
  26. bool Start();
  27. void Stop();
  28. void setAudioEn(bool nval);
  29. bool getAudioEn() const;
  30. void setMidiEn(bool nval);
  31. bool getMidiEn() const;
  32. protected:
  33. void *AudioThread();
  34. static void *_AudioThread(void *arg);
  35. void *MidiThread();
  36. static void *_MidiThread(void *arg);
  37. private:
  38. bool openMidi();
  39. void stopMidi();
  40. bool openAudio();
  41. void stopAudio();
  42. short *interleave(const Stereo<float *> &smps);
  43. struct {
  44. std::string device;
  45. snd_seq_t *handle;
  46. int alsaId;
  47. bool exiting;
  48. pthread_t pThread;
  49. } midi;
  50. struct {
  51. snd_pcm_t *handle;
  52. snd_pcm_hw_params_t *params;
  53. unsigned int sampleRate;
  54. snd_pcm_uframes_t frames;
  55. unsigned int periods;
  56. short *buffer;
  57. pthread_t pThread;
  58. float peaks[1];
  59. } audio;
  60. void *processAudio();
  61. };
  62. #endif