AudioDummy.h 2.3 KB

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