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