AudioPortAudio.h 3.4 KB

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