Commit 5ee6c325 authored by Jan Kiene's avatar Jan Kiene
Browse files

also handle out-of-threshold reference in single channels only

parent 7139f852
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
"""

import logging
import warnings
import math
import multiprocessing as mp
import platform
@@ -569,12 +570,11 @@ def ssnr(

        ss.append(ss_seg)

    if np.all(segment_counter == 0):
        # the reference signal was outside of [thresh_lowm thresh_high] for all segments -> return -inf
        # note that this is not in line with the mpeg conf tool which gives +/-0.0 in this case
        ssnr = np.asarray([-np.inf] * len(segment_counter))
    else:
        # round to 2 decimals. this is just to be in line with the mpeg conformance tool
    # if the reference signal was outside the thresholds for all segments in a channel, segment_counter is zero
    # for that channel and the division here would trigger a warning. We supress the warning and later
    # set the SSNr for those channels to -inf manually instead (overwriting later is simply easier than adding ifs here)
    with warnings.catch_warnings():
        ssnr = np.round(10 * np.log10(10 ** (np.sum(ss, axis=0) / segment_counter) - 1), 2)
    ssnr[segment_counter == 0] = -np.inf

    return ssnr