Skip to content

Commit a926c63

Browse files
committed
capture-test.py: Add channel map feature
Hardware is awful. Some MTL boards needlessly move their 2-channel mic inputs around in the 4 channel DMIC space, so doing the test in an automated way needs to duplicate the idea of a channel map. Thankfully this is python and not firmware so it's like six lines to add a --capmap argument. It's a string, so e.g. "--capmap 23" will select out the 3rd and 4th capture channels as the 2-channel stream to inspect. Signed-off-by: Andy Ross <andyross@google.com>
1 parent 6933ee2 commit a926c63

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tools/capture-test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def parse_opts():
6060
ap.add_argument("--capchan", type=int,
6161
help="Capture channel count (if different from output)")
6262
ap.add_argument("--capbits", type=int, default=16, help="Capture sample bits (16 or 32)")
63+
ap.add_argument("--capmap", type=str, default="01",
64+
help="Capture channel map (as string, e.g. '23' to select 3rd/4th elems)")
6365
ap.add_argument("--noise", default="noise.wav",
6466
help="WAV file containing 'noise' for capture")
6567
ap.add_argument("--duration", type=int, default=3, help="Capture duration (seconds)")
@@ -71,6 +73,7 @@ def parse_opts():
7173
opts = ap.parse_args()
7274
if not opts.capchan:
7375
opts.capchan = opts.chan
76+
opts.capmap = [int(x) for x in opts.capmap]
7477
opts.base_test = not (opts.chirp_test or opts.echo_test)
7578

7679
class ALSA:
@@ -295,7 +298,9 @@ def cap_to_playback(buf):
295298
# treat it, and it can plausibly create false positive chirp signals
296299
# loud enough).
297300
for i in range(0, len(buf), capsz):
298-
frame = [scale * x for x in struct.unpack(capfmt, buf[i:i+capsz])[0:opts.chan]]
301+
frame = struct.unpack(capfmt, buf[i:i+capsz]) # Decode
302+
frame = [frame[i] for i in opts.capmap] # Select via channel map
303+
frame = [scale * x for x in frame] # Convert to float
299304
if last_frame:
300305
delta_sum += sum(abs(last_frame[x] - frame[x]) for x in range(opts.chan))
301306
last_frame = frame

0 commit comments

Comments
 (0)