Commit ee36749d authored by norvell's avatar norvell
Browse files

Add fix for differing sampling rates in output

parent f49a32e7
Loading
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -54,15 +54,33 @@ def cmp_pcm(
    else:
        nchannels = pyivastest.constants.OC_TO_NCHANNELS[out_config.upper()]

    s1, _ = pyaudio3dtools.audiofile.readfile(
    s1, fs1 = pyaudio3dtools.audiofile.readfile(
        ref_file, nchannels, fs, outdtype=np.int16
    )
    s2, _ = pyaudio3dtools.audiofile.readfile(
    s2, fs2 = pyaudio3dtools.audiofile.readfile(
        cmp_file, nchannels, fs, outdtype=np.int16
    )

    # In case of wav input, override the nchannels with the one from the wav header
    nchannels = s1.shape[1]
    fs = fs1

    if fs1 != fs2:
        if peaq_binaural:
            fs = max(fs1,fs2)
            s1 = np.clip(
                pyaudio3dtools.audioarray.resample(s1.astype(float), fs, 48000),
                -32768,
                32767,
            ).astype(np.int16)
            s2 = np.clip(
                pyaudio3dtools.audioarray.resample(s2.astype(float), fs, 48000),
                -32768,
                32767,
            ).astype(np.int16)
    else:
        reason = "FAIL: Sampling rate differs."
        return 1, reason

    # In case number of channels do not match, fail already now. Could happen in case of
    # comparison to input with for a non-passthrough mode.