sox-users@lists.sourceforge.net unofficial mirror
 help / color / Atom feed
From: "Dr. Thomas Tensi" <t.tensi@gmx.de>
To: sox-users@lists.sourceforge.net
Subject: SOX mcompand crossover algorithm?
Date: Tue, 23 Jul 2019 21:44:57 +0200
Message-ID: <22dd29a2-219a-3fb3-7c0f-2eb2b2e2b4da@gmx.de> (raw)

Dear all,


I am currently trying to emulate some of the sox effects by
scripting them in Reaper.  I need those for exactly mirroring
an external effects chain in sox within a DAW.

For most of the effects reprogrammed, this works fine
(the results are bit-exact).

But I have significant problems with mcompand.

mcompand uses a 4-th order Linkwitz-Riley-filter for
crossovers.  I am able to reproduce the crossover algorithm
quite faithfully, but nevertheless I am not convinced about
the filter coefficients.

sox biquad filters produce the following IIR coefficients
for a sample rate of 44.1kHz and a crossover frequency of
1kHz (the numbers gained by checking the source-code):

     ======================================
     butterworth 2 biquad filters from sox:
     ======================================
     lb = [ 4.604E-03,  9.208E-03, 4.604E-03 ]
     hb = [ 9.042E-01, -1.808E+00, 9.042E-01 ]
     a  = [ 1.000E+00, -1.799E+00, 8.175E-01 ]

Those perfectly match the values from scipy.signal:
     signal.iirfilter(2, 1000/22050, btype="lowpass")
     signal.iirfilter(2, 1000/22050, btype="highpass")

     ==========================================
     butterworth 2 crossover from scipy.signal:
     ==========================================
     bLow2  = [ 0.004604,   0.009208,   0.004604  ]
     bHigh2 = [ 0.9041522, -1.80830441, 0.9041522 ]
     a2     = [ 1.,        -1.79909641, 0.8175124 ]

Using full debug mode for mcompand with a 1kHz crossover
frequency reveals the following coefficients:

     =================================
     butterworth 4 crossover from sox:
     =================================
     DBUG mcompand_xover:
     lb=[2.119680195800917e-005 8.47872078320367e-005
         0.000127180811748055
         8.47872078320367e-005 2.119680195800917e-005]
     DBUG mcompand_xover:
     hb=[0.8174912065828001 -3.2699648263312 4.9049472394968
         -3.2699648263312 0.8174912065828001]
     DBUG mcompand_xover:
     a=[1 -3.598192818969336 4.871772697390141 -2.9415672592774
        0.6683265296879234];

This does _not_ match the output from scipy.signal:

     ==========================================
     butterworth 4 crossover from scipy.signal:
     ==========================================
     lb=[2.15209512e-05, 8.60838049e-05, 1.29125707e-04,
         8.60838049e-05, 2.15209512e-05 ]
     hb=[ 0.82999258, -3.31997033, 4.97995549, -3.31997033,
          0.82999258 ]
     a=[ 1., -3.6278442, 4.95122513, -3.01192428, 0.68888769 ]

They are near, but not identical.  Is the coefficient
transformation for the iir filter cascade in
mcompand_xover.h possibly incorrect?


           Best regards,

                  Thomas


_______________________________________________
Sox-users mailing list
Sox-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 19:44 Dr. Thomas Tensi [this message]
2019-07-24 19:26 ` Dr. Thomas Tensi

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-users

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22dd29a2-219a-3fb3-7c0f-2eb2b2e2b4da@gmx.de \
    --to=sox-users@lists.sourceforge.net \
    --cc=t.tensi@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

sox-users@lists.sourceforge.net unofficial mirror

Archives are clonable: git clone --mirror https://public-inbox.org/sox-users

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.audio.sox
	nntp://ou63pmih66umazou.onion/inbox.comp.audio.sox
	nntp://news.gmane.org/gmane.comp.audio.sox

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git