AudioAlsa.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * AudioAlsa.h - device-class that implements ALSA-PCM-output
  3. *
  4. * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  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_ALSA_H
  25. #define AUDIO_ALSA_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_ALSA
  28. // older ALSA-versions might require this
  29. #define ALSA_PCM_NEW_HW_PARAMS_API
  30. #include <alsa/asoundlib.h>
  31. #include <QThread>
  32. #include "AudioDevice.h"
  33. class AudioAlsa : public QThread, public AudioDevice
  34. {
  35. Q_OBJECT
  36. public:
  37. /**
  38. * @brief Contains the relevant information about available ALSA devices
  39. */
  40. class DeviceInfo
  41. {
  42. public:
  43. DeviceInfo(QString const & deviceName, QString const & deviceDescription) :
  44. m_deviceName(deviceName),
  45. m_deviceDescription(deviceDescription)
  46. {}
  47. ~DeviceInfo() {}
  48. QString const & getDeviceName() const { return m_deviceName; }
  49. QString const & getDeviceDescription() const { return m_deviceDescription; }
  50. private:
  51. QString m_deviceName;
  52. QString m_deviceDescription;
  53. };
  54. typedef std::vector<DeviceInfo> DeviceInfoCollection;
  55. public:
  56. AudioAlsa( bool & _success_ful, AudioEngine* audioEngine );
  57. virtual ~AudioAlsa();
  58. inline static QString name()
  59. {
  60. return QT_TRANSLATE_NOOP( "AudioDeviceSetupWidget",
  61. "ALSA (Advanced Linux Sound Architecture)" );
  62. }
  63. static QString probeDevice();
  64. static DeviceInfoCollection getAvailableDevices();
  65. private:
  66. void startProcessing() override;
  67. void stopProcessing() override;
  68. void applyQualitySettings() override;
  69. void run() override;
  70. int setHWParams( const ch_cnt_t _channels, snd_pcm_access_t _access );
  71. int setSWParams();
  72. int handleError( int _err );
  73. snd_pcm_t * m_handle;
  74. snd_pcm_uframes_t m_bufferSize;
  75. snd_pcm_uframes_t m_periodSize;
  76. snd_pcm_hw_params_t * m_hwParams;
  77. snd_pcm_sw_params_t * m_swParams;
  78. bool m_convertEndian;
  79. } ;
  80. #endif
  81. #endif