Skip to content

Commit

Permalink
ensure HTx writes to the target channels
Browse files Browse the repository at this point in the history
  • Loading branch information
3ll3d00d committed Jun 8, 2024
1 parent 2f301bc commit 72bb411
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/python/model/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ def filter_channels(self):
else:
return ['1', '2']

@property
def input_channel_count(self):
return 0 if self == DspType.MINIDSP_HTX else 2


OUTPUT_CHANNELS_BY_DEVICE = {
DspType.MONOPRICE_HTP1: ['sub1', 'sub2', 'sub3', 'sub4', 'sub5', 'lf', 'rf', 'c', 'ls', 'rs', 'lb', 'rb', 'ltf',
Expand Down
6 changes: 3 additions & 3 deletions src/main/python/model/minidsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ def __init__(self, minidsp_type, optimise_filters, selected_channels=None, in_ou
super().__init__(minidsp_type, optimise_filters, pad=in_out_split is None)
self.__in_out_split = in_out_split
if selected_channels:
self.__selected_channels = [self.__extract_channel(i) for i in selected_channels]
self.__selected_channels = [self.__extract_channel(i, minidsp_type) for i in selected_channels]
else:
self.__selected_channels = minidsp_type.filter_channels

@staticmethod
def __extract_channel(txt):
def __extract_channel(txt, minidsp_type):
if len(txt) == 1:
return txt[0]
elif txt[0:5] == 'Input':
return txt[-1]
elif txt[0:6] == 'Output':
return str(int(txt[-1]) + 2)
return str(int(txt[-1]) + minidsp_type.input_channel_count)
else:
raise ValueError(f"Unsupported channel {txt}")

Expand Down
12 changes: 12 additions & 0 deletions src/test/python/model/test_minidsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ def test_merge_HTx():
convert_and_compare(f1, f2, filt, parser)


def test_merge_HTx_selected():
from model.minidsp import xml_to_filt, HDXmlParser
from model.merge import DspType
suffix = 'HTx'
dsp_type = DspType.MINIDSP_HTX
parser = HDXmlParser(dsp_type, False, selected_channels=[f'Output {i}' for i in range(1, 9)])
filt = xml_to_filt(os.path.join(os.path.dirname(__file__), 'input.xml'))
with open(os.path.join(os.path.dirname(__file__), f'MiniDSP-{suffix}.xml'), 'r') as f1:
with open(os.path.join(os.path.dirname(__file__), f'expected_output_{suffix}.xml'), 'r') as f2:
convert_and_compare(f1, f2, filt, parser)


def convert_and_compare(f1, f2, filts, parser):
dst = io.StringIO(f1.read())
expected = f2.read()
Expand Down

0 comments on commit 72bb411

Please sign in to comment.