Skip to content

Commit 1a864ad

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 e09defe commit 1a864ad

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/capture-test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ def parse_opts():
4949
global opts # pylint: disable=global-statement
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)")
@@ -114,6 +116,16 @@ def pcm_init_stream(pcm, rate, chans, fmt, access):
114116
alsa.snd_pcm_hw_params_set_channels(pcm, hwp, chans)
115117
alsa.snd_pcm_hw_params_set_rate(pcm, hwp, rate, 0)
116118
alsa.snd_pcm_hw_params_set_access(pcm, hwp, access)
119+
alsa.snd_pcm_hw_params_set_buffer_size(pcm, hwp, opts.bufsz)
120+
if opts.verbose:
121+
print("Set hw_params:")
122+
out = C.c_ulong(0)
123+
alsa.snd_output_buffer_open(C.byref(out))
124+
alsa.snd_pcm_hw_params_dump(hwp, out)
125+
buf = C.c_ulong(0)
126+
alsa.snd_output_buffer_string(out, C.byref(buf))
127+
print(C.string_at(buf.value).decode("ascii", errors="ignore"))
128+
117129
alsa.snd_pcm_hw_params(pcm, hwp)
118130

119131
def ctl_disable_rtnr():

0 commit comments

Comments
 (0)