Loading tests/test_be_ambi_converter_fixed_to_float.py 0 → 100644 +99 −0 Original line number Diff line number Diff line import pytest import subprocess import sys from enum import Enum from pathlib import Path from tempfile import TemporaryDirectory HERE = Path(__file__).absolute().parent TESTV_DIR = HERE.parent / "scripts/testv" sys.path.append(str(HERE.parent / "scripts")) from pyaudio3dtools import audiofile, audioarray class AMBI_CONVENTION(int, Enum): ACN_SN3D = 0 ACN_N3D = 1 FUMA_MAXN = 2 FUMA_FUMA = 3 SID_SN3D = 4 SID_N3D = 5 def run_ambi_converter( bin_path: Path, infile: Path, outfile: str, convention_in: AMBI_CONVENTION, convention_out: AMBI_CONVENTION, ): cmd = [ str(bin_path), str(infile), outfile, f"{int(convention_in)}", f"{int(convention_out)}", ] p = subprocess.run(cmd, capture_output=True) if p.returncode != 0: pytest.fail( f"Ambisonics converter run failed: {p.stdout.decode('utf8') + p.stderr.decode('utf8')}" ) INPUT_FILES = [TESTV_DIR / "stv3OA48c.wav"] CONVENTIONS = [c.value for c in AMBI_CONVENTION] AMBI_CONVERTER_PATH_FLOAT = HERE.parent / "ambi_converter_flt" AMBI_CONVERTER_PATH_FIXED = HERE.parent / "ambi_converter_fx" @pytest.mark.parametrize("infile", INPUT_FILES) @pytest.mark.parametrize("convention_out", CONVENTIONS) @pytest.mark.parametrize("convention_in", CONVENTIONS) def test_ambi_converter( infile: Path, convention_in: AMBI_CONVENTION, convention_out: AMBI_CONVENTION, # needs to be passed to correctly report errors test_info, ): if ( convention_out != AMBI_CONVENTION.ACN_SN3D and convention_in != AMBI_CONVENTION.ACN_SN3D ): pytest.skip("One of in and out convention needs to be ACN_SN3D") with TemporaryDirectory() as tmp_dir: outfile_base = Path(tmp_dir) / ( infile.stem + f"-{str(convention_in)}-to-{str(convention_out)}" ) outfile_flt = str(outfile_base) + "-flt.wav" outfile_fx = str(outfile_base) + "-fx.wav" run_ambi_converter( AMBI_CONVERTER_PATH_FLOAT, infile, outfile_flt, convention_in, convention_out, ) run_ambi_converter( AMBI_CONVERTER_PATH_FIXED, infile, outfile_fx, convention_in, convention_out, ) s_flt, _ = audiofile.readfile(outfile_flt) s_fx, _ = audiofile.readfile(outfile_fx) cmp_result = audioarray.compare(s_flt, s_fx, fs=48000, per_frame=False) if not cmp_result["bitexact"]: pytest.fail( f"Difference between float and fixed ambi_converter output found! Max abs diff: {cmp_result['max_abs_diff']}" ) Loading
tests/test_be_ambi_converter_fixed_to_float.py 0 → 100644 +99 −0 Original line number Diff line number Diff line import pytest import subprocess import sys from enum import Enum from pathlib import Path from tempfile import TemporaryDirectory HERE = Path(__file__).absolute().parent TESTV_DIR = HERE.parent / "scripts/testv" sys.path.append(str(HERE.parent / "scripts")) from pyaudio3dtools import audiofile, audioarray class AMBI_CONVENTION(int, Enum): ACN_SN3D = 0 ACN_N3D = 1 FUMA_MAXN = 2 FUMA_FUMA = 3 SID_SN3D = 4 SID_N3D = 5 def run_ambi_converter( bin_path: Path, infile: Path, outfile: str, convention_in: AMBI_CONVENTION, convention_out: AMBI_CONVENTION, ): cmd = [ str(bin_path), str(infile), outfile, f"{int(convention_in)}", f"{int(convention_out)}", ] p = subprocess.run(cmd, capture_output=True) if p.returncode != 0: pytest.fail( f"Ambisonics converter run failed: {p.stdout.decode('utf8') + p.stderr.decode('utf8')}" ) INPUT_FILES = [TESTV_DIR / "stv3OA48c.wav"] CONVENTIONS = [c.value for c in AMBI_CONVENTION] AMBI_CONVERTER_PATH_FLOAT = HERE.parent / "ambi_converter_flt" AMBI_CONVERTER_PATH_FIXED = HERE.parent / "ambi_converter_fx" @pytest.mark.parametrize("infile", INPUT_FILES) @pytest.mark.parametrize("convention_out", CONVENTIONS) @pytest.mark.parametrize("convention_in", CONVENTIONS) def test_ambi_converter( infile: Path, convention_in: AMBI_CONVENTION, convention_out: AMBI_CONVENTION, # needs to be passed to correctly report errors test_info, ): if ( convention_out != AMBI_CONVENTION.ACN_SN3D and convention_in != AMBI_CONVENTION.ACN_SN3D ): pytest.skip("One of in and out convention needs to be ACN_SN3D") with TemporaryDirectory() as tmp_dir: outfile_base = Path(tmp_dir) / ( infile.stem + f"-{str(convention_in)}-to-{str(convention_out)}" ) outfile_flt = str(outfile_base) + "-flt.wav" outfile_fx = str(outfile_base) + "-fx.wav" run_ambi_converter( AMBI_CONVERTER_PATH_FLOAT, infile, outfile_flt, convention_in, convention_out, ) run_ambi_converter( AMBI_CONVERTER_PATH_FIXED, infile, outfile_fx, convention_in, convention_out, ) s_flt, _ = audiofile.readfile(outfile_flt) s_fx, _ = audiofile.readfile(outfile_fx) cmp_result = audioarray.compare(s_flt, s_fx, fs=48000, per_frame=False) if not cmp_result["bitexact"]: pytest.fail( f"Difference between float and fixed ambi_converter output found! Max abs diff: {cmp_result['max_abs_diff']}" )