tools: tonepcm2 支持设备参数(测 D1p) + PROBE_ONLY 模式(只探测不播放, 防挂死)

This commit is contained in:
MeowOS committed 2026-09-01 03:16:52 +08:00
1 parent 57509cd582
commit 793a807ce3
1 file changed
+5 -2
+5 -2
View File
@@ -41,8 +41,10 @@ static const char *fmt_name(unsigned f)
int main(int argc, char **argv)
{
int sec = argc > 1 ? atoi(argv[1]) : 5;
int fd = open("/dev/snd/pcmC0D0p", O_RDWR);
if (fd < 0) { printf("open fail\n"); return 1; }
const char *dev = (argc > 2) ? argv[2] : "/dev/snd/pcmC0D0p";
int fd = open(dev, O_RDWR);
if (fd < 0) { printf("open %s fail\n", dev); return 1; }
printf("dev=%s\n", dev);
/* 1) REFINE 探测 */
struct snd_pcm_hw_params p;
@@ -85,6 +87,7 @@ int main(int argc, char **argv)
iv = &p.intervals[SNDRV_PCM_HW_PARAM_RATE - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
iv->min = iv->max = 44100; iv->integer = 1;
if (ioctl(fd, SNDRV_PCM_IOCTL_HW_REFINE, &p) != 0) { printf("REFINE2 fail\n"); close(fd); return 1; }
if (getenv("PROBE_ONLY")) { printf("PROBE_ONLY: stop before PARAMS/write\n"); close(fd); return 0; }
if (ioctl(fd, SNDRV_PCM_IOCTL_HW_PARAMS, &p) != 0) { printf("HW_PARAMS fail\n"); close(fd); return 1; }
printf("HW_PARAMS ok\n");
if (ioctl(fd, SNDRV_PCM_IOCTL_PREPARE, 0) != 0) { printf("PREPARE fail\n"); close(fd); return 1; }