2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "JackDummyDriver.h"
22 #include "JackEngineControl.h"
23 #include "JackGraphManager.h"
24 #include "JackDriverLoader.h"
25 #include "JackThreadedDriver.h"
26 #include "JackCompilerDeps.h"
33 int JackDummyDriver::Open(jack_nframes_t buffer_size
,
34 jack_nframes_t samplerate
,
40 const char* capture_driver_name
,
41 const char* playback_driver_name
,
42 jack_nframes_t capture_latency
,
43 jack_nframes_t playback_latency
)
45 if (JackAudioDriver::Open(buffer_size
,
55 playback_latency
) == 0) {
56 fEngineControl
->fPeriod
= 0;
57 fEngineControl
->fComputation
= 500 * 1000;
58 fEngineControl
->fConstraint
= 500 * 1000;
65 int JackDummyDriver::Process()
67 JackDriver::CycleTakeBeginTime();
68 JackAudioDriver::Process();
69 JackSleep(std::max(0L, long(fWaitTime
- (GetMicroSeconds() - fBeginDateUst
))));
73 int JackDummyDriver::SetBufferSize(jack_nframes_t buffer_size
)
75 JackAudioDriver::SetBufferSize(buffer_size
);
76 fWaitTime
= (unsigned long)((((float)buffer_size
) / ((float)fEngineControl
->fSampleRate
)) * 1000000.0f
);
87 SERVER_EXPORT jack_driver_desc_t
* driver_get_descriptor () {
88 jack_driver_desc_t
* desc
;
91 desc
= (jack_driver_desc_t
*)calloc (1, sizeof (jack_driver_desc_t
));
92 strcpy(desc
->name
, "dummy"); // size MUST be less then JACK_DRIVER_NAME_MAX + 1
93 strcpy(desc
->desc
, "Timer based backend"); // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
96 desc
->params
= (jack_driver_param_desc_t
*)calloc (desc
->nparams
, sizeof (jack_driver_param_desc_t
));
99 strcpy(desc
->params
[i
].name
, "capture");
100 desc
->params
[i
].character
= 'C';
101 desc
->params
[i
].type
= JackDriverParamUInt
;
102 desc
->params
[i
].value
.ui
= 2U;
103 strcpy(desc
->params
[i
].short_desc
, "Number of capture ports");
104 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
107 strcpy(desc
->params
[i
].name
, "playback");
108 desc
->params
[i
].character
= 'P';
109 desc
->params
[i
].type
= JackDriverParamUInt
;
110 desc
->params
[1].value
.ui
= 2U;
111 strcpy(desc
->params
[i
].short_desc
, "Number of playback ports");
112 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
115 strcpy(desc
->params
[i
].name
, "rate");
116 desc
->params
[i
].character
= 'r';
117 desc
->params
[i
].type
= JackDriverParamUInt
;
118 desc
->params
[i
].value
.ui
= 48000U;
119 strcpy(desc
->params
[i
].short_desc
, "Sample rate");
120 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
123 strcpy(desc
->params
[i
].name
, "monitor");
124 desc
->params
[i
].character
= 'm';
125 desc
->params
[i
].type
= JackDriverParamBool
;
126 desc
->params
[i
].value
.i
= 0;
127 strcpy(desc
->params
[i
].short_desc
, "Provide monitor ports for the output");
128 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
131 strcpy(desc
->params
[i
].name
, "period");
132 desc
->params
[i
].character
= 'p';
133 desc
->params
[i
].type
= JackDriverParamUInt
;
134 desc
->params
[i
].value
.ui
= 1024U;
135 strcpy(desc
->params
[i
].short_desc
, "Frames per period");
136 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
139 strcpy(desc
->params
[i
].name
, "wait");
140 desc
->params
[i
].character
= 'w';
141 desc
->params
[i
].type
= JackDriverParamUInt
;
142 desc
->params
[i
].value
.ui
= 21333U;
143 strcpy(desc
->params
[i
].short_desc
,
144 "Number of usecs to wait between engine processes");
145 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
150 SERVER_EXPORT
Jack::JackDriverClientInterface
* driver_initialize(Jack::JackLockedEngine
* engine
, Jack::JackSynchro
* table
, const JSList
* params
) {
151 jack_nframes_t sample_rate
= 48000;
152 jack_nframes_t period_size
= 1024;
153 unsigned int capture_ports
= 2;
154 unsigned int playback_ports
= 2;
155 unsigned long wait_time
= 0;
157 const jack_driver_param_t
* param
;
158 bool monitor
= false;
160 for (node
= params
; node
; node
= jack_slist_next (node
)) {
161 param
= (const jack_driver_param_t
*) node
->data
;
163 switch (param
->character
) {
166 capture_ports
= param
->value
.ui
;
170 playback_ports
= param
->value
.ui
;
174 sample_rate
= param
->value
.ui
;
178 period_size
= param
->value
.ui
;
182 wait_time
= param
->value
.ui
;
186 monitor
= param
->value
.i
;
191 if (wait_time
== 0) // Not set
192 wait_time
= (unsigned long)((((float)period_size
) / ((float)sample_rate
)) * 1000000.0f
);
194 Jack::JackDriverClientInterface
* driver
= new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine
, table
, wait_time
));
195 if (driver
->Open(period_size
, sample_rate
, 1, 1, capture_ports
, playback_ports
, monitor
, "dummy", "dummy", 0, 0) == 0) {