title
Products            Buy            Support Forum            Professional            About            Codec Central
 

External DSP: resample

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jul059
    • Dec 2009
    • 8

    External DSP: resample

    Hello,

    I'm trying to use an external DSP to resample audio files. I want to use SOX. I'm using it from within ffmpeg, and here's what I've gotten working so far:

    1. I created the following batch file:

    Code:
    @echo off
    
    set "input=%~1"
    set "filename=%~nx1"
    set "filepath=%~dp1"
    
    if not defined filepath set "filepath=%cd%"
    
    ffmpeg.exe -i "%filepath%%filename%" -af "aresample=resampler=soxr:out_sample_rate=44100:precision=33:cheby=1:osf=s16:dither_method=triangular" "%filepath%%~n1_2%~x1"
    del "%filepath%%filename%"
    ren "%filepath%%~n1_2%~x1" "%filename%"
    
    exit /b %ERRORLEVEL%

    2. I used "Advanced BAT to EXE converter v4.61" to generate an exe file from the bat.
    3. I put both the generated "resample.exe" and a static ffmpeg build in a single folder.
    4. The following commands work from within windows shell:

    - If the current path is the path of the file to be converted:
    Code:
    (path to resample.exe)\resample.exe "filename"
    - If the current path is a random path:
    Code:
    (path to resample.exe)\resample.exe "(path to filename)\filename"
    In both cases, I get a file with the same name as the original, but resampled and with bitdepth 16.

    5. Here's what doesn't work in dbpoweramp:
    - external DSP --> before conversion --> select "resample.exe" in the same path as previous examples --> command line: "[infilelong]"
    It generates a file, but without resampling.


    Any help would be greatly appreciated! I've always had trouble with managing filenames, paths, current path, etc. in by batch files. I feel that's the issue.
  • Spoon
    Administrator
    • Apr 2002
    • 44022

    #2
    Re: External DSP: resample

    ffmpeg.exe you need to supply the full program path to it
    Spoon
    www.dbpoweramp.com

    Comment

    • jul059
      • Dec 2009
      • 8

      #3
      Re: External DSP: resample

      Thank you for the comment.

      Unfortunately, it doesn't seem to work. Also, I have noticed something: If I try to convert a "sample.flac" file to wav with this DSP, I get a "sample_2.flac" which is resampled as expected and an unresampled "sample.wav", which tells me there's at least 2 problems I need to solve:

      1. It means my DSP received the original flac file instead of a decoded wav file (which I thought was what's supposed to happen. I read this in a post from you from 2015),
      2. Somehow the script is able to complete the renaming process when used from within a command prompt, but it still leaves the "_2" file intact when run with dbpowermap.

      This seem to happen only when outputting to wav. Use of other encoders will stall indefinitely.

      point 1 seem to be confirmed by this log excerpt:

      Code:
      ->->  [clDSP_RunExternal::BeginConversion]
        Run Before Conversion DSP Effect, running: D:\(redacted)\resample_24bits.EXE  [clDSP_RunExternal::BeginConversion]
        Command Line: "D:\(redacted)\sample.flac"  [clDSP_RunExternal::BeginConversion]
      <-<-  [clDSP_RunExternal::BeginConversion]
      ->->  [clEncoder_WAVE::BeginConversion]
        Converting to 'D:\(redacted)\sample.wav' encoder settings ' -compression="PCM"'
        Wave output WaveFormat: Format Tag: 1  Channels: 2  Bits per Sample: 24  Samples Per Second: 96000  Bytes Per Second: 576000  Block Align: 6  CB Size: 0
        ->->  [clRIFFHandler::InitializeNewWAV]
          clRIFFHandler::CalcAllChunks: Ok
          ->-> Adding Chunk 'fmt ' Length: 16  [clRIFFHandler::AddChunk]
            clRIFFHandler::CalcAllChunks: Ok
          <-<-  [clRIFFHandler::AddChunk]
          ->-> Adding Chunk 'data' Length: 0  [clRIFFHandler::AddChunk]
            clRIFFHandler::CalcAllChunks: Ok
          <-<-  [clRIFFHandler::AddChunk]
          ->->  [clRIFFHandler::WriteChunkHeaders]
            clRIFFHandler::CalcAllChunks: Ok
            Writing Chunk Header 'fmt '  Length: 16  ChunkPosition: 12  ChunkDataPos: 20
            Writing Chunk Header 'data'  Length: 0  ChunkPosition: 36  ChunkDataPos: 44
          <-<- Exit as only write to data chunk  [clRIFFHandler::WriteChunkHeaders]
          Writing Chunk Data 'fmt '  Length: 16  ChunkPosition: 12  ChunkDataPos: 20
        <-<-  [clRIFFHandler::InitializeNewWAV]
      <-<-  [clEncoder_WAVE::BeginConversion]
      Communicate  [clDecoder::Get]
      Communicate  [clEncoder_WAVE::Get]
      Encoding To: Wave
      Encoder Cmd Line:  -compression="PCM"
      DSP Effects:
          Run External: -when="2" -prog="D:\(redacted)\resample_24bits.EXE" -cli="{qtD}[infilelong]{qtD}"

      Any ideas how to proceed?
      Thank you!
      Last edited by jul059; January 29, 2024, 12:19 AM.

      Comment

      • Spoon
        Administrator
        • Apr 2002
        • 44022

        #4
        Re: External DSP: resample

        [outfilelong]

        is the filename you need
        Spoon
        www.dbpoweramp.com

        Comment

        • jul059
          • Dec 2009
          • 8

          #5
          Re: External DSP: resample

          Thanks again for the reply!

          [outfilelong] seems to pass the output filename as argument and not the intermediate file.

          Code:
          ->->  [clDSP_RunExternal::BeginConversion]
            Run Before Conversion DSP Effect, running: D:\(redacted)\resample_24bits.EXE  [clDSP_RunExternal::BeginConversion]
            Command Line: "D:\(redacted)\sample.m4a"  [clDSP_RunExternal::BeginConversion]
          <-<-  [clDSP_RunExternal::BeginConversion]
          ->->  [clEncoder::BeginConversion]
            Converting to 'D:\(redacted)\sample.m4a' encoder settings ' -cli_encoder="C:\(redacted)\qaac64.exe" -cli_cmd="--cvbr 80 --he - -o {qt}[outfile]{qt}" -selection="2,6,1,0"'
            Using Encoder 'C:\(redacted)\qaac64.exe'
            Command Line '--cvbr 80 --he - -o "D:\(redacted)\SAMPLE.M4A"'
            Input Wave Format:Format Tag: 1  Channels: 2  Bits per Sample: 24  Samples Per Second: 96000  Bytes Per Second: 576000  Block Align: 6  CB Size: 0
            Output Wave Format:Format Tag: 1  Channels: 2  Bits per Sample: 24  Samples Per Second: 96000  Bytes Per Second: 576000  Block Align: 6  CB Size: 0
            Passing Wave Header: Yes
            Using StdInput Pipe: Yes
            dBpoweramp Writing Tags: Yes
          <-<-  [clEncoder::BeginConversion]
          Communicate  [clDecoder::Get]
          Communicate  [clEncoder::Get]
          Encoding To: m4a QAAC (iTunes)
          Encoder Cmd Line:  -cli_encoder="C:\(redacted)\qaac64.exe" -cli_cmd="--cvbr 80 --he - -o {qt}[outfile]{qt}" -selection="2,6,1,0"
          DSP Effects:
              Run External: -when="2" -prog="D:\(redacted)\resample_24bits.EXE" -cli="{qtD}[outfilelong]{qtD}"
          It also doesn't seem to work even if I convert to wave, use outfilelong, and try to run it before or after.

          Comment

          • Spoon
            Administrator
            • Apr 2002
            • 44022

            #6
            Re: External DSP: resample

            There is no intermediate file, run external is either before, or after conversion.
            Spoon
            www.dbpoweramp.com

            Comment

            • jul059
              • Dec 2009
              • 8

              #7
              Re: External DSP: resample

              I see.

              I'm not sure how to make it work then.

              Might I suggest to include Sox in dbpoweramp? It is among the best 3 resamplers available. Also, a functionality I find most convenient is it's ability to automatically normalize to avoid clipping by using a command like this:

              Sox.exe --norm "sourcefile" "%outfile" rate -v -I 44.1k
              --norm apparently does the following (https://www.scrc.umanitoba.ca/doc/scrchelp/man/sox.html):

              --norm[=dB-level]
              Automatically invoke the gain effect to guard against clipping and to normalise the audio. E.g.

              sox --norm infile -b 16 outfile rate 44100 dither -s



              is shorthand for

              sox infile -b 16 outfile gain -h rate 44100 gain -nh dither -s

              I would use this command to convert high quality audio for compression to AAC, Opus, etc (retaining the high bit depth).

              It can also be used to reduce bit depth at the same time, as follows:

              Sox.exe --norm "sourcefile" -b 16 "%outfile" rate -v -I 44.1k dither -S

              Comment

              • Spoon
                Administrator
                • Apr 2002
                • 44022

                #8
                Re: External DSP: resample

                dBpoweramp is based on SSRC which I think is better than SOX, you can see the testing there:



                Clipping prevention is easy in dbpoweramp, you can set bith depth to floating point before the resmaple, then normalize to maximum, reduce slightly if want then set bit depth to integer, with ditehr.
                Spoon
                www.dbpoweramp.com

                Comment

                • jul059
                  • Dec 2009
                  • 8

                  #9
                  Re: External DSP: resample

                  Originally posted by Spoon
                  dBpoweramp is based on SSRC which I think is better than SOX, you can see the testing there:



                  Clipping prevention is easy in dbpoweramp, you can set bith depth to floating point before the resmaple, then normalize to maximum, reduce slightly if want then set bit depth to integer, with ditehr.
                  I must say I fail to see how SSRC High Precision is better than SOX VHQ. Sweep and 1 khz tone look better with SOX, and passband could be adjusted in SOX if desired. In any case, they are both excellent and audibly indistinguishable.

                  I will try that method, thank you.

                  Comment

                  • Spoon
                    Administrator
                    • Apr 2002
                    • 44022

                    #10
                    Re: External DSP: resample

                    1KHz is better in dBpoweramp:



                    Sweep is identical.
                    Spoon
                    www.dbpoweramp.com

                    Comment

                    • jul059
                      • Dec 2009
                      • 8

                      #11
                      Re: External DSP: resample

                      Originally posted by Spoon
                      1KHz is better in dBpoweramp:



                      Sweep is identical.
                      Ah interesting! I hadn't bothered to look for dbPoweramp and compared Sox to SSRC directly. Thanks! Interesting how you get better results than SSRC High precision.

                      Comment

                      Working...

                      ]]>