Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: SOF mis-detection silenced HDA codecs (Realtek ALC257 etc.)

Two bugs that combined to produce silent audio on every non-SOF Linux
device (ThinkPads, generic laptops):

1. The SOF probe at audio.c:2130 fired TRUE on any modern non-AC97
system because both gates were trivially satisfied:
- /sys/class/sound/card0/id → exists everywhere
- /proc/asound/card0/codec97#0 → absent on every non-AC97 codec
Replaced with a real check for the SOF kernel module:
/sys/module/snd_sof{,_pci}/initstate exists iff SOF is loaded.

2. The S32_LE write path uses `(int32_t)int16 << 8`, placing the int16
sample in the LOW 24 bits of int32. That's correct for SOF MAX98360A
(24-bit DSP at the SSP1 BE DAI), but 256× too quiet (-48 dB) for
HDA-direct codecs that interpret S32_LE as a true 32-bit DAC value.
Many HDA codecs (incl. ALC257) accept S32_LE in hw_params but expect
the sample in the high bits. Easier than a per-codec shift: only
try S32_LE when sof_active. Force S16_LE everywhere else.

flash-mac.sh: also bake user identity (handle/sub/email) into config.json
on both partitions by reading ~/.ac-token via SUDO_USER's home — same
flow as ac-os require_login. Empty fields fall back to anon if the user
hasn't run `ac-login` yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

+47 -14
+27 -2
fedac/native/scripts/flash-mac.sh
··· 63 63 [ -f "${SPLASH_EFI}" ] || die "Missing splash bootloader: ${SPLASH_EFI}" 64 64 [ -f "${SDBOOT_EFI}" ] || die "Missing systemd-boot: ${SDBOOT_EFI}" 65 65 66 + # --- read ac-login token (~/.ac-token) for handle/sub/email injection --- 67 + # When invoked as root via sudo, $HOME points at /var/root. Use SUDO_USER's 68 + # home so we read the actual operator's token, not the empty root one. 69 + TOKEN_HOME="${HOME}" 70 + [ -n "${SUDO_USER:-}" ] && TOKEN_HOME="$(eval echo ~${SUDO_USER})" 71 + TOKEN_FILE="${TOKEN_HOME}/.ac-token" 72 + 73 + USER_HANDLE=""; USER_SUB=""; USER_EMAIL="" 74 + if [ -f "${TOKEN_FILE}" ] && command -v node >/dev/null 2>&1; then 75 + eval "$(node -e ' 76 + const t = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")); 77 + let h = t.user?.handle || t.user?.name || ""; 78 + if (h.startsWith("@")) h = h.slice(1); 79 + const out = (k, v) => process.stdout.write(`${k}=${JSON.stringify(v || "")}\n`); 80 + out("USER_HANDLE", h); 81 + out("USER_SUB", t.user?.sub); 82 + out("USER_EMAIL", t.user?.email); 83 + ' "${TOKEN_FILE}" 2>/dev/null)" 84 + [ -n "${USER_HANDLE}" ] && log "Authenticated as @${USER_HANDLE}" 85 + fi 86 + [ -z "${USER_HANDLE}${USER_SUB}${USER_EMAIL}" ] && \ 87 + log "No ~/.ac-token (run \`ac-login\` first to bake credentials in)" 88 + 66 89 INFO=$(diskutil info "${USB_DEV}" 2>/dev/null) || die "diskutil info failed for ${USB_DEV}" 67 90 echo "${INFO}" | grep -q "Removable Media:.*Removable\|Device Location:.*External" \ 68 91 || die "${USB_DEV} is not removable/external. Aborting." ··· 148 171 mkdir -p "${M1}/EFI/BOOT" 149 172 cp "${KERNEL}" "${M1}/EFI/BOOT/BOOTX64.EFI" 150 173 cp "${INITRAMFS}" "${M1}/initramfs.cpio.gz" 151 - echo '{"handle":"","piece":"notepat","sub":"","email":""}' | tee "${M1}/config.json" >/dev/null 174 + printf '{"handle":"%s","piece":"notepat","sub":"%s","email":"%s"}\n' \ 175 + "${USER_HANDLE}" "${USER_SUB}" "${USER_EMAIL}" | tee "${M1}/config.json" >/dev/null 152 176 [ -f "${SRC_DIR}/wifi_creds.json" ] && cp "${SRC_DIR}/wifi_creds.json" "${M1}/wifi_creds.json" 153 177 154 178 # --- layout ACEFI (systemd-boot universal) --- ··· 168 192 initrd /initramfs.cpio.gz 169 193 options console=tty0 quiet loglevel=3 vt.global_cursor_default=0 init=/init nomodeset efi=noruntime 170 194 EOF 171 - echo '{"handle":"","piece":"notepat","sub":"","email":""}' | tee "${M2}/config.json" >/dev/null 195 + printf '{"handle":"%s","piece":"notepat","sub":"%s","email":"%s"}\n' \ 196 + "${USER_HANDLE}" "${USER_SUB}" "${USER_EMAIL}" | tee "${M2}/config.json" >/dev/null 172 197 [ -f "${SRC_DIR}/wifi_creds.json" ] && cp "${SRC_DIR}/wifi_creds.json" "${M2}/wifi_creds.json" 173 198 174 199 # --- verify (sha256 round-trip on every kernel + initramfs copy) ---
+20 -12
fedac/native/src/audio.c
··· 2061 2061 return audio; 2062 2062 } 2063 2063 2064 + // SOF detection must happen FIRST, because the format choice depends on it. 2065 + // The S32_LE write path uses `<< 8` shift (writes int16 into the low 24 2066 + // bits of int32), which is correct for SOF's MAX98360A 24-bit DSP but 2067 + // 256× too quiet for HDA's true 32-bit DAC — even though both codecs 2068 + // accept S32_LE in their hw_params. Force S16_LE on non-SOF hardware. 2069 + int sof_active = (access("/sys/module/snd_sof/initstate", F_OK) == 0) || 2070 + (access("/sys/module/snd_sof_pci/initstate", F_OK) == 0); 2071 + 2064 2072 // Configure ALSA — negotiate rate dynamically. 2065 2073 // Try preferred rates from highest to lowest. The hardware decides what it 2066 2074 // actually supports; we adapt period/buffer sizes to match the negotiated rate. ··· 2071 2079 /* SOF topology FE PCMs use S32_LE internally; the SSP1 BE DAI 2072 2080 * (MAX98360A) runs S24_LE. Writing S16_LE to this pipeline 2073 2081 * causes 48dB attenuation + quantization noise ("crunchy quiet"). 2074 - * Try S32_LE first — if the FE PCM accepts it, we write int32 2075 - * samples and the DSP does zero conversion. Fall back to S16_LE 2076 - * for non-SOF hardware (HDA, USB, etc). */ 2082 + * Try S32_LE on SOF only. On HDA / USB / generic codecs, S16_LE 2083 + * is the universally-correct choice — even when the codec 2084 + * advertises S32_LE support, our int16<<8 conversion drops 8 of 2085 + * the high bits and produces inaudibly-quiet output. */ 2077 2086 audio->use_s32 = 0; 2078 - if (snd_pcm_hw_params_set_format(pcm, params, SND_PCM_FORMAT_S32_LE) == 0) { 2087 + if (sof_active && 2088 + snd_pcm_hw_params_set_format(pcm, params, SND_PCM_FORMAT_S32_LE) == 0) { 2079 2089 audio->use_s32 = 1; 2080 - fprintf(stderr, "[audio] Negotiated S32_LE format\n"); 2090 + fprintf(stderr, "[audio] Negotiated S32_LE format (SOF)\n"); 2081 2091 } else { 2082 2092 snd_pcm_hw_params_any(pcm, params); 2083 2093 snd_pcm_hw_params_set_access(pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED); 2084 2094 snd_pcm_hw_params_set_format(pcm, params, SND_PCM_FORMAT_S16_LE); 2085 - fprintf(stderr, "[audio] Negotiated S16_LE format (S32_LE not supported)\n"); 2095 + fprintf(stderr, "[audio] Negotiated S16_LE format%s\n", 2096 + sof_active ? " (S32_LE rejected)" : " (non-SOF, forced)"); 2086 2097 } 2087 2098 snd_pcm_hw_params_set_channels(pcm, params, AUDIO_CHANNELS); 2088 2099 ··· 2123 2134 // despite mixer, codec, and GPIO all looking correct. We saw 10,686 2124 2135 // sdmode toggles in a single boot's kmsg on the G7 at the 1ms setting. 2125 2136 // 2126 - // Probe whether we're on a SOF platform (sound/soc/sof is one path) and 2127 - // bump to 10ms / 40ms which is what ChromeOS itself uses. Non-SOF HDA 2128 - // devices (ThinkPads, most laptops) keep the tight latency because their 2129 - // amp/codec model doesn't gate on per-period DAPM events. 2130 - int sof_active = (access("/sys/class/sound/card0/id", R_OK) == 0) && 2131 - (access("/proc/asound/card0/codec97#0", F_OK) != 0); 2137 + // Period + buffer: 20ms/80ms on SOF (avoids MAX98357A SD_MODE GPIO 2138 + // thrash), 1ms/4ms on HDA-direct paths (tight latency safe there). 2139 + // sof_active was set above before format negotiation. 2132 2140 snd_pcm_uframes_t period; 2133 2141 snd_pcm_uframes_t buffer_size; 2134 2142 if (sof_active) {