lucianodato / noise-repellent

Lv2 suite of plugins for broadband noise reduction
GNU Lesser General Public License v3.0
455 stars 38 forks source link

Apply a preset and the associated state.ttl to a set of files #56

Closed s-leroux closed 6 years ago

s-leroux commented 6 years ago

Hi Luciano, and first of all congratulations for the great work on noise-repellent.

I started using that plug-in from Ardour. But I wonder if it is possible to apply noise-repellent in batch to a set of files, given the state.ttl file and the preset found in an Ardour XML file:

        <lv2 last-preset-uri="" last-preset-label="" parameter-changed-since-last-preset="1" state-dir="state2">
          <Port symbol="reduction" value="10"/>
          <Port symbol="offset" value="0"/>
          <Port symbol="release" value="150"/>
          <Port symbol="masking" value="5"/>
          <Port symbol="transient_protection" value="1"/>
          <Port symbol="whitening" value="0"/>
          <Port symbol="noise_learn" value="0"/>
          <Port symbol="adaptive_noise_learn" value="0"/>
          <Port symbol="reset_noise_profile" value="0"/>
          <Port symbol="Residual_listen" value="0"/>
          <Port symbol="enable" value="1"/>
        </lv2>

I suspect it might be possible with jalv, lv2apply or a similar LV2 container usable from the command line, but I can't find how to do it. Any idea or suggestions?

FrnchFrgg commented 6 years ago

The .ttl file does not contain the noise profile, it is saved elsewhere (with the LV2 state extension). So your approach is doomed to begin with. The problem is that the profile is essentially a big table of real values, which is not what "ports" are made. Maybe some kind of atoms could work, but I doubt it.

What you can do, however, is use NR in adaptative mode, since it would create its profile on the fly. Not as good a result, but still usable.

s-leroux commented 6 years ago

Interesting @FrnchFrgg .

Attached is the state.ttl (with the .txt extension added for GitHub to upload it). That file strongly looked to me as the noise profile. state.ttl.txt

"it is saved elsewhere (with the LV2 state extension)." Could you precise the location?

"What you can do, however, is use NR in adaptative mode, since it would create its profile on the fly. Not as good a result, but still usable." It is not an option. I switched from Audacity noise reduction plug-in because it was not satisfactory and Audacity WAV output in batch chains was downsampled to 16 bits, so if I change my workflow, this will be for a higher output quality. Not a lower one.

"So your approach is doomed to begin with." I can't believe there is no way to restore the state saved by the plug-in. I suspect this is related to the code here, but I can't see how the plug-in locate the "right" profile file.

FrnchFrgg commented 6 years ago

After more testing and advice from rgareus, when you save a preset the noise profile is saved in the ttl when saving a preset. All in the same file (in your home's .lv2/).

An example of such a file is attached. You cannot use lv2apply for that it seems, because lv2apply cannot load a preset, just set port values. jalv would be less automatic. Here noise repellent doesn't work in jalv anyway, some problem with latency query that's not answered in time/correctly.

A way you can achieve what you want is to setup noise repellent in an Ardour bus, with the correct noise profile and settings, then write a command line with your tool of choice that pipes the audio to the input jack port of the bus, and gets the cleaned up audio from the output jack port of the bus to write it to a file. That part could be automatable.

It is enough provided all your files need the same noise-repellent settings.

FrnchFrgg commented 6 years ago

You should ask in #lv2 on freenode how to apply an lv2 plugin to a file on the command line. They are more knowledgeable than me, and your question is not noise-repellent specific IMHO.

FrnchFrgg commented 6 years ago

When you use the preset normally with ardour, the noise profile is in <session path>/plugins/<number1>/state<number2>/ where <number1> represents the plugin id in the session, and <number2> increases at each saved modification. Indeed it is the state.ttl file.

When you save a preset (with the top buttons in the plugin UI), they end up as ~/.lv2/<plugin-name>_<preset-name>.lv2/<preset-name>.ttl

An example of which is following

@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix state: <http://lv2plug.in/ns/ext/state#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/lucianodato/noise-repellent> ;
    rdfs:label "test" ;
    lv2:port [
        lv2:symbol "Residual_listen" ;
        pset:value 0.0
    ] , [
        lv2:symbol "adaptive_noise_learn" ;
        pset:value 0.0
    ] , [
        lv2:symbol "enable" ;
        pset:value 1.0
    ] , [
        lv2:symbol "masking" ;
        pset:value 5.0
    ] , [
        lv2:symbol "noise_learn" ;
        pset:value 0.0
    ] , [
        lv2:symbol "offset" ;
        pset:value 3.0
    ] , [
        lv2:symbol "reduction" ;
        pset:value 10.0
    ] , [
        lv2:symbol "release" ;
        pset:value 150.0
    ] , [
        lv2:symbol "reset_noise_profile" ;
        pset:value 0.0
    ] , [
        lv2:symbol "transient_protection" ;
        pset:value 1.0
    ] , [
        lv2:symbol "whitening" ;
        pset:value 0.0
    ] ;
    state:state [
        <https://github.com/lucianodato/noise-repellent#fftsize> "1024"^^xsd:int ;
        <https://github.com/lucianodato/noise-repellent#nwindow> "643.0"^^xsd:float ;
        <https://github.com/lucianodato/noise-repellent#FFTp2> [
            a atom:Vector ;
            atom:childType atom:Float ;
            rdf:value (
                "0.03420767"^^xsd:float
                "0.06960466"^^xsd:float
                "0.0789343"^^xsd:float
                                [...snip...]
                "0.00000218"^^xsd:float
                "0.00000229"^^xsd:float
                "0.00000282"^^xsd:float
            )
        ]
    ] .
lucianodato commented 6 years ago

Could this be considered fixed with Robin's work on lv2file?