ESP32 source: 48 kHz stereo PCM overflows capture buffer; Opus registers as player

未关闭
#219 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp

调研方向

Start with the source capture and send path around components/sendspin/sendspin_hub.h, using the provided 48 kHz stereo YAML to reproduce the capture-buffer warnings and timestamp resets. Trace the client/hello source advertisement and codec-dependent registration path to determine why Opus registers as a player. Reproduction is complete when 48 kHz stereo no longer overflows and the Opus build is registered as a source without bridge resets.

由索引模型根据 Issue 内容生成。

描述

ESP32-A1S Sendspin source: 48 kHz stereo PCM overflows the capture buffer (32 kHz stereo / 48 kHz mono are clean); Opus makes MA register the board as a player

Tested with the joshualh/sendspin-a1s-source ESPHome test rig (that repo has issues disabled), which uses the sendspin-cpp source role from #166/#167/#172/#175.

Summary

Using the sendspin-a1s-source test rig as a Sendspin source (line-in from a stereo → Music Assistant Live Input → AirPlay speaker):

  1. 48 kHz / 16-bit stereo PCM (~1.5 Mbit/s) drops audio. The board logs Capture buffer full; dropping writes until it drains, and Music Assistant (aiosendspin SourceBridge) logs Source timestamp jumped …, resetting bridge. Each reset is an audible gap.
  2. The data rate is the limit. 48 kHz mono (~0.77 Mbit/s) and 32 kHz stereo (~1.0 Mbit/s) both play cleanly, with zero board drops and zero bridge resets, on the same hardware, Wi-Fi, server and speaker.
  3. codec: opus makes Music Assistant register the board as a player ("type protocol", then wrapped in a Universal Player that "requires setup") instead of a source, so Opus can't be used to reduce the data rate.

The playback path is not the cause: the same Music Assistant server and the same AirPlay player play normal library content cleanly.

I searched the issues in joshualh/sendspin-a1s-source, Sendspin/sendspin-cpp, Sendspin/aiosendspin and esphome/esphome (including draft PR #21696) and found no existing report.

Environment

Item Version / detail
Board ESP32-A1S Audio Kit V2.2, ES8388 codec (I²C 0x10), 8 MB PSRAM, chip rev 3.1, DIP switches as shipped
Component joshualh/sendspin-a1s-source @ b7a93b6 (local copy)
sendspin-cpp joshualh/sendspin-cpp fork @ 6d7ecef (includes upstream #175 "Ride out source send stalls"; no source changes upstream since the fork's base)
Local patch Added to components/sendspin/sendspin_hub.h (build failed without it): StringRef get_client_id() const { return this->client_ == nullptr ? StringRef() : StringRef(this->client_->client_id()); }
ESPHome 2026.10.1 (Home Assistant add-on), ESP-IDF 5.5.6
Home Assistant Core 2026.10.4, OS 18.3
Music Assistant 2.10.8, aiosendspin 10.2.1
Wi-Fi RSSI −51 to −54 dBm, power_save_mode: none, consumer router (not a mesh)
Input Stereo tape-record output (line level) → A1S LINE2 input
Output in MA Live Input → AirPlay 2 player (Arylic LP10)

Working config (32 kHz stereo, clean)

esp32:
  board: esp-wrover-kit
  flash_frequency: 80MHZ
  framework:
    type: esp-idf

psram:
  speed: 80MHZ
  ignore_not_found: false   # enables ESPHome's high-performance lwip/Wi-Fi tier

logger:
  level: INFO

wifi:
  power_save_mode: none

external_components:
  - source:
      type: local
      path: sendspin-a1s/components
    components: [sendspin]

# ES8388 on_boot register writes: 0x0C=0x0C, 0x0B=0x00, 0x12=0x22, 0x16=0x00
# select adc_input: LINE2

microphone:
  - platform: i2s_audio
    id: a1s_adc
    adc_type: external
    i2s_din_pin: GPIO35
    pdm: false
    sample_rate: 32000      # 48000 drops (see below)
    bits_per_sample: 16bit
    channel: stereo
    use_apll: true
    # I2S: MCLK GPIO0, BCLK GPIO27, LRCK GPIO25

sendspin:
  id: sendspin_hub
  task_stack_in_psram: false
  static_pairing_code: "<redacted>"
  source:
    microphone:
      microphone: a1s_adc
      channels: [0, 1]
    capture_buffer: 2000ms
    # chunk_duration: default 20 ms

(Full YAML available on request.)

Steps to reproduce

  1. Flash the config above with sample_rate: 48000, and pair the board in Music Assistant.
  2. Feed a continuous line-level signal (a record playing) into LINE2.
  3. Select the board's Live Input in MA and play it to an AirPlay player.
  4. Watch the ESPHome log and the MA server log.

Observed at 48 kHz stereo

Board (ESPHome log):

[W][sendspin.source_task]: Capture buffer full; dropping writes until it drains
[W][sendspin.source_task]: Dropped 1 capture writes

Music Assistant log:

WARNING aiosendspin.audio.source_bridge: Source timestamp jumped 2495928 us, resetting bridge
  • Each board overflow is followed by one MA bridge reset, and each reset is an audible gap.
  • The gap size tracks capture_buffer. With 500 ms, the board warnings came in runs exactly ~0.62 s apart, and MA's jumps were whole multiples of ~0.62 s (1.24, 1.87, 2.48 s). With 2000 ms, the jumps are ~2.5 s. This fits the source task flushing the whole backlog on overflow and resuming from live capture.
  • The buffer fills steadily rather than from occasional stalls. Raising capture_buffer from 500 ms to 2000 ms made overflows less frequent (about every 3.5 s, then every 10–15 s) but each one longer. The user heard playback start clean, then gaps getting closer together. A 2 s buffer still overflowing means sending lags capture all the time, not just during brief Wi-Fi stalls.
  • In mono and at 32 kHz stereo: no overflows and no resets over 20+ minutes of playback.

What I tried (one change at a time)

Change Board drops Result
Baseline (repo defaults, 48 kHz stereo) 0.82 /s —
task_stack_in_psram: false 0.36 /s better
+ PSRAM and flash at 80 MHz 0.23 /s better
+ 44.1 kHz instead of 48 kHz 0.69 /s worse, reverted
40 ms chunks instead of 20 ms 0.57 /s worse, reverted
60 ms chunks — boot/crash loop, reverted
use_apll: true 0.28 /s no meaningful change (kept)
capture_buffer: 2000ms ~0.09 /s, but ~2.5 s gaps fewer but longer gaps (kept)
psram: ignore_not_found: false (ESPHome high-performance lwip/Wi-Fi tier confirmed in build log) ~0.065 /s slight improvement only (kept)
Mono, 48 kHz (channels: [0]) 0 clean
codec: opus (stereo, 48 kHz) — MA registers the board as a player, not a source
32 kHz stereo 0 clean (current config)

Opus registration problem

With codec: opus as the only change, Music Assistant logs:

INFO [music_assistant.players] Player (type protocol) registered: <id>/Sansui Source
INFO [music_assistant.Universal Player] Creating universal player <id> with protocol players: ['<id>']
INFO [music_assistant.players] Player (type player) registered: <id>/Sansui Source

With PCM, the same board registers as Player (type source). In sendspin-cpp, the client/hello source support object doesn't appear to depend on the codec, so I'm not sure whether the difference comes from the build (Opus-enabled sdkconfig) or from the MA side.

Other observations

  • MA logs "non-compliant client" warnings for the board: client/hello sent supported_pair_methods as a list, client sent client_stream/start, superseded by client-stream/start (and /end). They look like the fork's aiosendspin 9.1.1 message names meeting aiosendspin 10.2.1. Harmless here, but noting them.
  • Pairing persists across power cycles: the board is powered off nightly and re-registers as a source without re-pairing.

Questions

  1. Is ~1.5 Mbit/s (48 kHz/16-bit stereo PCM) expected to be beyond the A1S source pipeline? Wi-Fi capacity shouldn't be the limit at −52 dBm, and ESPHome's high-performance network tier barely changed it. Is the cost per message (e.g. Noise encryption, websocket framing), or something else in the send path?
  2. Why does codec: opus change how MA registers the board (player instead of source)? Opus would be the natural fix for stereo at 48 kHz.
  3. On overflow, would dropping only the oldest chunk(s) instead of flushing the whole backlog keep each gap small (tens of ms rather than the full buffer length)?
  4. Should the MA bridge insert silence for a gap this size instead of resetting?

Happy to run test builds or capture DEBUG logs.

主要语言
C++
星标
32
派生
19
平均合并
14 小时 54 分钟
30 天内合并 PR
49

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Sendspin/sendspin-cpp 的其他 Issue

查看 Sendspin/sendspin-cpp 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。