2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2006 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 "driver_interface.h"
25 #include "JackDriverLoader.h"
32 int JackDummyDriver::Open(jack_nframes_t nframes
,
33 jack_nframes_t samplerate
,
39 const char* capture_driver_name
,
40 const char* playback_driver_name
,
41 jack_nframes_t capture_latency
,
42 jack_nframes_t playback_latency
)
44 int res
= JackAudioDriver::Open(nframes
,
55 fEngineControl
->fPeriod
= 0;
56 fEngineControl
->fComputation
= 500 * 1000;
57 fEngineControl
->fConstraint
= 500 * 1000;
61 int JackDummyDriver::Process()
63 fLastWaitUst
= GetMicroSeconds(); // Take callback date here
64 JackAudioDriver::Process();
65 usleep(std::max(0L, long(fWaitTime
- (GetMicroSeconds() - fLastWaitUst
))));
69 int JackDummyDriver::SetBufferSize(jack_nframes_t buffer_size
)
71 fEngineControl
->fBufferSize
= buffer_size
;
72 fEngineControl
->fPeriodUsecs
= jack_time_t(1000000.f
/ fEngineControl
->fSampleRate
* fEngineControl
->fBufferSize
); // In microsec
76 void JackDummyDriver::PrintState()
78 std::cout
<< "JackDummyDriver state" << std::endl
;
80 jack_port_id_t port_index
;
82 std::cout
<< "Input ports" << std::endl
;
84 for (int i
= 0; i
< fPlaybackChannels
; i
++) {
85 port_index
= fCapturePortList
[i
];
86 JackPort
* port
= fGraphManager
->GetPort(port_index
);
87 std::cout
<< port
->GetName() << std::endl
;
88 if (fGraphManager
->GetConnectionsNum(port_index
)) {}
91 std::cout
<< "Output ports" << std::endl
;
93 for (int i
= 0; i
< fCaptureChannels
; i
++) {
94 port_index
= fPlaybackPortList
[i
];
95 JackPort
* port
= fGraphManager
->GetPort(port_index
);
96 std::cout
<< port
->GetName() << std::endl
;
97 if (fGraphManager
->GetConnectionsNum(port_index
)) {}
101 } // end of namespace
108 jack_driver_desc_t
* driver_get_descriptor () {
109 jack_driver_desc_t
* desc
;
112 desc
= (jack_driver_desc_t
*)calloc (1, sizeof (jack_driver_desc_t
));
113 strcpy(desc
->name
, "dummy");
115 desc
->params
= (jack_driver_param_desc_t
*)calloc (desc
->nparams
, sizeof (jack_driver_param_desc_t
));
118 strcpy(desc
->params
[i
].name
, "capture");
119 desc
->params
[i
].character
= 'C';
120 desc
->params
[i
].type
= JackDriverParamUInt
;
121 desc
->params
[i
].value
.ui
= 2U;
122 strcpy(desc
->params
[i
].short_desc
, "Number of capture ports");
123 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
126 strcpy(desc
->params
[i
].name
, "playback");
127 desc
->params
[i
].character
= 'P';
128 desc
->params
[i
].type
= JackDriverParamUInt
;
129 desc
->params
[1].value
.ui
= 2U;
130 strcpy(desc
->params
[i
].short_desc
, "Number of playback ports");
131 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
134 strcpy(desc
->params
[i
].name
, "rate");
135 desc
->params
[i
].character
= 'r';
136 desc
->params
[i
].type
= JackDriverParamUInt
;
137 desc
->params
[i
].value
.ui
= 48000U;
138 strcpy(desc
->params
[i
].short_desc
, "Sample rate");
139 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
142 strcpy(desc
->params
[i
].name
, "monitor");
143 desc
->params
[i
].character
= 'm';
144 desc
->params
[i
].type
= JackDriverParamBool
;
145 desc
->params
[i
].value
.i
= 0;
146 strcpy(desc
->params
[i
].short_desc
, "Provide monitor ports for the output");
147 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
150 strcpy(desc
->params
[i
].name
, "period");
151 desc
->params
[i
].character
= 'p';
152 desc
->params
[i
].type
= JackDriverParamUInt
;
153 desc
->params
[i
].value
.ui
= 1024U;
154 strcpy(desc
->params
[i
].short_desc
, "Frames per period");
155 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
158 strcpy(desc
->params
[i
].name
, "wait");
159 desc
->params
[i
].character
= 'w';
160 desc
->params
[i
].type
= JackDriverParamUInt
;
161 desc
->params
[i
].value
.ui
= 21333U;
162 strcpy(desc
->params
[i
].short_desc
,
163 "Number of usecs to wait between engine processes");
164 strcpy(desc
->params
[i
].long_desc
, desc
->params
[i
].short_desc
);
169 Jack::JackDriverClientInterface
* driver_initialize(Jack::JackEngine
* engine
, Jack::JackSynchro
** table
, const JSList
* params
) {
170 jack_nframes_t sample_rate
= 48000;
171 jack_nframes_t period_size
= 1024;
172 unsigned int capture_ports
= 2;
173 unsigned int playback_ports
= 2;
174 unsigned long wait_time
= 0;
176 const jack_driver_param_t
* param
;
177 bool monitor
= false;
179 for (node
= params
; node
; node
= jack_slist_next (node
)) {
180 param
= (const jack_driver_param_t
*) node
->data
;
182 switch (param
->character
) {
185 capture_ports
= param
->value
.ui
;
189 playback_ports
= param
->value
.ui
;
193 sample_rate
= param
->value
.ui
;
197 period_size
= param
->value
.ui
;
201 wait_time
= param
->value
.ui
;
205 monitor
= param
->value
.i
;
210 if (wait_time
== 0) // Not set
211 wait_time
= (unsigned long)((((float)period_size
) / ((float)sample_rate
)) * 1000000.0f
);
213 Jack::JackDriverClientInterface
* driver
= new Jack::JackThreadedDriver(new Jack::JackDummyDriver("dummy_pcm", engine
, table
, wait_time
));
214 if (driver
->Open(period_size
, sample_rate
, 1, 1, capture_ports
, playback_ports
, monitor
, "dummy", "dummy", 0, 0) == 0) {