-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_viewer.cpp
165 lines (123 loc) · 4.3 KB
/
model_viewer.cpp
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
154
155
156
157
158
159
160
161
162
163
164
165
/*--------------------
*
* Name : model_viewer.cpp
* Author : Niall Moran
* Licence : GPL
*
--------------------*/
#include "engine.h"
using namespace std;
jack_port_t *input_port;
jack_port_t *output_port;
float *data_array;
int pos;
fftw_complex *fftw_in, *fftw_out, *fftw_in_data, *fftw_data, *window;
fftw_plan *fftw_p, fftw_plan_data;
float **height_map;
int current_window;
int main(int argc, char*argv[]);
int main( int argc, char* argv[] )
{
jack_client_t *client;
const char **ports;
char name[] = "jackvis";
/* try to become a client of the JACK server */
if ((client = jack_client_new (name)) == 0) {
fprintf (stderr, "jack server not running?\n");
return 1;
}
data_array = (float*)malloc(sizeof(float)*DATA_SIZE);
height_map = (float**)malloc(sizeof(float*)*BINS);
for ( int i = 0 ; i < BINS ; i++ ) {
height_map[i] = (float*)malloc(sizeof(float)*BINS);
for ( int j = 0 ; j < BINS ; j++ ) {
height_map[i][j] = 0.0;
}
}
fftw_in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE*2);
for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE*2 ; i++ ) {
fftw_in[i][0] = 0.0; fftw_in[i][1] = 0.0;
}
fftw_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE);
for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE ; i++ ) {
fftw_out[i][0] = 0.0; fftw_out[i][1] = 0.0;
}
fftw_p = (fftw_plan*)malloc(sizeof(fftw_plan)*WINDOW_SIZE);
for ( int i = 0 ; i < WINDOW_SIZE ; i++ ) {
fftw_p[i] = fftw_plan_dft_1d(FRAME_SIZE*WINDOW_SIZE, &(fftw_in[i*FRAME_SIZE]), fftw_out, FFTW_FORWARD, FFTW_ESTIMATE);
}
current_window = 0;
fftw_in_data = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE);
for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE ; i++ ) {
fftw_in_data[i][0] = 0.0; fftw_in[i][1] = 0.0;
}
window = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * FRAME_SIZE*WINDOW_SIZE);
for ( int i = 0 ; i < FRAME_SIZE*WINDOW_SIZE ; i++ ) {
window[i][0] = 0.54 - 0.46 * cos((2.0*PI*((double)i))/((double)(FRAME_SIZE*WINDOW_SIZE-1)));
}
fftw_plan_data = fftw_plan_dft_1d(FRAME_SIZE*WINDOW_SIZE, fftw_in_data, fftw_out, FFTW_FORWARD, FFTW_MEASURE);
for ( int i = 0 ; i < DATA_SIZE ; i++ ) {
data_array[i] = 0.0;
}
pos = 0;
/* tell the JACK server to call `process()' whenever
there is work to be done.
*/
jack_set_process_callback (client, process, 0);
/* tell the JACK server to call `jack_shutdown()' if
it ever shuts down, either entirely, or if it
just decides to stop calling us.
*/
jack_on_shutdown (client, jack_shutdown, 0);
/* display the current sample rate.
*/
//printf ("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);
/* tell the JACK server that we are ready to roll */
if (jack_activate (client)) {
fprintf (stderr, "cannot activate client");
return 1;
}
/* connect the ports. Note: you can't do this before
the client is activated, because we can't allow
connections to be made to clients that aren't
running.
*/
//if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) {
if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsOutput)) == NULL) {
fprintf(stderr, "Cannot find any physical capture ports\n");
exit(1);
}
int j = 0;
while ( ports[j] != NULL ) {
if (jack_connect (client, ports[j], jack_port_name (input_port))) {
fprintf (stderr, "cannot connect input ports\n");
}
j++;
}
free (ports);
/*if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
fprintf(stderr, "Cannot find any physical playback ports\n");
exit(1);
}*/
/*if (jack_connect (client, jack_port_name (output_port), ports[i])) {
fprintf (stderr, "cannot connect output ports\n");
}*/
CEngine *myengine = new CEngine(argc, argv);
myengine->start();
//free (ports);
free(data_array);
for ( int i = 0 ; i < WINDOW_SIZE; i++ ) {
fftw_destroy_plan(fftw_p[i]);
}
free(fftw_p);
fftw_free(fftw_in); fftw_free(fftw_out);
for ( int i = 0 ; i < BINS ; i++ ) {
free(height_map[i]);
}
free(height_map);
jack_client_close (client);
return 0 ;
}