Commit 26cec3c2 authored by Jan Kiene's avatar Jan Kiene
Browse files

first version of delay test, mono only

parent aac8f0aa
Loading
Loading
Loading
Loading
+137 −0
Original line number Diff line number Diff line
# steps:
# 1 define expected delays for all modes/bitrates combination
# 2 generate the test signals
# 3 run all modes with delay compensation
# 4 run all modes without delay compenstaion
# 5 measure delay for all channels and report/compare to expected delay
import subprocess
import os
import json
from tkinter import W
import numpy as np
import sys
import re
PYAUDIO3DTOOLS_PATH = "./scripts/"
sys.path.append(PYAUDIO3DTOOLS_PATH)
from pyaudio3dtools import audioarray, audiofile
import pathlib

OC_TO_NCHANNELS = {
    "MONO": 1,
    "STEREO": 2,
    "BINAURAL": 2,
    "BINAURAL_ROOM": 2,
    "5_1": 6,
    "7_1": 8,
    "5_1_2": 8,
    "5_1_4": 10,
    "7_1_4": 12,
    "FOA": 4,
    "HOA2": 9,
    "HOA3": 16,
    "EXT": 1,
    "ISM1": 1,
    "ISM2": 2,
    "ISM3": 3,
    "ISM4": 4,
    "MASA1TC": 1,
    "MASA2TC": 2,
}

FORMATS = [
	"MONO",
	"STEREO",
	*[f"ISM{x}" for x in range(1, 5)],
	"5_1",
	"5_1_2",
	"5_1_4",
	"7_1",
	"7_1_4",
	"SBA",
	"MASA1TC",
	"MASA2TC"
]


TEST_FILE = "./delay_test_file_{}.pcm"
CFG = "ci/delay_test_linux.json"

def main():
	formats = list(OC_TO_NCHANNELS.keys())
	# for testing
	FORMATS = ["mono"]

	form = FORMATS[0]

	# generate test signal
	test_file = TEST_FILE.format(form)
	gen_cmd = ["python3", "./ci/generate_delay_measurement_signal.py", form, test_file]
	subprocess.call(gen_cmd)

	# run format
	outfolder_delaycmp = "out_delay_cmp"
	run_cmd = [
		"python3",
		"./scripts/runIvasCodec.py",
		"-C",
		form,
		"-p",
		CFG,
		"-I",
		test_file,
		"-o",
		outfolder_delaycmp
	]
	subprocess.call(run_cmd)

	outfolder_nodelaycmp = "out_no_delay_cmp"
	run_cmd_nodelaycmp = list(run_cmd)
	run_cmd_nodelaycmp[-1] = outfolder_nodelaycmp
	run_cmd_nodelaycmp.extend([
		"-D=-NO_DELAY_CMP",
		"-E=-NO_DELAY_CMP"
	])
	subprocess.call(run_cmd_nodelaycmp)

	get_delay_for_folders(outfolder_delaycmp, outfolder_nodelaycmp)


def get_delay_for_folders(folder_delay_cmp: str, folder_no_delay_cmp: str):

	folder_path_delay_cmp = pathlib.Path(folder_delay_cmp)
	files_delay_cmp = sorted([ f.name for f in folder_path_delay_cmp.joinpath("dec").iterdir() ])

	folder_path_no_delay_cmp = pathlib.Path(folder_no_delay_cmp)
	files_no_delay_cmp = sorted([ f.name for f in folder_path_no_delay_cmp.joinpath("dec").iterdir() ])

	assert(files_delay_cmp == files_no_delay_cmp)

	delays_for_samplerates = dict()	
	for f in files_delay_cmp:
		# for testing only
		if "dtx" in f or "amr" in f or "_rs" in f:
			continue

		f_cmp = folder_path_delay_cmp.joinpath("dec", f)
		f_no_cmp = folder_path_no_delay_cmp.joinpath("dec", f)

		s_cmp, fs = audiofile.readfile(f_cmp)
		s_no_cmp, fs = audiofile.readfile(f_no_cmp)

		delay = audioarray.getdelay(s_cmp, s_no_cmp)

		match = re.search("b[0-9_]*_[fb|swb|wb|nb]+", f)
		bitrate = match.group()[1:-3].replace("_", ".")

		if fs not in delays_for_samplerates:
			delays_for_samplerates[fs] = dict()
		delays_for_samplerates[fs][bitrate] = delay

	for fs, fs_dict in delays_for_samplerates.items():
		unique_values = np.unique(list(fs_dict.values())) 
		unique_values = [v / fs for v in unique_values]
		print(f"Values for {fs}: {unique_values}")


if __name__ == "__main__":
	main()
 No newline at end of file