Jack2 1.9.12

JackDummyDriver.cpp
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4
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.
9
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.
14
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.
18
19 */
20
21 #include "JackDummyDriver.h"
22 #include "JackDriverLoader.h"
23 #include "JackThreadedDriver.h"
24 #include "JackCompilerDeps.h"
25 #include <iostream>
26 #include <unistd.h>
27 #include <math.h>
28
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34
35 SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor () {
36 jack_driver_desc_t * desc;
37 jack_driver_desc_filler_t filler;
38 jack_driver_param_value_t value;
39
40 desc = jack_driver_descriptor_construct("dummy", JackDriverMaster, "Timer based backend", &filler);
41
42 value.ui = 2U;
43 jack_driver_descriptor_add_parameter(desc, &filler, "capture", 'C', JackDriverParamUInt, &value, NULL, "Number of capture ports", NULL);
44 jack_driver_descriptor_add_parameter(desc, &filler, "playback", 'P', JackDriverParamUInt, &value, NULL, "Number of playback ports", NULL);
45
46 value.ui = 48000U;
47 jack_driver_descriptor_add_parameter(desc, &filler, "rate", 'r', JackDriverParamUInt, &value, NULL, "Sample rate", NULL);
48
49 value.i = 0;
50 jack_driver_descriptor_add_parameter(desc, &filler, "monitor", 'm', JackDriverParamBool, &value, NULL, "Provide monitor ports for the output", NULL);
51
52 value.ui = 1024U;
53 jack_driver_descriptor_add_parameter(desc, &filler, "period", 'p', JackDriverParamUInt, &value, NULL, "Frames per period", NULL);
54
55 value.ui = 21333U;
56 jack_driver_descriptor_add_parameter(desc, &filler, "wait", 'w', JackDriverParamUInt, &value, NULL, "Number of usecs to wait between engine processes", NULL);
57
58 return desc;
59 }
60
61 SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) {
62 jack_nframes_t sample_rate = 48000;
63 jack_nframes_t buffer_size = 1024;
64 unsigned int capture_ports = 2;
65 unsigned int playback_ports = 2;
66 int wait_time = 0;
67 const JSList * node;
68 const jack_driver_param_t * param;
69 bool monitor = false;
70
71 for (node = params; node; node = jack_slist_next (node)) {
72 param = (const jack_driver_param_t *) node->data;
73
74 switch (param->character) {
75
76 case 'C':
77 capture_ports = param->value.ui;
78 break;
79
80 case 'P':
81 playback_ports = param->value.ui;
82 break;
83
84 case 'r':
85 sample_rate = param->value.ui;
86 break;
87
88 case 'p':
89 buffer_size = param->value.ui;
90 break;
91
92 case 'w':
93 wait_time = param->value.ui;
94 break;
95
96 case 'm':
97 monitor = param->value.i;
98 break;
99 }
100 }
101
102 if (wait_time > 0) {
103 buffer_size = lroundf((float(wait_time) * float(sample_rate)) / 1000000.0f);
104 }
105
106 if (buffer_size > BUFFER_SIZE_MAX) {
107 buffer_size = BUFFER_SIZE_MAX;
108 jack_error("Buffer size set to %d", BUFFER_SIZE_MAX);
109 }
110
111 Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine, table));
112 if (driver->Open(buffer_size, sample_rate, 1, 1, capture_ports, playback_ports, monitor, "dummy", "dummy", 0, 0) == 0) {
113 return driver;
114 } else {
115 delete driver;
116 return NULL;
117 }
118 }
119
120 #ifdef __cplusplus
121 }
122 #endif
Jack::JackThreadedDriver
The base class for threaded drivers using a "decorator" pattern. Threaded drivers are used with block...
Definition: JackThreadedDriver.h:34
Jack::JackLockedEngine
Locked Engine, access to methods is serialized using a mutex.
Definition: JackLockedEngine.h:78
jack_driver_param_value_t
Definition: driver_interface.h:64
Jack::JackPosixSemaphore
Inter process synchronization using POSIX semaphore.
Definition: JackPosixSemaphore.h:36
jack_error
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:92
Jack::JackDummyDriver
The dummy driver.
Definition: JackDummyDriver.h:33
jack_driver_desc_filler_t
Definition: driver_interface.h:142
Jack::JackDriverClientInterface
The base interface for drivers clients.
Definition: JackDriver.h:114
jack_driver_param_t
Definition: driver_interface.h:125
_JSList
Definition: linux/alsa/jslist.h:35
jack_driver_desc_t
Definition: driver_interface.h:132