FFmpeg  4.3
sofa2wavs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <mysofa.h>
26 
27 int main(int argc, char **argv)
28 {
29  struct MYSOFA_HRTF *hrtf;
30  int sample_rate;
31  int err, i, j;
32 
33  if (argc < 3) {
34  printf("usage: %s input_SOFA_file output_directory\n", argv[0]);
35  return 1;
36  }
37 
38  hrtf = mysofa_load(argv[1], &err);
39  if (!hrtf || err) {
40  printf("invalid input SOFA file: %s\n", argv[1]);
41  return 1;
42  }
43 
44  if (hrtf->DataSamplingRate.elements != 1)
45  goto fail;
46  sample_rate = hrtf->DataSamplingRate.values[0];
47 
48  err = mkdir(argv[2], 0744);
49  if (err)
50  goto fail;
51 
52  err = chdir(argv[2]);
53  if (err)
54  goto fail;
55 
56  for (i = 0; i < hrtf->M; i++) {
57  FILE *file;
58  int bps = 32;
59  int blkalign = 8;
60  int bytespersec = blkalign * sample_rate;
61  char filename[1024];
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;
67 
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);
83 
84  for (j = 0; j < hrtf->N; j++) {
85  float l, r;
86 
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);
91  }
92  fclose(file);
93  }
94 
95 fail:
96  mysofa_free(hrtf);
97 
98  return 0;
99 }
main
int main(int argc, char **argv)
Definition: sofa2wavs.c:27
sample_rate
sample_rate
Definition: ffmpeg_filter.c:192
fail
#define fail()
Definition: checkasm.h:123
bps
unsigned bps
Definition: movenc.c:1533
size
int size
Definition: twinvq_data.h:11134
printf
printf("static const uint8_t my_array[100] = {\n")
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
r
#define r
Definition: input.c:40
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
file
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration file
Definition: fate.txt:125
snprintf
#define snprintf
Definition: snprintf.h:34