diff mbox

[FFmpeg-devel,2/2] tools: add sofa2wavs

Message ID 20170609114401.29263-2-onemda@gmail.com
State Accepted
Commit 1a30bf60be9243830b68e8fe2e20539f08a85926
Headers show

Commit Message

Paul B Mahol June 9, 2017, 11:44 a.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 Makefile          |  1 +
 tools/Makefile    |  1 +
 tools/sofa2wavs.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)
 create mode 100644 tools/sofa2wavs.c

Comments

wm4 June 9, 2017, 2:34 p.m. UTC | #1
On Fri,  9 Jun 2017 13:44:01 +0200
Paul B Mahol <onemda@gmail.com> wrote:

> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  Makefile          |  1 +
>  tools/Makefile    |  1 +
>  tools/sofa2wavs.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 81 insertions(+)
>  create mode 100644 tools/sofa2wavs.c
> 
> diff --git a/Makefile b/Makefile
> index 685b613..a2df8b9 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -82,6 +82,7 @@ target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o $(FF_DEP_LIBS)
>  	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH)

Again: if this tool is needed anyway, why not make a minimal custom
file format that will make the filter nicer to use?
Paul B Mahol June 9, 2017, 3:02 p.m. UTC | #2
On 6/9/17, wm4 <nfxjfg@googlemail.com> wrote:
> On Fri,  9 Jun 2017 13:44:01 +0200
> Paul B Mahol <onemda@gmail.com> wrote:
>
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  Makefile          |  1 +
>>  tools/Makefile    |  1 +
>>  tools/sofa2wavs.c | 79
>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 81 insertions(+)
>>  create mode 100644 tools/sofa2wavs.c
>>
>> diff --git a/Makefile b/Makefile
>> index 685b613..a2df8b9 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -82,6 +82,7 @@ target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o
>> $(FF_DEP_LIBS)
>>  	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS)
>> $(LIBFUZZER_PATH)
>
> Again: if this tool is needed anyway, why not make a minimal custom
> file format that will make the filter nicer to use?

wav is minimal custom format, I already said that I do not want to invent new
minimal format for storing HRIRs.

But I will not block the patch that will do that, so feel free to post patch.
wm4 June 9, 2017, 4:07 p.m. UTC | #3
On Fri, 9 Jun 2017 17:02:37 +0200
Paul B Mahol <onemda@gmail.com> wrote:

> On 6/9/17, wm4 <nfxjfg@googlemail.com> wrote:
> > On Fri,  9 Jun 2017 13:44:01 +0200
> > Paul B Mahol <onemda@gmail.com> wrote:
> >  
> >> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> >> ---
> >>  Makefile          |  1 +
> >>  tools/Makefile    |  1 +
> >>  tools/sofa2wavs.c | 79
> >> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >>  3 files changed, 81 insertions(+)
> >>  create mode 100644 tools/sofa2wavs.c
> >>
> >> diff --git a/Makefile b/Makefile
> >> index 685b613..a2df8b9 100644
> >> --- a/Makefile
> >> +++ b/Makefile
> >> @@ -82,6 +82,7 @@ target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o
> >> $(FF_DEP_LIBS)
> >>  	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS)
> >> $(LIBFUZZER_PATH)  
> >
> > Again: if this tool is needed anyway, why not make a minimal custom
> > file format that will make the filter nicer to use?  
> 
> wav is minimal custom format, I already said that I do not want to invent new
> minimal format for storing HRIRs.

Even then the user has to build a quite complicated graph to feed the
various wav files to the filter. For what reason?
Paul B Mahol June 9, 2017, 4:16 p.m. UTC | #4
On 6/9/17, wm4 <nfxjfg@googlemail.com> wrote:
> On Fri, 9 Jun 2017 17:02:37 +0200
> Paul B Mahol <onemda@gmail.com> wrote:
>
>> On 6/9/17, wm4 <nfxjfg@googlemail.com> wrote:
>> > On Fri,  9 Jun 2017 13:44:01 +0200
>> > Paul B Mahol <onemda@gmail.com> wrote:
>> >
>> >> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> >> ---
>> >>  Makefile          |  1 +
>> >>  tools/Makefile    |  1 +
>> >>  tools/sofa2wavs.c | 79
>> >> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >>  3 files changed, 81 insertions(+)
>> >>  create mode 100644 tools/sofa2wavs.c
>> >>
>> >> diff --git a/Makefile b/Makefile
>> >> index 685b613..a2df8b9 100644
>> >> --- a/Makefile
>> >> +++ b/Makefile
>> >> @@ -82,6 +82,7 @@ target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o
>> >> $(FF_DEP_LIBS)
>> >>  	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS)
>> >> $(LIBFUZZER_PATH)
>> >
>> > Again: if this tool is needed anyway, why not make a minimal custom
>> > file format that will make the filter nicer to use?
>>
>> wav is minimal custom format, I already said that I do not want to invent
>> new
>> minimal format for storing HRIRs.
>
> Even then the user has to build a quite complicated graph to feed the
> various wav files to the filter. For what reason?

To load/read/use only what is needed. And it does not need to be wavs it can be
any format FFmpeg supports.

Note that minimal format is possible, it would just be dump of
libmysofa struct as
it is stored in memory.
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 685b613..a2df8b9 100644
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,7 @@  target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o $(FF_DEP_LIBS)
 	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH)
 
 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
+tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS)
 tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/target_dec_%_fuzzer$(EXESUF): $(FF_DEP_LIBS)
diff --git a/tools/Makefile b/tools/Makefile
index 3ebd361..3909e7c 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -1,4 +1,5 @@ 
 TOOLS = qt-faststart trasher uncoded_frame
+TOOLS-$(CONFIG_LIBMYSOFA) += sofa2wavs
 TOOLS-$(CONFIG_ZLIB) += cws2fws
 
 tools/target_dec_%_fuzzer.o: tools/target_dec_fuzzer.c
diff --git a/tools/sofa2wavs.c b/tools/sofa2wavs.c
new file mode 100644
index 0000000..f85e54f
--- /dev/null
+++ b/tools/sofa2wavs.c
@@ -0,0 +1,79 @@ 
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <mysofa.h>
+
+int main(int argc, char **argv)
+{
+    struct MYSOFA_HRTF *hrtf;
+    int sample_rate;
+    int err, i, j;
+
+    if (argc < 3) {
+        printf("usage: %s input_SOFA_file output_directory\n", argv[0]);
+        return 1;
+    }
+
+    hrtf = mysofa_load(argv[1], &err);
+    if (!hrtf || err) {
+        printf("invalid input SOFA file: %s\n", argv[1]);
+        return 1;
+    }
+
+    if (hrtf->DataSamplingRate.elements != 1)
+        goto fail;
+    sample_rate = hrtf->DataSamplingRate.values[0];
+
+    err = mkdir(argv[2], 0744);
+    if (err)
+        goto fail;
+
+    err = chdir(argv[2]);
+    if (err)
+        goto fail;
+
+    for (i = 0; i < hrtf->M; i++) {
+        FILE *file;
+        int bps = 32;
+        int blkalign = 8;
+        int bytespersec = blkalign * sample_rate;
+        char filename[1024];
+        int azi = hrtf->SourcePosition.values[i * 3];
+        int ele = hrtf->SourcePosition.values[i * 3 + 1];
+        int dis = hrtf->SourcePosition.values[i * 3 + 2];
+        int size = 8 * hrtf->N;
+        int offset = i * 2 * hrtf->N;
+
+        snprintf(filename, sizeof(filename), "azi_%d_ele_%d_dis_%d.wav", azi, ele, dis);
+        file = fopen(filename, "w+");
+        fwrite("RIFF", 4, 1, file);
+        fwrite("\xFF\xFF\xFF\xFF", 4, 1, file);
+        fwrite("WAVE", 4, 1, file);
+        fwrite("fmt ", 4, 1, file);
+        fwrite("\x10\x00\00\00", 4, 1, file);
+        fwrite("\x03\x00", 2, 1, file);
+        fwrite("\x02\x00", 2, 1, file);
+        fwrite(&sample_rate, 4, 1, file);
+        fwrite(&bytespersec, 4, 1, file);
+        fwrite(&blkalign, 2, 1, file);
+        fwrite(&bps, 2, 1, file);
+        fwrite("data", 4, 1, file);
+        fwrite(&size, 4, 1, file);
+
+        for (j = 0; j < hrtf->N; j++) {
+            float l, r;
+
+            l = hrtf->DataIR.values[offset + j];
+            r = hrtf->DataIR.values[offset + j + hrtf->N];
+            fwrite(&l, 4, 1, file);
+            fwrite(&r, 4, 1, file);
+        }
+        fclose(file);
+    }
+
+fail:
+    mysofa_free(hrtf);
+
+    return 0;
+}