def get_linkwitz_riley_coeffs(gain, lo, hi, sr):
    def get_c(cutoff, sr):
        wcT = pi * cutoff / sr
        return 1 / tan(wcT)

    def get_lopass_coeffs(gain, cutoff, sr):
        c = get_c(cutoff, sr)
        a0 = c * c + c * sqrt(2) + 1
        b = [gain / a0, 2 * gain / a0, gain / a0]
        a = [1, (-2 * (c * c - 1)) / a0, (c * c - c * sqrt(2) + 1) / a0]
        return b, a

    def get_hipass_coeffs(gain, cutoff, sr):
        c = get_c(cutoff, sr)
        a0 = c * c + c * sqrt(2) + 1
        b = [(gain * c * c) / a0, (-2 * gain * c * c) / a0, (gain * c * c) / a0]
        a = [1, (-2 * (c * c - 1)) / a0, (c * c - c * sqrt(2) + 1) / a0]
        return b, a

    return twopass_coeffs([get_lopass_coeffs(gain, hi, sr),
                           get_hipass_coeffs(gain, lo, sr)])