22 #include <sys/types.h>
27 int main(
int argc,
char **argv)
29 struct MYSOFA_HRTF *hrtf;
34 printf(
"usage: %s input_SOFA_file output_directory\n", argv[0]);
38 hrtf = mysofa_load(argv[1], &err);
40 printf(
"invalid input SOFA file: %s\n", argv[1]);
44 if (hrtf->DataSamplingRate.elements != 1)
46 sample_rate = hrtf->DataSamplingRate.values[0];
48 err = mkdir(argv[2], 0744);
56 for (i = 0; i < hrtf->M; i++) {
62 int azi = hrtf->SourcePosition.values[i * 3];
63 int ele = hrtf->SourcePosition.values[i * 3 + 1];
64 int dis = hrtf->SourcePosition.values[i * 3 + 2];
65 int size = 8 * hrtf->N;
66 int offset = i * 2 * hrtf->N;
68 snprintf(filename,
sizeof(filename),
"azi_%d_ele_%d_dis_%d.wav", azi, ele, dis);
69 file = fopen(filename,
"w+");
70 fwrite(
"RIFF", 4, 1, file);
71 fwrite(
"\xFF\xFF\xFF\xFF", 4, 1, file);
72 fwrite(
"WAVE", 4, 1, file);
73 fwrite(
"fmt ", 4, 1, file);
74 fwrite(
"\x10\x00\00\00", 4, 1, file);
75 fwrite(
"\x03\x00", 2, 1, file);
76 fwrite(
"\x02\x00", 2, 1, file);
77 fwrite(&sample_rate, 4, 1, file);
78 fwrite(&bytespersec, 4, 1, file);
79 fwrite(&blkalign, 2, 1, file);
80 fwrite(&bps, 2, 1, file);
81 fwrite(
"data", 4, 1, file);
82 fwrite(&size, 4, 1, file);
84 for (j = 0; j < hrtf->N; j++) {
87 l = hrtf->DataIR.values[offset + j];
88 r = hrtf->DataIR.values[offset + j + hrtf->N];
89 fwrite(&l, 4, 1, file);
90 fwrite(&r, 4, 1, file);
int main(int argc, char **argv)
static const uint8_t offset[127][2]