Commit 23397080 authored by Jan Kiene's avatar Jan Kiene
Browse files

add noise to end of signals to prevent ending with dtx section

parent 445beba8
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import pytest
import pathlib
import sys
import re
import numpy as np
from tempfile import TemporaryDirectory

from .constants import TESTV_DIR, SCRIPTS_DIR
@@ -226,6 +227,22 @@ def run_test(
        bitstream_file = tmp_dir.joinpath(f"{in_format}.192").absolute()
        sampling_rate_khz = 48
        input_file = TESTV_DIR.joinpath(INPUT_FILES[in_format])

        # for DTX cases append 5 frames of white noise to the file
        # this should make sure that there is no DTX segment at the very end of the signal
        # DTX at the end can still cause length differences which are fine to exist, but make the comparison hard to handle
        # EXCEPTION (of course there is one...): MASA. We cant append to the signal without appending some MD. Luckily, this problem does not occur with the MASA testvectors
        if dtx == DTX_ON and "MASA" not in in_format:
            input_signal, fs = audiofile.readfile(input_file)
            noise_len = fs // 50 * 5
            noise_amplitude = np.max(input_signal)
            noise = (
                np.random.random((noise_len, input_signal.shape[1])) * noise_amplitude
            )
            input_signal = np.concatenate([input_signal, noise])
            input_file = tmp_dir.joinpath(f"{input_file.stem}-plus-noise.wav")
            audiofile.writefile(input_file, input_signal, fs)

        options = get_options(in_format, dtx == DTX_ON)
        dut_encoder_frontend.run(
            bitrate,
@@ -238,7 +255,7 @@ def run_test(

        # run decoder without network simulation
        output = output_dir_no_jbm.joinpath(
            f"{in_format}-{bitrate}-{out_format}.wav"
            f"{in_format}-{bitrate}-{out_format}-{dtx}.wav"
        ).absolute()
        dut_decoder_frontend.run(out_format, sampling_rate_khz, bitstream_file, output)