-
Notifications
You must be signed in to change notification settings - Fork 66
/
circlescope.c
136 lines (106 loc) · 3.49 KB
/
circlescope.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
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
/*
OpenLase - a realtime laser graphics toolkit
Copyright (C) 2009-2011 Hector Martin "marcan" <hector@marcansoft.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define _BSD_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <jack/jack.h>
#include <stdint.h>
#include <math.h>
typedef jack_default_audio_sample_t sample_t;
typedef jack_nframes_t nframes_t;
jack_port_t *in_l;
jack_port_t *in_r;
jack_port_t *out_x;
jack_port_t *out_y;
jack_port_t *out_w;
nframes_t rate;
sample_t max_size = 1.0f;
sample_t min_size = 0.2f;
sample_t boost = 6;
//float w = 110 * (2*M_PI);
float w = 523.251131f / 4.0f * (2*M_PI) / 1;
float pos = 0.0f;
#define MAX(a,b) (((a)<(b))?(b):(a))
#define MIN(a,b) (((a)>(b))?(b):(a))
int process (nframes_t nframes, void *arg)
{
sample_t *i_l = (sample_t *) jack_port_get_buffer (in_l, nframes);
sample_t *i_r = (sample_t *) jack_port_get_buffer (in_r, nframes);
sample_t *o_x = (sample_t *) jack_port_get_buffer (out_x, nframes);
sample_t *o_y = (sample_t *) jack_port_get_buffer (out_y, nframes);
sample_t *o_w = (sample_t *) jack_port_get_buffer (out_w, nframes);
nframes_t frm;
for (frm = 0; frm < nframes; frm++) {
sample_t val = (*i_l++ + *i_r++) / 2;
val *= boost;
val = MAX(MIN(val,1.0f),-1.0f);
val = val * 0.5f + 0.5f;
val *= (max_size - min_size);
val += min_size;
*o_w++ = 1.0f;
*o_x++ = cosf(pos) * val;
*o_y++ = sinf(pos) * val;
pos += w / rate;
while(pos >= (2*M_PI)) {
pos -= (2*M_PI);
}
}
return 0;
}
int bufsize (nframes_t nframes, void *arg)
{
printf ("the maximum buffer size is now %u\n", nframes);
return 0;
}
int srate (nframes_t nframes, void *arg)
{
rate = nframes;
printf ("Sample rate: %u/sec\n", nframes);
return 0;
}
void jack_shutdown (void *arg)
{
exit (1);
}
int main (int argc, char *argv[])
{
jack_client_t *client;
static const char jack_client_name[] = "circlescope";
jack_status_t jack_status;
if ((client = jack_client_open(jack_client_name, JackNullOption, &jack_status)) == 0) {
fprintf (stderr, "jack server not running?\n");
return 1;
}
jack_set_process_callback (client, process, 0);
jack_set_buffer_size_callback (client, bufsize, 0);
jack_set_sample_rate_callback (client, srate, 0);
jack_on_shutdown (client, jack_shutdown, 0);
in_l = jack_port_register (client, "in_l", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
in_r = jack_port_register (client, "in_r", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
out_x = jack_port_register (client, "out_x", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
out_y = jack_port_register (client, "out_y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
out_w = jack_port_register (client, "out_w", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
if (jack_activate (client)) {
fprintf (stderr, "cannot activate client");
return 1;
}
while (1)
sleep(1);
jack_client_close (client);
exit (0);
}