HQPlayer vs SOX

Discussion in 'Computer Audiophile: Software, Configs, Tools' started by Woland, Aug 7, 2021.

  1. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    To simplify things a bit, SoX can handle the flacs directly, and as a bonus will copy the tags across for you:
    Code:
    sox -S <in.flac> -r 176400 -b 24 <out.flac> upsample 4 fir <taps.txt> vol 4
    
    This vol matches the input and output volumes. You will get some clipped samples with sausaged recordings.
     
  2. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    Using my modified SoX, I am running rate with the following parameters:
    - stopband rejection 198db
    - cutoff -3db at 99.9993% bandwidth
    This produces a filter of around 8 million taps. It sounds different to the one I was running with 99.98% bandwidth and all other parameters the same (giving a filter of about 300,000 taps), more delicate and filigreed in the transients.

    Can you run up your chosen algorithm for FIR coefficients to produce something comparable?
     
  3. soumya

    soumya Acquaintance

    Joined:
    Jun 24, 2018
    Likes Received:
    42
    Trophy Points:
    18
    Location:
    Mordor, Middle Earth
    You can use Octave if all you want is to generate gazillion taps using windowing technique. They are sub optimal since lion's share of coefficients will be ~ 0. So improvements will be diminishing. You need to make the coefficients behave like a sinc function without the discontinuities (Gibb’s Phenomenon)
     
  4. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    I guess I have found that I prefer the sound of upsampling that is closer to mathematically perfect (convolve with a sinc of infinite extent). Your perspective I infer is that deliberately deviating from that has certain advantages? I.e., what is your filter recipe trying to achieve sonically and why might one prefer it to an extremely long windowed sinc?
     
  5. Woland

    Woland Friend

    Pyrate
    Joined:
    Jan 13, 2021
    Likes Received:
    1,311
    Trophy Points:
    93
    Location:
    a friendly land
    While we're in the topic.. Roon is a pretty polished product. Why are its upscaling options so uninteresting compared to what's available on HQPlayer?
     
  6. GoodEnoughGear

    GoodEnoughGear Evil Dr. Shultz‎

    Pyrate
    Joined:
    Oct 25, 2015
    Likes Received:
    3,070
    Trophy Points:
    113
    Location:
    Cape Town, South Africa
    HQplayer can be integrated with Roon...maybe they're happy outsourcing that aspect for the small (I imagine) percentage of users that care?
     
  7. Woland

    Woland Friend

    Pyrate
    Joined:
    Jan 13, 2021
    Likes Received:
    1,311
    Trophy Points:
    93
    Location:
    a friendly land
  8. soumya

    soumya Acquaintance

    Joined:
    Jun 24, 2018
    Likes Received:
    42
    Trophy Points:
    18
    Location:
    Mordor, Middle Earth

    Uhm no, clearly you misunderstood my previous reply. So I take it a primers on window functions is due. :)
    The pure normalized sinc function is the FT of what we call as Rectangular Window.
    See this
    https://en.wikipedia.org/wiki/Windo...tion_and_frequency_response_-_Rectangular.svg

    In rectangular window function, all coefficients are sinc. This ensures it will retrieve all transient values. However the downside is the transition from 0 to sinc values is abrupt leading to discontinuities. Also notice the side lobe attenuation is very low for the same number of coefficients. Anyways because of this abrupt discontinuities and less steep attenuation compared to other window functions, we generally don't use rectangular window in signal processing.

    Now to circumvent abrupt discontinuities, we make use of various families of more conventional window functions like Hamming, Hann, Blackman, Nuttal etc. Each have varying degree of compromise between side-lobe attenuation vs mainlobe width (ideal sinc coefficients). Please read them here https://en.wikipedia.org/wiki/Window_function. Particularly pay special attention to amplitude vs FT .

    The most flexible of them all is Kaiser Window and this is what is being used internally in SoX's rate and sinc filiter.
    The reason it is flexible is because of the alpha/beta parameter. When beta = 0 it will behave like a pure rectangular window function with all its nastiness. As you increase the beta values, the sidelobe attenuation increases but the coefficients depart further and further away from ideal sinc values. This is what I was pointing to in my earlier reply - it doesn't make sense to just keep increasing coefficients if vast majority of them are nearer to 0 instead of ideal sinc coefficients.
    Your personal preferences aside , doing so will lead to it sounding unnatural due to time domain inaccuracies - and is the primary reason IMO why people coming from NOS world say up-sampling makes a DAC sound thin. It doesn't have to.
    So this leads us to the question how to better make use of the limited processing power that we have in terms of number of coefficients for a given sampling rate, to get the adequate suppression of side-lobes and have enough sinc like behaviour.
    Think I did my due diligence here to inspire you to read and think a bit more about this predicament :)
    [​IMG]
     
    Last edited: Nov 3, 2021
  9. soumya

    soumya Acquaintance

    Joined:
    Jun 24, 2018
    Likes Received:
    42
    Trophy Points:
    18
    Location:
    Mordor, Middle Earth
    This post here has much better illustration on Kaiser beta parameter effect both in time and frequency domain.
    https://www.dsprelated.com/freebooks/sasp/Kaiser_Window.html

    But I would urge you to play with Octave/Matlab, generate coefficient using different window functions, plot the frequency response and impulse response and make notes how it changes sound. Use SoX fir filter to load the coefficients you generate.
    Once you are comfortable with these conventional filters, you can take things to next level and design custom filters which try to maximize the sinc nature but keep attenuation to 32 bit noise floor or lesser.
     
  10. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    Thanks, that's very useful information. I didn't know exactly how SoX rate builds its FIR coefficients, but now I know it's a Kaiser windowed sinc, I am fiddling around with SoX itself and going purely by ear to see what difference various choices make.

    One thing that sounds pretty good at first blush is using SoX sinc with a filter length equal to the track length and beta = 0 (rectangular window). This confused me a bit: surely with this choice one gets perfect reconstruction? Thinking a bit more about this, I realised why this is not true: any finite length piece of audio cannot be band-limited, because it's not infinite in extent. So the Nyquist theorem in fact does not apply. Because the length of a track is finite and fixed on playback, the rectangular window this imposes necessarily leads to ripples in the frequency domain.

    The question is whether this has any practical impact. Basically what this come down to is, how do our ears work. Obviously they don't fourier transform a whole 5 minute song in one go, there is some kind of windowed FFT going on (plus I guess a purely time-domain non-linear component). Which suggest that all of the above considerations will happen beyond what is perceptible. In any case, I'm going to try this very naive upsampling for a few days and see how it sounds.
     
  11. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    Update: the "pure sinc" upsampling sounds really good, though probably not for everybody. Transients are very clean and pure, the top end is beautiful, and microdynamics and low level detail and texture really take a step up. The downside is that you lose a little incisiveness which at first listen makes it sound less dynamic. However, once you get used to it you realise that the dynamics are still there, they are just less in your face and more delicate. I would describe the presentation as more natural, and perhaps a little more laid back.

    This is definitely offline-only as I use a filter length of 64M taps pure sinc. For 4x fs, this filter is -100dB by 5Hz over the stopband frequency and the highest sideband lobe is -120dB, so probably no real need to mess around with windows.

    Will get instructions together for using this with a unix-based system tonight.
     
  12. Cellist88

    Cellist88 Friend

    Pyrate
    Joined:
    Nov 11, 2015
    Likes Received:
    1,607
    Trophy Points:
    93
    Location:
    NJ
    @Garns, I would like to participate too, but am confused how to do so on a windows 10 pc.
     
  13. Woland

    Woland Friend

    Pyrate
    Joined:
    Jan 13, 2021
    Likes Received:
    1,311
    Trophy Points:
    93
    Location:
    a friendly land
    If you can bundle it with steps to apply your patch to SOX on Pi, that would be hugely useful!
     
  14. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    OK, here's a first pass of how to do this. This requires a GNU toolchain, so probably Linux or a Mac. (Should be fine to compile on a RPi). We will need to find someone with Cygwin/Visual Studio who can do a Windows compile for you @Cellist88!

    First you need to clone and compile the patched sox source. In a scratch directory you need to run
    Code:
    git clone https://github.com/rhgg2/sox.git
    cd sox
    autoreconf -i
    ./configure
    make
    make install
    If all goes to plan this will install sox in /usr/local/bin. Or you can skip the last line, and copy src/sox to wherever you like.

    Now here's the formula I use to offline upsample 4x (max I can do to output over the PI2AES):
    Code:
     sox -S -V6 <in.flac> -b 24 -r 176400 <out.flac> upsample 4 sinc -22050 -n 64000000 -L -b 0 vol 4
    
    This will give you unity gain, but you can drop vol 4 to a smaller number if you have excessive clipping. For 48kHz source files you need -r 192000 rather than -r 176400. The -n 64000000 is the number of taps, about all I can manage on my 8Gb Mac before it runs out of RAM, but you might manage less or more. Because there is no clever windowing being done, in this case moar really is better.

    Still really enjoying the sound - transients and low level detail are amazing (anything with glockenspiel in is heaps better). Would be interesting to compare it to HQPlayer...
     
    Last edited: Nov 11, 2021
  15. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    Okaay, I don't exactly know if these will work, but I made some binaries for OSX and Windows:
    https://drive.google.com/drive/folders/1DSAVcXAWRxb-JjXiC4v897WYsPIBkN6i

    The windows one you can copy all the files to a directory and hope for the best that you can run it from that directory.

    The OSX one should be standalone except it might complain about libogg, which if you don't have it you'll need to install from homebrew or similar. You will need to run
    Code:
    chmod +x sox
    in the downloaded directory to make the file executable, and then either copy it somewhere on your path (e.g., /usr/local/bin) or run it with an explicit path, e.g.,
    Code:
    ./sox <parameters>
    from the directory you downloaded it. Note that if you already have sox on your path, OSX will run that version by preference if you don't provide a path.
     
    Last edited: Nov 21, 2021
  16. schnesim

    schnesim New

    Joined:
    Jul 4, 2019
    Likes Received:
    23
    Trophy Points:
    8
    Location:
    north
    @Garns I gave your OSX build a try with the command you suggested
    Code:
     sox -S -V6 <in.flac> -b 24 -r 176400 <out.flac> upsample 4 sinc -22050 -n 64000000 -L -b 0 vol 4
    
    But it complains about the number of taps
    Did I miss something?
     
  17. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    Make sure you aren't running a version of sox you already have installed. Try starting your command with ./sox rather than sox (from the directory that contains the downloaded version of sox). If that works, you can fix permanently by renaming your existing version of sox (which is likely in /usr/local/bin) to something else, and copying this new version of sox in its place.
     
  18. Woland

    Woland Friend

    Pyrate
    Joined:
    Jan 13, 2021
    Likes Received:
    1,311
    Trophy Points:
    93
    Location:
    a friendly land
    I just had a very quick experiment - and it works for me.

    Downloaded, then marked it executable..

    Code:
    chmod +x sox
    .. and applied it to the free music track selected earlier:

    Code:
    ./sox -S -V6 Jezebell\ -\ Paisley\ Dark\ Edits\ Box\ 6\ -\ 01\ Tullio\ de\ Piscopo\ -\ Stop\ Bajon\ \(Primavera\)\ \(Jezebell\ edit\).flac  -b 24 -r 176400 Jezebell.flac  upsample 4 sinc -22050 -n 64000000 -L -b 0 vol 4
    There are warnings about clipping and non-standard rate.

    Code:
    ./sox:      SoX v14.4.2
    time:     Nov 21 2021 19:50:25
    uname:    Darwin MacBook-Pro-3.local 18.7.0 Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64
    compiler: gcc 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)
    arch:     1288 48 88 L
    ./sox INFO formats: detected file format type `flac'
    ./sox DBUG flac: API version 11
    ./sox DBUG vol: mult=4 limit=0
    
    Input File     : 'Jezebell - Paisley Dark Edits Box 6 - 01 Tullio de Piscopo - Stop Bajon (Primavera) (Jezebell edit).flac'
    Channels       : 2
    Sample Rate    : 44100
    Precision      : 24-bit
    Duration       : 00:07:00.00 = 18522000 samples = 31500 CDDA sectors
    File Size      : 85.2M
    Bit Rate       : 1.62M
    Sample Encoding: 24-bit FLAC
    Endian Type    : little
    Reverse Nibbles: no
    Reverse Bits   : no
    Comments       :
    TITLE=Tullio de Piscopo - Stop Bajon (Primavera) (Jezebell edit)
    ARTIST=Jezebell
    DATE=2021
    COMMENT=Visit https://paisleydarkrecords.bandcamp.com
    ALBUM=Paisley Dark Edits Box 6
    TRACKNUMBER=1
    ALBUMARTIST=Jezebell
    
    ./sox INFO flac: encoding at 24 bits per sample
    ./sox INFO flac: non-standard rate; output may not be streamable
    
    Output File    : 'Jezebell.flac'
    Channels       : 2
    Sample Rate    : 176400
    Precision      : 24-bit
    Duration       : 00:07:00.00 = 74088000 samples ~ 31500 CDDA sectors
    Sample Encoding: 24-bit FLAC
    Endian Type    : little
    Reverse Nibbles: no
    Reverse Bits   : no
    Comments       :
    TITLE=Tullio de Piscopo - Stop Bajon (Primavera) (Jezebell edit)
    ARTIST=Jezebell
    DATE=2021
    COMMENT=Visit https://paisleydarkrecords.bandcamp.com
    ALBUM=Paisley Dark Edits Box 6
    TRACKNUMBER=1
    ALBUMARTIST=Jezebell
    
    ./sox DBUG effects: sox_add_effect: extending effects table, new size = 8
    ./sox DBUG effects_i_dsp: make_lpf(n=64000001 Fc=0.25 β=0 ρ=0 dc-norm=0 scale=1)
    ./sox INFO sox: effects chain: input        44100Hz  2 channels (multi) 24 bits 00:07:00.00
    ./sox INFO sox: effects chain: upsample    176400Hz  2 channels         24 bits 00:07:00.00
    ./sox INFO sox: effects chain: sinc        176400Hz  2 channels         32 bits 00:07:00.00
    ./sox INFO sox: effects chain: vol         176400Hz  2 channels (multi) 32 bits 00:07:00.00
    ./sox INFO sox: effects chain: output      176400Hz  2 channels (multi) 24 bits 00:07:00.00
    ./sox DBUG sox: start-up time = 5.22247
    In:100%  00:07:00.00 [00:00:00.00] Out:74.1M [      |      ] Hd:0.0 Clip:260
    ./sox WARN vol: vol clipped 179 samples; decrease volume?
    ./sox WARN sox: `Jezebell.flac' output clipped 81 samples; decrease volume?
    Done.

    I should be able to share the input and output files as this is a free music track.
     
    Last edited: Nov 21, 2021
  19. Garns

    Garns Friend

    Pyrate
    Joined:
    Jul 9, 2016
    Likes Received:
    2,483
    Trophy Points:
    93
    Location:
    Sydney, AUS
    Great, that looks correct, and thanks, yes, you will need to do chmod +x sox after downloading. If the clipping bothers you, you can decrease "vol 4" a bit, though it'll no longer be level-matched against the input.
     
  20. Scott Kramer

    Scott Kramer Friend

    Pyrate
    Joined:
    May 3, 2016
    Likes Received:
    1,446
    Trophy Points:
    93
    Code:
    piCore8 64bit raspi4 8GB
    tce-load -wi autoconf automake libtool git m4 grep gawk sed pkg-config gcc compiletc nano
    
    git clone https://github.com/rhgg2/sox.git
    cd sox
    autoreconf -i
    #nano +14397 configure
    ./configure --with-flac
    make
    #make install
    
    piCore script (soxup)
    #!/bin/sh
    mkdir "Hires"
    RATE=176400
    TAPS=64000000
    for f in *.flac
    do
        ~/flac -d "$f"
    done
    for f in *.wav              
    do
        /mnt/sda2/tce/sox/src/sox -S -V6 "$f" -b 24 -r $RATE "Hires/$f" upsample 4 sinc -22050 -n $TAPS -L -b 0 vol 3
    done
    
    Notes
    #/mnt/sda2/tce/sox/src/sox -S -V6 in.wav -b 24 -r 176400 out.wav upsample 4 sinc -22050 -n 64000000 -L -b 0 vol 3
    #--with-flac
    
    need to comment these lines out in configure, they error out:
    Screen Shot 2021-11-21 at 3.01.18 AM.jpg

    Screen Shot 2021-11-21 at 4.17.56 AM.jpg


    Thank You @Garns! --> Wanted to try this on a pi and directly in piCore (might be able to pipe it real-time to squeeze-lite). Does anyone know the flag or file to edit to add in sox flac support*? It could be those bad configure lines, not sure about the fix. macOS/WIN it's already compiled in.

    edit: * ./configure --with-flac
     

    Attached Files:

    Last edited: Nov 28, 2021

Share This Page