-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjack.cc
154 lines (122 loc) · 3.53 KB
/
jack.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "jack.h"
int
process (jack_nframes_t nframes, void *arg)
{
AudioDriver * driver = (AudioDriver *) arg ;
jack_default_audio_sample_t *in, *out;
in = (float *)jack_port_get_buffer (driver -> input_port, nframes);
out = (float *)jack_port_get_buffer (driver -> output_port, nframes);
driver -> processor -> process (nframes, in, out);
return 0;
}
/**
* JACK calls this shutdown_callback if the server ever shuts down or
* decides to disconnect the client.
*/
void
jack_shutdown (void *arg)
{
exit (1);
}
bool AudioDriver::activate () {
IN
if (jack_activate (client)) {
LOGD ( "cannot activate client");
return false ;
}
/* Connect the ports. You can't do this before the client is
* activated, because we can't make connections to clients
* that aren't running. Note the confusing (but necessary)
* orientation of the driver backend ports: playback ports are
* "input" to the backend, and capture ports are "output" from
* it.
*/
i_ports = jack_get_ports (client, NULL, NULL,
JackPortIsPhysical|JackPortIsOutput);
if (i_ports == NULL) {
LOGD ("no physical capture ports\n");
return false ;
}
if (jack_connect (client, i_ports[0], jack_port_name (input_port))) {
LOGD ( "cannot connect input ports\n");
}
o_ports = jack_get_ports (client, NULL, NULL,
JackPortIsPhysical|JackPortIsInput);
if (o_ports == NULL) {
LOGD ("no physical playback ports\n");
return false ;
}
if (jack_connect (client, jack_port_name (output_port), o_ports[0])) {
LOGD ( "cannot connect output ports\n");
return false ;
}
LOGD ("[audio engine ok]");
//~ free (i_ports);
//~ free (o_ports);
LOGD ("[processor %d] great success!\n", processor -> bypass);
OUT
return true ;
}
bool AudioDriver::deactivate () {
IN
LOGD ("DE activate");
if (jack_deactivate (client)) {
LOGD ( "cannot deactivate client");
return false ;
}
OUT
return true ;
}
bool AudioDriver::open () {
IN
client_name = strdup ("Amp Rack\0");
LOGD ("client name: %s\n", client_name);
client = jack_client_open (client_name, options, &status, server_name);
if (client == NULL) {
LOGD ("jack_client_open() failed, "
"status = 0x%2.0x\n", status);
//~ abort ();
return false ;
}
if (status & JackServerFailed) {
LOGD ("Unable to connect to JACK server\n");
return false ;
}
if (status & JackServerStarted) {
LOGD ("JACK server started\n");
}
if (status & JackNameNotUnique) {
client_name = jack_get_client_name(client);
LOGD ("unique name `%s' assigned\n", client_name);
}
jack_set_process_callback (client, process, this);
jack_on_shutdown (client, jack_shutdown, 0);
LOGD ("engine sample rate: %" PRIu32 "\n",
jack_get_sample_rate (client));
/* create two ports */
input_port = jack_port_register (client, "input",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsInput, 0);
output_port = jack_port_register (client, "output",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput, 0);
if ((input_port == NULL) || (output_port == NULL)) {
LOGD ("no more JACK ports available\n");
exit (1);
}
/* Tell the JACK server that we are ready to roll. Our
* process() callback will start running now. */
OUT
return activate () ;
}
void AudioDriver::close () {
IN
jack_client_close (client);
OUT
}
int AudioDriver::get_sample_rate () {
return jack_get_sample_rate (client);
}
int AudioDriver::get_buffer_size () {
return jack_get_buffer_size (client);
}