Skip to content

Commit

Permalink
use .formatInfo when rewriting bwf files
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjnixon committed Dec 1, 2023
1 parent 11b15d7 commit 594c025
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
11 changes: 2 additions & 9 deletions ear/cmdline/ambix_to_bwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..fileio.adm.generate_ids import generate_ids
from ..fileio.adm.xml import adm_to_xml
from ..fileio import openBw64
from ..fileio.bw64.chunks import ChnaChunk, FormatInfoChunk
from ..fileio.bw64.chunks import ChnaChunk


def add_args(subparsers):
Expand Down Expand Up @@ -105,15 +105,8 @@ def ambix_to_bwf(args):
chna = ChnaChunk()
populate_chna_chunk(chna, adm)

fmtInfo = FormatInfoChunk(
formatTag=1,
channelCount=infile.channels,
sampleRate=infile.sampleRate,
bitsPerSample=infile.bitdepth,
)

with openBw64(
args.output, "w", chna=chna, formatInfo=fmtInfo, axml=axml
args.output, "w", chna=chna, formatInfo=infile.formatInfo, axml=axml
) as outfile:
while True:
samples = infile.read(1024)
Expand Down
32 changes: 14 additions & 18 deletions ear/cmdline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from ..compatibility import write_bytes_to_stdout
from ..fileio import openBw64
from ..fileio.bw64.chunks import FormatInfoChunk, ChnaChunk
from ..fileio.bw64.chunks import ChnaChunk
import warnings
from . import ambix_to_bwf
from . import generate_test_file
Expand All @@ -23,9 +23,6 @@ def replace_axml_command(args):
axml = axml_file.read()

with openBw64(args.input) as infile:
formatInfo = FormatInfoChunk(channelCount=infile.channels,
sampleRate=infile.sampleRate,
bitsPerSample=infile.bitdepth)
if args.gen_chna:
adm = adm_xml.parse_string(axml)
adm_chna.guess_track_indices(adm)
Expand All @@ -39,8 +36,9 @@ def replace_axml_command(args):
"not have a CHNA chunk. Either specify '-g', or use an input " +
"file with a CHNA chunk.")

with openBw64(args.output, 'w', formatInfo=formatInfo,
axml=axml, chna=chna) as outfile:
with openBw64(
args.output, "w", formatInfo=infile.formatInfo, axml=axml, chna=chna
) as outfile:
while True:
samples = infile.read(2048)
if not len(samples):
Expand Down Expand Up @@ -82,10 +80,6 @@ def regenerate_command(args):
import lxml.etree

with openBw64(args.input) as infile:
formatInfo = FormatInfoChunk(channelCount=infile.channels,
sampleRate=infile.sampleRate,
bitsPerSample=infile.bitdepth)

adm = ADM()
load_common_definitions(adm)

Expand All @@ -109,20 +103,22 @@ def regenerate_command(args):
chna = ChnaChunk()
adm_chna.populate_chna_chunk(chna, adm)

with openBw64(args.output, 'w', formatInfo=formatInfo,
axml=axml, chna=chna) as outfile:
with openBw64(
args.output, "w", formatInfo=infile.formatInfo, axml=axml, chna=chna
) as outfile:
for samples in infile.iter_sample_blocks(2048):
outfile.write(samples)


def rewrite_command(args):
with openBw64(args.input) as infile:
formatInfo = FormatInfoChunk(channelCount=infile.channels,
sampleRate=infile.sampleRate,
bitsPerSample=infile.bitdepth)

with openBw64(args.output, 'w', formatInfo=formatInfo,
axml=infile.axml, chna=infile.chna) as outfile:
with openBw64(
args.output,
"w",
formatInfo=infile.formatInfo,
axml=infile.axml,
chna=infile.chna,
) as outfile:
while True:
samples = infile.read(2048)
if not len(samples):
Expand Down

0 comments on commit 594c025

Please sign in to comment.