Commit 5d609d77 authored by lefort's avatar lefort
Browse files

Ambisonics added.

parent cb486a4c
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -51,7 +51,14 @@ DECODER_CMD = [

HRTF_BINARY_FILE = "default_rom_{}kHz.bin"
SAMPLE_RATE = ["16", "32", "48"]
FORMATS_MC = ["MONO", "STEREO", "5_1", "5_1_2", "5_1_4", "7_1", "7_1_4"]

INPUT_FORMATS_MC = ["MONO", "STEREO", "5_1", "5_1_2", "5_1_4", "7_1", "7_1_4"]
INPUT_FORMATS_SBA = {
    "FOA":"1", 
    "HOA2":"2", 
    "HOA3":"3"
}

OUTPUT_FORMATS_BINAURAL = ["BINAURAL", "BINAURAL_ROOM_IR"] # "BINAURAL_ROOM_REVERB"
HR_TRAJECTORIES_TO_TEST = ["headrot_case00_3000_q"]

@@ -61,4 +68,7 @@ FORMAT_TO_FILE_WOEXT = {
    "5_1_2": "stv512MC{}c",
    "5_1_4": "stv514MC{}c",
    "7_1_4": "stv714MC{}c",
    "FOA": "stvFOA{}c",
    "HOA2": "stv2OA{}c",
    "HOA3": "stv3OA{}c",
}
 No newline at end of file
+32 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ from .utils import *

@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("out_fs", SAMPLE_RATE)
@pytest.mark.parametrize("in_fmt", FORMATS_MC)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_MC)
def test_multichannel_binaural_static(test_info, in_fmt, out_fmt, out_fs):

    if in_fmt in ["MONO", "STEREO"]:
@@ -53,7 +53,7 @@ def test_multichannel_binaural_static(test_info, in_fmt, out_fmt, out_fs):
@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("out_fs", SAMPLE_RATE)
@pytest.mark.parametrize("in_fmt", FORMATS_MC)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_MC)
def test_multichannel_binaural_headrotation(test_info, in_fmt, out_fmt, out_fs, trj_file):

    if in_fmt in ["MONO", "STEREO"]:
@@ -66,3 +66,33 @@ def test_multichannel_binaural_headrotation(test_info, in_fmt, out_fmt, out_fs,
        out_fs,
        trj_file=str(TESTV_DIR.joinpath(f"{trj_file}.csv"))
    )

""" Ambisonics """

@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("fs", SAMPLE_RATE[1:])
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_SBA)
def test_sba_binaural_static(test_info, in_fmt, fs, out_fmt):

    compare_ambisonics_rom_vs_binary(
        test_info, 
        in_fmt, 
        fs,
        out_fmt, 
        fs,
    )

@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("fs", SAMPLE_RATE[1:])
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_SBA)
def test_sba_binaural_headrotation(test_info, in_fmt, fs, out_fmt, trj_file):

    compare_ambisonics_rom_vs_binary(
        test_info, 
        in_fmt, 
        fs,
        out_fmt, 
        fs,
        trj_file=str(TESTV_DIR.joinpath(f"{trj_file}.csv"))
    )
 No newline at end of file
+50 −9
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ from .compare_audio import compare_audio_arrays
sys.path.append(SCRIPTS_DIR)
import pyaudio3dtools


# fixture returns test information, enabling per-testcase SNR
@pytest.fixture
def test_info(request):
@@ -53,7 +52,7 @@ def test_info(request):
def run_cmd(cmd, env=None):
    logging.info(f"\nRunning command\n{' '.join(cmd)}\n")
    try:
        sp.run(cmd, check=True, capture_output=True, text=True, env=env)
        sp.run(cmd, check=True, capture_output=True, text=True)
    except sp.CalledProcessError as e:
        raise SystemError(
            f"Command returned non-zero exit status ({e.returncode}): {' '.join(e.cmd)}\n{e.stderr}\n{e.stdout}"
@@ -180,15 +179,18 @@ def compare_multichannel_rom_vs_binary(
    out_fs,
    trj_file: Optional[str] = None
):
    ivas_format = "mc"
    option_list = [f"-{ivas_format}", in_fmt]
    in_fs = 48
    encoding_bitrate = 512000
    bitrate = 512000

    filename_ext = f"_{ivas_format}_{bitrate}_{in_fmt}_{in_fs}-{out_fmt}_{out_fs}"

    input_path = TESTV_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs)).with_suffix(".wav")
    bitstream_path = BITSTREAM_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs))
    option_list = ["-mc", in_fmt]
    run_encoder(encoding_bitrate, in_fs, input_path, bitstream_path, add_option_list=option_list)
    bitstream_path = BITSTREAM_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs) + filename_ext)
    run_encoder(bitrate, in_fs, input_path, bitstream_path, add_option_list=option_list)
    
    out_rom_path = DEC_ROM_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs)).with_suffix(".wav")
    out_rom_path = DEC_ROM_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs) + filename_ext).with_suffix(".wav")
    if trj_file is not None:
        option_list = ["-t", trj_file]
    else :
@@ -196,7 +198,7 @@ def compare_multichannel_rom_vs_binary(
    run_decoder(out_fmt, out_fs, bitstream_path, out_rom_path, add_option_list=option_list)
    out_rom, out_rom_fs = pyaudio3dtools.audiofile.readfile(out_rom_path)

    out_bin_path = DEC_BINARY_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs)).with_suffix(".wav")
    out_bin_path = DEC_BINARY_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs) + filename_ext).with_suffix(".wav")
    hrtf_file = HRTF_BINARY_FILE.format(out_fs)
    if trj_file is not None:
        option_list.extend(["-hrtf", str(HRTF_BINARY_DIR.joinpath(hrtf_file))])
@@ -206,3 +208,42 @@ def compare_multichannel_rom_vs_binary(
    out_bin, out_bin_fs = pyaudio3dtools.audiofile.readfile(out_rom_path)

    check_BE(test_info, out_rom, out_rom_fs, out_bin, out_bin_fs)


def compare_ambisonics_rom_vs_binary(
    test_info, 
    in_fmt, 
    in_fs,
    out_fmt, 
    out_fs,
    trj_file: Optional[str] = None
):
    ivas_format = "sba"
    option_list = [f"-{ivas_format}", INPUT_FORMATS_SBA[in_fmt]]
    bitrate = 256000
    
    filename_ext = f"_{ivas_format}_{bitrate}_{in_fmt}_{in_fs}-{out_fmt}_{out_fs}"

    input_path = TESTV_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs)).with_suffix(".wav")
    bitstream_path = BITSTREAM_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs) + filename_ext)

    run_encoder(bitrate, in_fs, input_path, bitstream_path, add_option_list=option_list)

    out_rom_path = DEC_ROM_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs) + filename_ext).with_suffix(".wav")
    if trj_file is not None:
        option_list = ["-t", trj_file]
    else :
        option_list = None
    run_decoder(out_fmt, out_fs, bitstream_path, out_rom_path, add_option_list=option_list)
    out_rom, out_rom_fs = pyaudio3dtools.audiofile.readfile(out_rom_path)

    out_bin_path = DEC_BINARY_DIR.joinpath(FORMAT_TO_FILE_WOEXT[in_fmt].format(in_fs) + filename_ext).with_suffix(".wav")
    hrtf_file = HRTF_BINARY_FILE.format(out_fs)
    if trj_file is not None:
        option_list.extend(["-hrtf", str(HRTF_BINARY_DIR.joinpath(hrtf_file))])
    else :
        option_list = ["-hrtf", str(HRTF_BINARY_DIR.joinpath(hrtf_file))]
    run_decoder(out_fmt, out_fs, bitstream_path, out_bin_path, add_option_list=option_list)
    out_bin, out_bin_fs = pyaudio3dtools.audiofile.readfile(out_rom_path)

    check_BE(test_info, out_rom, out_rom_fs, out_rom, out_rom_fs)
 No newline at end of file