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
|
/* define_loudspeakers.c 0.1
(c) Ville Pulkki 2.2.1999 Helsinki University of Technology*/
#include <stdio.h>
#include "define_loudspeakers.h"
void load_ls_triplets(ls lss[MAX_LS_AMOUNT],
struct ls_triplet_chain **ls_triplets,
int ls_amount, char *filename)
{
struct ls_triplet_chain *trip_ptr, *prev;
int i,j,k;
FILE *fp;
char c[10000];
char *toke;
trip_ptr = *ls_triplets;
prev = NULL;
while (trip_ptr != NULL){
prev = trip_ptr;
trip_ptr = trip_ptr->next;
}
if((fp=fopen(filename,"r")) == NULL){
fprintf(stderr,"Could not open loudspeaker setup file.\n");
exit(-1);
}
while(1) {
if(fgets(c,10000,fp) == NULL)
break;
toke = (char *) strtok(c, " ");
if(sscanf(toke, "%d",&i)>0){
toke = (char *) strtok(NULL," ");
sscanf(toke, "%d",&j);
toke = (char *) strtok(NULL," ");
sscanf(toke, "%d",&k);
} else {
break;
}
trip_ptr = (struct ls_triplet_chain*)
malloc (sizeof (struct ls_triplet_chain));
if(prev == NULL)
*ls_triplets = trip_ptr;
else
prev->next = trip_ptr;
trip_ptr->next = NULL;
trip_ptr->ls_nos[0] = i-1;
trip_ptr->ls_nos[1] = j-1;
trip_ptr->ls_nos[2] = k-1;
prev=trip_ptr;
trip_ptr=NULL;
}
}
main(int argc,char **argv)
/* Inits the loudspeaker data. Calls choose_ls_tuplets or _triplets
according to current dimension. The inversion matrices are
stored in transposed form to ease calculation at run time.*/
{
char *s;
int dim;
float tmp;
struct ls_triplet_chain *ls_triplets = NULL;
ls lss[MAX_LS_AMOUNT];
char c[10000];
char *toke;
ang_vec a_vector;
cart_vec c_vector;
int i=0,j;
float azi, ele;
int ls_amount;
FILE *fp;
if(argc != 2 && argc != 3){
fprintf(stderr,"Usage: define_loudspeakers loudspeaker_directions_file [loudspeaker_triplet_file]\n");
exit(-1);
}
if((fp=fopen(argv[1],"r")) == NULL){
fprintf(stderr,"Could not open loudspeaker setup file.%s\n",argv[1]);
exit(-1);
}
fgets(c,10000,fp);
toke = (char *) strtok(c, " ");
sscanf(toke, "%d",&dim);
if (!((dim==2) || (dim == 3))){
fprintf(stderr,"Error in loudspeaker dimension.\n");
exit (-1);
}
printf("File: %s ",argv[1]);
while(1) {
if(fgets(c,10000,fp) == NULL)
break;
toke = (char *) strtok(c, " ");
if(sscanf(toke, "%f",&azi)>0){
if(dim == 3) {
toke = (char *) strtok(NULL," ");
sscanf(toke, "%f",&ele);
} else if(dim == 2) {
ele=0.0;
}
} else {
break;
}
a_vector.azi = azi;
a_vector.ele = ele;
angle_to_cart(&a_vector,&c_vector);
lss[i].coords.x = c_vector.x;
lss[i].coords.y = c_vector.y;
lss[i].coords.z = c_vector.z;
lss[i].angles.azi = a_vector.azi;
lss[i].angles.ele = a_vector.ele;
lss[i].angles.length = 1.0;
i++;
}
ls_amount = i;
if(ls_amount < dim) {
fprintf(stderr,"Too few loudspeakers %d\n",ls_amount);
exit (-1);
}
if(dim == 3){
if(argc==2) /* select triplets */
choose_ls_triplets(lss, &ls_triplets,ls_amount);
else /* load triplets from a file */
load_ls_triplets(lss, &ls_triplets,ls_amount,argv[2]);
calculate_3x3_matrixes(ls_triplets,lss,ls_amount);
} else if (dim ==2) {
choose_ls_tuplets(lss, &ls_triplets,ls_amount);
}
}
|