AudioDummy.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * AudioDummy.h - dummy audio-device
  3. *
  4. * Copyright (c) 2004-2014 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_DUMMY_H
  25. #define AUDIO_DUMMY_H
  26. #include "AudioDevice.h"
  27. #include "AudioDeviceSetupWidget.h"
  28. #include "AudioEngine.h"
  29. #include "MicroTimer.h"
  30. class AudioDummy : public QThread, public AudioDevice
  31. {
  32. Q_OBJECT
  33. public:
  34. AudioDummy( bool & _success_ful, AudioEngine* audioEngine ) :
  35. AudioDevice( DEFAULT_CHANNELS, audioEngine )
  36. {
  37. _success_ful = true;
  38. }
  39. virtual ~AudioDummy()
  40. {
  41. stopProcessing();
  42. }
  43. inline static QString name()
  44. {
  45. return QT_TRANSLATE_NOOP( "AudioDeviceSetupWidget", "Dummy (no sound output)" );
  46. }
  47. class setupWidget : public AudioDeviceSetupWidget
  48. {
  49. public:
  50. setupWidget( QWidget * _parent ) :
  51. AudioDeviceSetupWidget( AudioDummy::name(), _parent )
  52. {
  53. }
  54. virtual ~setupWidget()
  55. {
  56. }
  57. void saveSettings() override
  58. {
  59. }
  60. void show() override
  61. {
  62. parentWidget()->hide();
  63. QWidget::show();
  64. }
  65. } ;
  66. private:
  67. void startProcessing() override
  68. {
  69. start();
  70. }
  71. void stopProcessing() override
  72. {
  73. stopProcessingThread( this );
  74. }
  75. void run() override
  76. {
  77. MicroTimer timer;
  78. while( true )
  79. {
  80. timer.reset();
  81. const surroundSampleFrame* b = audioEngine()->nextBuffer();
  82. if( !b )
  83. {
  84. break;
  85. }
  86. if( audioEngine()->hasFifoWriter() )
  87. {
  88. delete[] b;
  89. }
  90. const int microseconds = static_cast<int>( audioEngine()->framesPerPeriod() * 1000000.0f / audioEngine()->processingSampleRate() - timer.elapsed() );
  91. if( microseconds > 0 )
  92. {
  93. usleep( microseconds );
  94. }
  95. }
  96. }
  97. } ;
  98. #endif