Skip to content

Commit

Permalink
fileio: run trackIndex validation in Bw64AdmReader
Browse files Browse the repository at this point in the history
fixes #30
  • Loading branch information
tomjnixon committed Mar 18, 2024
1 parent d491a07 commit 52ec6fe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ear/fileio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .adm.adm import ADM
from .adm.xml import load_axml_string
from .adm.common_definitions import load_common_definitions
from .adm.chna import load_chna_chunk
from .adm.chna import load_chna_chunk, validate_trackIndex


def openBw64(filename, mode='r', **kwargs):
Expand Down Expand Up @@ -147,5 +147,6 @@ def _parse_adm(self):
self.logger.info("Parsing done!")

load_chna_chunk(adm, chna)
validate_trackIndex(adm, self.channels)

return adm
35 changes: 35 additions & 0 deletions ear/test/test_integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,41 @@ def test_plain_wav(tmpdir):
assert b"does not have ADM metadata" in err_no_adm


def test_bad_track_index(tmpdir):
from ..fileio import openBw64
from ..fileio.bw64.chunks import AudioID, ChnaChunk, FormatInfoChunk

bad_track_index = str(tmpdir / "bad_track_index.wav")
rendered_file = str(tmpdir / "bad_track_index_out.wav")

chna = ChnaChunk()
chna.audioIDs.append(
AudioID(
trackIndex=2,
audioTrackUID="ATU_00000001",
audioTrackFormatIDRef="AT_00010003_01",
audioPackFormatIDRef="AP_00010001",
)
)

samples = generate_samples()[:, :1]
fmtInfo = FormatInfoChunk(
formatTag=1, channelCount=samples.shape[1], sampleRate=sr, bitsPerSample=24
)

with openBw64(bad_track_index, "w", chna=chna, formatInfo=fmtInfo) as outfile:
outfile.write(samples)

args = ["ear-render", "-s", "0+5+0", bad_track_index, rendered_file]
proc = subprocess.run(args, capture_output=True)

assert proc.returncode != 0

[err_bad_track] = [line for line in proc.stderr.split(b"\n") if line.strip()]
assert b"ATU_00000001 has track index 2" in err_bad_track
assert b"in a file with 1 track" in err_bad_track


@pytest.mark.parametrize("order", [1, 2])
@pytest.mark.parametrize("chna_only", [False, True])
def test_hoa(tmpdir, order, chna_only):
Expand Down

0 comments on commit 52ec6fe

Please sign in to comment.