Skip to content

Commit 3f95419

Browse files
committed
capture-test: Add buffer size control & verbose logging
Recent SOF drivers have started populating the buffer size of ALSA hw_params structs with values that produce an -EINVAL if you try to set them (unclear to me if this is a bug or not). Regardless, the capture test wants control over that, so add it. Also hook the ALSA hw_params dump code (for debugging issues like this) and hide it under a "--verbose" flag. Signed-off-by: Andy Ross <andyross@google.com>
1 parent 6571dcf commit 3f95419

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/capture-test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ def parse_opts():
4949
global opts
5050
ap = argparse.ArgumentParser(description=HELP_TEXT,
5151
formatter_class=argparse.RawDescriptionHelpFormatter)
52+
ap.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
5253
ap.add_argument("--disable-rtnr", action="store_true", help="Disable RTNR noise reduction")
5354
ap.add_argument("-c", "--card", type=int, default=0, help="ALSA card index")
5455
ap.add_argument("--pcm", type=int, default=16, help="Output ALSA PCM index")
5556
ap.add_argument("--cap", type=int, default=18, help="Capture ALSA PCM index")
5657
ap.add_argument("--rate", type=int, default=48000, help="Sample rate")
5758
ap.add_argument("--chan", type=int, default=2, help="Output channel count")
59+
ap.add_argument("--bufsz", type=int, default=2048, help="Buffer size in frames")
5860
ap.add_argument("--capchan", type=int,
5961
help="Capture channel count (if different from output)")
6062
ap.add_argument("--capbits", type=int, default=16, help="Capture sample bits (16 or 32)")
@@ -111,8 +113,18 @@ def pcm_init_stream(pcm, rate, chans, fmt, access):
111113
alsa.snd_pcm_hw_params_any(pcm, hwp)
112114
alsa.snd_pcm_hw_params_set_format(pcm, hwp, fmt)
113115
alsa.snd_pcm_hw_params_set_channels(pcm, hwp, chans)
114-
alsa.snd_pcm_hw_params_set_rate(pcm, hwp, rate, alsa.PCM_STREAM_PLAYBACK)
116+
alsa.snd_pcm_hw_params_set_rate(pcm, hwp, rate, 0)
115117
alsa.snd_pcm_hw_params_set_access(pcm, hwp, access)
118+
alsa.snd_pcm_hw_params_set_buffer_size(pcm, hwp, opts.bufsz)
119+
if opts.verbose:
120+
print(f"Set hw_params:")
121+
out = C.c_ulong(0)
122+
alsa.snd_output_buffer_open(C.byref(out))
123+
alsa.snd_pcm_hw_params_dump(hwp, out)
124+
buf = C.c_ulong(0)
125+
alsa.snd_output_buffer_string(out, C.byref(buf))
126+
print(C.string_at(buf.value).decode("ascii"))
127+
116128
alsa.snd_pcm_hw_params(pcm, hwp)
117129

118130
def ctl_disable_rtnr():

0 commit comments

Comments
 (0)