fix(audiod): ALSA 几何收窄 period=1024×4(tiny_alsa惯例) — 根治长流停摆(驱动默认巨buffer致hbc3000桥周期中断稀缺wedge; tonepcm2矩阵实测60s零stall)。宿主38/38 PASS

This commit is contained in:
MeowOS committed 2026-09-01 11:06:01 +08:00
1 parent 805fcf179a
commit 84fd0a87aa
4 files changed
+18 -1

No files matched your search

Binary file not shown.
+6
View File
@@ -676,6 +676,12 @@ static int alsa_hw_params(int fd, unsigned rate, unsigned ch, unsigned fmt)
memset(sm, 0, sizeof *sm); pmask(sm, SNDRV_PCM_SUBFORMAT_STD);
pivset(&p.intervals[SNDRV_PCM_HW_PARAM_CHANNELS - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL], ch);
pivset(&p.intervals[SNDRV_PCM_HW_PARAM_RATE - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL], rate);
/* M2.94 长流停摆根治(真机实证 60s 零 stall):显式收窄周期几何到 tiny_alsa 惯例
* period=1024 frames × 4。否则驱动默认 buffer 巨大(上限 1048576 帧 ≈23s),
* hbc3000 桥靠周期中断驱动,中断稀缺 → 桥时钟域 wedge → 播 12s 左右停摆。
* (tonepcm2 几何矩阵实测:1024×4 连续 60s 实时消费零 stall。) */
pivset(&p.intervals[SNDRV_PCM_HW_PARAM_PERIOD_SIZE - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL], 1024);
pivset(&p.intervals[SNDRV_PCM_HW_PARAM_PERIODS - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL], 4);
p.rmask = ~0u; p.info = 0; p.msbits = 0; p.rate_num = 0; p.rate_den = 0;
return ioctl(fd, SNDRV_PCM_IOCTL_HW_PARAMS, &p);
}
+11
View File
@@ -86,6 +86,17 @@ int main(int argc, char **argv)
iv->min = iv->max = 2; iv->integer = 1;
iv = &p.intervals[SNDRV_PCM_HW_PARAM_RATE - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
iv->min = iv->max = 44100; iv->integer = 1;
{ /* 几何收窄:TPCM_PERIOD/TPCM_BCOUNT 环境变量(默认 1024x4,对齐 tinyalsa 惯例) */
unsigned ps = 1024, bc = 4;
const char *e;
if ((e = getenv("TPCM_PERIOD"))) ps = (unsigned)atoi(e);
if ((e = getenv("TPCM_BCOUNT"))) bc = (unsigned)atoi(e);
struct snd_interval *iv2 = &p.intervals[SNDRV_PCM_HW_PARAM_PERIOD_SIZE - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
iv2->min = iv2->max = ps; iv2->integer = 1;
iv2 = &p.intervals[SNDRV_PCM_HW_PARAM_PERIODS - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
iv2->min = iv2->max = bc; iv2->integer = 1;
printf("geometry: period=%u count=%u\n", ps, bc);
}
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; }