This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
inprocess.c
110 lines (95 loc) · 3.01 KB
/
inprocess.c
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
/** @file inprocess.c
*
* @brief This demonstrates the basic concepts for writing a client
* that runs within the JACK server process.
*
* For the sake of example, a port_pair_t is allocated in
* jack_initialize(), passed to inprocess() as an argument, then freed
* in jack_finish().
*/
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <jack/jack.h>
/**
* For the sake of example, an instance of this struct is allocated in
* jack_initialize(), passed to inprocess() as an argument, then freed
* in jack_finish().
*/
typedef struct {
jack_port_t *input_port;
jack_port_t *output_port;
} port_pair_t;
/**
* Called in the realtime thread on every process cycle. The entry
* point name was passed to jack_set_process_callback() from
* jack_initialize(). Although this is an internal client, its
* process() interface is identical to @ref simple_client.c.
*
* @return 0 if successful; otherwise jack_finish() will be called and
* the client terminated immediately.
*/
int
inprocess (jack_nframes_t nframes, void *arg)
{
port_pair_t *pp = arg;
jack_default_audio_sample_t *out =
jack_port_get_buffer (pp->output_port, nframes);
jack_default_audio_sample_t *in =
jack_port_get_buffer (pp->input_port, nframes);
memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
return 0; /* continue */
}
/**
* This required entry point is called after the client is loaded by
* jack_internal_client_load().
*
* @param client pointer to JACK client structure.
* @param load_init character string passed to the load operation.
*
* @return 0 if successful; otherwise jack_finish() will be called and
* the client terminated immediately.
*/
int
jack_initialize (jack_client_t *client, const char *load_init)
{
port_pair_t *pp = malloc (sizeof (port_pair_t));
if (pp == NULL)
return 1; /* heap exhausted */
jack_set_process_callback (client, inprocess, pp);
/* create a pair of ports */
pp->input_port = jack_port_register (client, "input",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsInput, 0);
pp->output_port = jack_port_register (client, "output",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput, 0);
/* join the process() cycle */
jack_activate (client);
/* try to connect to the first physical input & output ports */
if (jack_connect (client, "system:capture_1",
jack_port_name (pp->input_port))) {
fprintf (stderr, "cannot connect input port\n");
return 1; /* terminate client */
}
if (jack_connect (client, jack_port_name (pp->output_port),
"system:playback_1")) {
fprintf (stderr, "cannot connect output port\n");
return 1; /* terminate client */
}
return 0; /* success */
}
/**
* This required entry point is called immediately before the client
* is unloaded, which could happen due to a call to
* jack_internal_client_unload(), or a nonzero return from either
* jack_initialize() or inprocess().
*
* @param arg the same parameter provided to inprocess().
*/
void
jack_finish (void *arg)
{
if (arg)
free ((port_pair_t *) arg);
}