AudioPortAudio.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * AudioPortAudio.h - device-class that performs PCM-output via PortAudio
  3. *
  4. * Copyright (c) 2008 Csaba Hruska <csaba.hruska/at/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_PORTAUDIO_H
  25. #define AUDIO_PORTAUDIO_H
  26. #include <QtCore/QObject>
  27. #include "lmmsconfig.h"
  28. #include "ComboBoxModel.h"
  29. class AudioPortAudioSetupUtil : public QObject
  30. {
  31. Q_OBJECT
  32. public slots:
  33. void updateDevices();
  34. void updateChannels();
  35. public:
  36. ComboBoxModel m_backendModel;
  37. ComboBoxModel m_deviceModel;
  38. } ;
  39. #ifdef LMMS_HAVE_PORTAUDIO
  40. #include <portaudio.h>
  41. #include <QtCore/QSemaphore>
  42. #include "AudioDevice.h"
  43. #include "AudioDeviceSetupWidget.h"
  44. #if defined paNeverDropInput || defined paNonInterleaved
  45. # define PORTAUDIO_V19
  46. #else
  47. # define PORTAUDIO_V18
  48. #endif
  49. class ComboBox;
  50. class LcdSpinBox;
  51. class AudioPortAudio : public AudioDevice
  52. {
  53. public:
  54. AudioPortAudio( bool & _success_ful, Mixer* mixer );
  55. virtual ~AudioPortAudio();
  56. inline static QString name()
  57. {
  58. return QT_TRANSLATE_NOOP( "setupWidget", "PortAudio" );
  59. }
  60. int process_callback( const float *_inputBuffer,
  61. float * _outputBuffer,
  62. unsigned long _framesPerBuffer );
  63. class setupWidget : public AudioDeviceSetupWidget
  64. {
  65. public:
  66. setupWidget( QWidget * _parent );
  67. virtual ~setupWidget();
  68. virtual void saveSettings();
  69. private:
  70. ComboBox * m_backend;
  71. ComboBox * m_device;
  72. AudioPortAudioSetupUtil m_setupUtil;
  73. } ;
  74. private:
  75. virtual void startProcessing();
  76. virtual void stopProcessing();
  77. virtual void applyQualitySettings();
  78. #ifdef PORTAUDIO_V19
  79. static int _process_callback( const void *_inputBuffer, void * _outputBuffer,
  80. unsigned long _framesPerBuffer,
  81. const PaStreamCallbackTimeInfo * _timeInfo,
  82. PaStreamCallbackFlags _statusFlags,
  83. void *arg );
  84. #else
  85. #define paContinue 0
  86. #define paComplete 1
  87. #define Pa_GetDeviceCount Pa_CountDevices
  88. #define Pa_GetDefaultInputDevice Pa_GetDefaultInputDeviceID
  89. #define Pa_GetDefaultOutputDevice Pa_GetDefaultOutputDeviceID
  90. #define Pa_IsStreamActive Pa_StreamActive
  91. static int _process_callback( void * _inputBuffer, void * _outputBuffer,
  92. unsigned long _framesPerBuffer, PaTimestamp _outTime, void * _arg );
  93. typedef double PaTime;
  94. typedef PaDeviceID PaDeviceIndex;
  95. typedef struct PaStreamParameters
  96. {
  97. PaDeviceIndex device;
  98. int channelCount;
  99. PaSampleFormat sampleFormat;
  100. PaTime suggestedLatency;
  101. void *hostApiSpecificStreamInfo;
  102. } PaStreamParameters;
  103. #endif
  104. PaStream * m_paStream;
  105. PaStreamParameters m_outputParameters;
  106. PaStreamParameters m_inputParameters;
  107. bool m_wasPAInitError;
  108. surroundSampleFrame * m_outBuf;
  109. int m_outBufPos;
  110. int m_outBufSize;
  111. bool m_stopped;
  112. } ;
  113. #endif
  114. #endif