2 * Copyright (c) 2017 Paul B Mahol
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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++) {
60 int bytespersec = blkalign * sample_rate;
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);