AudioSoundIo.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * AudioSoundIo.h - device-class that performs PCM-output via libsoundio
  3. *
  4. * Copyright (c) 2015 Andrew Kelley <superjoe30@gmail.com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef AUDIO_SOUNDIO_H
  25. #define AUDIO_SOUNDIO_H
  26. #include <QtCore/QObject>
  27. #include "lmmsconfig.h"
  28. #include "ComboBoxModel.h"
  29. #ifdef LMMS_HAVE_SOUNDIO
  30. #include <soundio/soundio.h>
  31. #include "AudioDevice.h"
  32. #include "AudioDeviceSetupWidget.h"
  33. class ComboBox;
  34. class LcdSpinBox;
  35. // Exists only to work around "Error: Meta object features not supported for nested classes"
  36. class AudioSoundIoSetupUtil : public QObject
  37. {
  38. Q_OBJECT
  39. public:
  40. virtual ~AudioSoundIoSetupUtil();
  41. void *m_setupWidget;
  42. public slots:
  43. void updateDevices();
  44. void reconnectSoundIo();
  45. };
  46. class AudioSoundIo : public AudioDevice
  47. {
  48. public:
  49. AudioSoundIo( bool & _success_ful, Mixer* mixer );
  50. virtual ~AudioSoundIo();
  51. inline static QString name()
  52. {
  53. return QT_TRANSLATE_NOOP( "setupWidget", "soundio" );
  54. }
  55. class setupWidget : public AudioDeviceSetupWidget
  56. {
  57. public:
  58. setupWidget( QWidget * _parent );
  59. virtual ~setupWidget();
  60. virtual void saveSettings();
  61. void updateDevices();
  62. void reconnectSoundIo();
  63. private:
  64. AudioSoundIoSetupUtil m_setupUtil;
  65. ComboBox * m_backend;
  66. ComboBox * m_device;
  67. ComboBoxModel m_backendModel;
  68. ComboBoxModel m_deviceModel;
  69. SoundIo * m_soundio;
  70. struct DeviceId {
  71. QString id;
  72. bool is_raw;
  73. };
  74. QList<DeviceId> m_deviceList;
  75. int m_defaultOutIndex;
  76. bool m_isFirst;
  77. } ;
  78. private:
  79. virtual void startProcessing();
  80. virtual void stopProcessing();
  81. SoundIo *m_soundio;
  82. SoundIoOutStream *m_outstream;
  83. surroundSampleFrame * m_outBuf;
  84. int m_outBufSize;
  85. fpp_t m_outBufFramesTotal;
  86. fpp_t m_outBufFrameIndex;
  87. bool m_stopped;
  88. int m_disconnectErr;
  89. void onBackendDisconnect(int err);
  90. void writeCallback(int frame_count_min, int frame_count_max);
  91. void errorCallback(int err);
  92. void underflowCallback();
  93. static void staticWriteCallback(SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) {
  94. return ((AudioSoundIo *)outstream->userdata)->writeCallback(frame_count_min, frame_count_max);
  95. }
  96. static void staticErrorCallback(SoundIoOutStream *outstream, int err) {
  97. return ((AudioSoundIo *)outstream->userdata)->errorCallback(err);
  98. }
  99. static void staticUnderflowCallback(SoundIoOutStream *outstream) {
  100. return ((AudioSoundIo *)outstream->userdata)->underflowCallback();
  101. }
  102. static void staticOnBackendDisconnect(SoundIo *soundio, int err) {
  103. return ((AudioSoundIo *)soundio->userdata)->onBackendDisconnect(err);
  104. }
  105. };
  106. #endif
  107. #endif