CarlosDerSeher / snapclient

snapclient on ESP32
GNU General Public License v3.0
133 stars 18 forks source link

Sample rates different from 48kHz break player #15

Closed jhuber-de closed 1 year ago

jhuber-de commented 1 year ago

Hi,

I have an issue with the snapclient on my LyraT v4.3. I build the firmware using the NETCON-Branch and changed only my wifi and snapcast server IP using the menuconfig. Flashing and connecting to the snapcast server works, but the playback using librespot as input to snapcast is a horrible stuttery noise. Other clients like my phone work just fine with my librespot / snapcast setup.

The output of the LyraT throws a ton of E (250821) PLAYER: Failed to allocate IRAM memory for pcm chunk payload and E (250821) PLAYER: Failed to allocate IRAM memory for pcm chunk payload warnings / errors.

E (249040) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (249057) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249057) PLAYER: RESYNCING HARD 2: age 25197us, latency 592103734159us, free 37932, largest block 13824, 34, rssi: -75
I (249161) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249162) PLAYER: RESYNCING HARD 2: age 25305us, latency 592103734159us, free 41456, largest block 18432, 33, rssi: -74
I (249266) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249266) PLAYER: RESYNCING HARD 2: age 25239us, latency 592103734159us, free 37928, largest block 12544, 34, rssi: -73
I (249370) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249371) PLAYER: RESYNCING HARD 2: age 25229us, latency 592103734137us, free 37932, largest block 13824, 34, rssi: -74
I (249475) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249475) PLAYER: RESYNCING HARD 2: age 25271us, latency 592103734137us, free 37944, largest block 18432, 34, rssi: -73
I (249579) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249580) PLAYER: RESYNCING HARD 2: age 25189us, latency 592103734137us, free 37944, largest block 18432, 34, rssi: -72
I (249684) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249684) PLAYER: RESYNCING HARD 2: age 25203us, latency 592103734137us, free 37924, largest block 9216, 34, rssi: -74
E (249721) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
E (249762) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
E (249784) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (249788) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249789) PLAYER: RESYNCING HARD 2: age 25248us, latency 592103734137us, free 37928, largest block 13824, 34, rssi: -73
E (249883) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (249893) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249893) PLAYER: RESYNCING HARD 2: age 25267us, latency 592103734137us, free 37936, largest block 13824, 34, rssi: -74
I (249997) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (249998) PLAYER: RESYNCING HARD 2: age 25242us, latency 592103734137us, free 37928, largest block 11520, 34, rssi: -68
E (250061) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
E (250099) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (250102) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250103) PLAYER: RESYNCING HARD 2: age 25665us, latency 592103734137us, free 37932, largest block 9216, 34, rssi: -69
I (250206) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250207) PLAYER: RESYNCING HARD 2: age 25266us, latency 592103734137us, free 37936, largest block 12544, 34, rssi: -70
E (250302) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (250311) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250311) PLAYER: RESYNCING HARD 2: age 24591us, latency 592103733475us, free 37924, largest block 9216, 34, rssi: -72
I (250416) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250416) PLAYER: RESYNCING HARD 2: age 25257us, latency 592103733475us, free 37916, largest block 18432, 34, rssi: -71
I (250520) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250521) PLAYER: RESYNCING HARD 2: age 25235us, latency 592103733475us, free 37888, largest block 18432, 34, rssi: -72
I (250625) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250625) PLAYER: RESYNCING HARD 2: age 25249us, latency 592103733475us, free 36156, largest block 13824, 34, rssi: -73
E (250705) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
E (250718) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (250729) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250730) PLAYER: RESYNCING HARD 2: age 25244us, latency 592103733475us, free 37832, largest block 13824, 34, rssi: -76
E (250821) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (250834) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (250834) PLAYER: RESYNCING HARD 2: age 25268us, latency 592103733475us, free 37824, largest block 13824, 34, rssi: -74
E (250919) PLAYER: Failed to allocate IRAM memory for pcm chunk payload

This is another output right after reseting the LyraT and starting the playback on spotify

rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:7660
ho 0 tail 12 room 4
load:0x40078000,len:15748
load:0x40080400,len:4392
0x40080400: _init at ??:?

entry 0x4008069c
I (29) boot: ESP-IDF v4.3.4-dirty 2nd stage bootloader
I (29) boot: compile time 16:25:03
I (29) boot: chip revision: 3
I (32) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (40) qio_mode: Enabling default flash chip QIO
I (45) boot.esp32: SPI Speed      : 80MHz
I (49) boot.esp32: SPI Mode       : QIO
I (54) boot.esp32: SPI Flash Size : 4MB
I (59) boot: Enabling RNG early entropy source...
I (64) boot: Partition Table:
I (68) boot: ## Label            Usage          Type ST Offset   Length
I (75) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (82) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (90) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (97) boot:  3 factory          factory app      00 00 00010000 00120000
I (105) boot:  4 ota_0            OTA app          00 10 00130000 00120000
I (112) boot:  5 ota_1            OTA app          00 11 00250000 00120000
I (120) boot: End of partition table
I (124) boot: Defaulting to factory image
I (129) boot_comm: chip revision: 3, min. application chip revision: 0
I (136) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=19dd0h (105936) map
I (174) esp_image: segment 1: paddr=00029df8 vaddr=3ffb0000 size=03ddch ( 15836) load
I (179) esp_image: segment 2: paddr=0002dbdc vaddr=40080000 size=0243ch (  9276) load
I (183) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=8d4f4h (578804) map
I (347) esp_image: segment 4: paddr=000bd51c vaddr=4008243c size=113bch ( 70588) load
I (371) esp_image: segment 5: paddr=000ce8e0 vaddr=50000000 size=00010h (    16) load
I (381) boot: Loaded app from partition at offset 0x10000
I (381) boot: Disabling RNG early entropy source...
I (393) cpu_start: Pro cpu up.
I (393) cpu_start: Starting app cpu, entry point is 0x40081058
0x40081058: call_start_cpu1 at /home/jakob/esp/esp-idf/components/esp_system/port/cpu_start.c:150

I (0) cpu_start: App cpu up.
I (407) cpu_start: Pro cpu start user code
I (407) cpu_start: cpu freq: 240000000
I (407) cpu_start: Application information:
I (412) cpu_start: Project name:     snapclient
I (417) cpu_start: App version:      ec1a7f5-dirty
I (422) cpu_start: Compile time:     Dec  5 2022 19:00:15
I (429) cpu_start: ELF file SHA256:  76d602c9e1dc9a00...
I (435) cpu_start: ESP-IDF:          v4.3.4-dirty
I (440) heap_init: Initializing. RAM available for dynamic allocation:
I (447) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (453) heap_init: At 3FFBA120 len 00025EE0 (151 KiB): DRAM
I (459) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (466) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (472) heap_init: At 400937F8 len 0000C808 (50 KiB): IRAM
I (479) spi_flash: detected chip: gd
I (483) spi_flash: flash io: qio
W (486) spi_flash: Detected size(8192k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (500) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (560) SC: Start codec chip
I (570) ES8388_DRIVER: init,out:02, in:00
I (575) SC: Audio board_init done
I (576) AUDIO_HAL: Codec mode is 3, Ctrl:1
I (580) LYRAT_V4_3: I2S0, MCLK output by GPIO0
I (580) SC: init player
I (624) PLAYER: player_setup_i2s: dma_buf_len is 441, dma_buf_count is 4
I (624) c_I2S: already uninstalled
I (625) c_I2S: DMA Malloc info, datalen=blocksize=1764, dma_buf_count=4
I (645) c_I2S: APLL: Req RATE: 44100, real rate: 44099.988, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 11289597.000, SCLK: 1411199.625000, diva: 1, divb: 0
I (649) PLAYER: Start player_task
I (652) PLAYER: init player done
I (652) PLAYER: started sync task
I (658) wifi:wifi driver task: 3ffc4ad4, prio:23, stack:6656, core=0
I (666) system_api: Base MAC address is not set
I (671) system_api: read default base MAC address from EFUSE
I (690) wifi:wifi firmware version: 4ad6fcc
I (690) wifi:wifi certification version: v7.0
I (690) wifi:config NVS flash: enabled
I (691) wifi:config nano formating: disabled
I (695) wifi:Init data frame dynamic rx buffer num: 16
I (699) wifi:Init management frame dynamic rx buffer num: 16
I (705) wifi:Init management short buffer num: 32
I (709) wifi:Init dynamic tx buffer num: 32
I (713) wifi:Init static rx buffer size: 1600
I (717) wifi:Init static rx buffer num: 8
I (720) wifi:Init dynamic rx buffer num: 16
I (725) wifi_init: rx ba win: 16
I (728) wifi_init: tcpip mbox: 32
I (732) wifi_init: udp mbox: 6
I (736) wifi_init: tcp mbox: 6
I (739) wifi_init: tcp tx win: 65534
I (743) wifi_init: tcp rx win: 65534
I (748) wifi_init: tcp mss: 1460
I (751) wifi_init: WiFi IRAM OP enabled
I (756) wifi_init: WiFi RX IRAM OP enabled
I (763) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (849) wifi:mode : sta (e0:5a:1b:15:be:34)
I (849) wifi:enable tsf
I (850) WIFI: wifi_init_sta finished.
I (854) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (855) wifi:state: init -> auth (b0)
I (861) wifi:state: auth -> assoc (0)
I (868) wifi:state: assoc -> run (10)
I (881) wifi:connected with XXXXXXXX, aid = 2, channel 1, BW20, bssid = 44:d9:e7:92:b6:9c
I (881) wifi:security: WPA2-PSK, phy: bgn, rssi: -89
I (885) wifi:pm start, type: 1
W (895) wifi:<ba-add>idx:0 (ifx:0, 44:d9:e7:92:b6:9c), tid:0, ssn:0, winSize:64
I (904) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (2156) WIFI: Connected with IP Address:192.168.111.156
I (2156) esp_netif_handlers: sta ip: 192.168.111.156, mask: 255.255.255.0, gw: 192.168.111.1
I (2160) WIFI: connected to ap SSID: XXXXXXXX
I (2165) SC: Connected to AP
I (2168) NETF: Setup mdns
I (2183) SC: try connecting to static configuration 192.168.111.30:1704
E (2183) esp_ota_ops: Running firmware is factory
I (2186) OTA: idf.py build ; curl snapclient.local:8032 --data-binary @- < build/snapclient.bin
I (2199) SC: netconn connected
I (2201) SC: netconn sent hello message
I (2219) SC: Buffer length:  1000
I (2219) SC: Latency:        0
I (2219) SC: Mute:           0
I (2219) SC: Setting volume: 100
I (2235) SC: fLaC sampleformat: 44100:16:2
I (2260) PLAYER: snapserver config changed, buffer 1000ms, chunk 0ms, sample rate 0, ch 0, bits 0 mute 0 latency 0
I (4249) SC: latency buffer full
W (10434) PLAYER: pcm chunk queue not created
W (10451) PLAYER: pcm chunk queue not created
W (10461) PLAYER: pcm chunk queue not created
W (10467) PLAYER: pcm chunk queue not created
W (10486) PLAYER: pcm chunk queue not created
I (10492) PLAYER: player_setup_i2s: dma_buf_len is 573, dma_buf_count is 4
I (10493) c_I2S: DMA Malloc info, datalen=blocksize=2292, dma_buf_count=4
I (10511) c_I2S: APLL: Req RATE: 44100, real rate: 44099.988, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 11289597.000, SCLK: 1411199.625000, diva: 1, divb: 0
W (10515) PLAYER: pcm chunk queue not created
I (10528) c_I2S: APLL: Req RATE: 44100, real rate: 44099.988, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 11289597.000, SCLK: 1411199.625000, diva: 1, divb: 0
I (10533) PLAYER: created new queue with 39
I (10538) PLAYER: snapserver config changed, buffer 1000ms, chunk 26ms, sample rate 44100, ch 2, bits 16 mute 0 latency 0
E (11524) PLAYER: couldn't get memory to insert chunk
I (11525) PLAYER: 10448, 4096, 36, 9112, 4096
I (11535) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (11535) PLAYER: RESYNCING HARD 2: age 25284us, latency 592987098227us, free 28540, largest block 13824, 35, rssi: -79
I (11639) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (11639) PLAYER: RESYNCING HARD 2: age 25237us, latency 592987098227us, free 28548, largest block 13312, 35, rssi: -81
I (11743) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (11744) PLAYER: RESYNCING HARD 2: age 25232us, latency 592987098227us, free 33192, largest block 18432, 34, rssi: -81
E (11846) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (11848) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (11849) PLAYER: RESYNCING HARD 2: age 25706us, latency 592987098227us, free 28536, largest block 13824, 35, rssi: -80
E (11948) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (11952) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (11953) PLAYER: RESYNCING HARD 2: age 25246us, latency 592987098227us, free 28528, largest block 13824, 35, rssi: -81
E (12046) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (12057) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12057) PLAYER: RESYNCING HARD 2: age 25251us, latency 592987098227us, free 28480, largest block 13824, 35, rssi: -81
I (12161) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12162) PLAYER: RESYNCING HARD 2: age 25252us, latency 592987098227us, free 33136, largest block 18432, 34, rssi: -82
I (12266) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12266) PLAYER: RESYNCING HARD 2: age 25223us, latency 592987098227us, free 29944, largest block 15104, 34, rssi: -84
I (12370) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12371) PLAYER: RESYNCING HARD 2: age 25163us, latency 592987098169us, free 28480, largest block 9472, 35, rssi: -81
I (12475) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12475) PLAYER: RESYNCING HARD 2: age 25181us, latency 592987098169us, free 40264, largest block 15360, 31, rssi: -83
E (12568) PLAYER: couldn't get memory to insert chunk
I (12568) PLAYER: 9128, 4096, 36, 9112, 4096
I (12579) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12580) PLAYER: RESYNCING HARD 2: age 25174us, latency 592987098169us, free 28464, largest block 12544, 35, rssi: -74
I (12684) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12684) PLAYER: RESYNCING HARD 2: age 25298us, latency 592987098169us, free 32232, largest block 13824, 34, rssi: -75
E (12788) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (12788) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12791) PLAYER: RESYNCING HARD 2: age 27401us, latency 592987098169us, free 33156, largest block 18432, 34, rssi: -75
E (12906) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (12919) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (12919) PLAYER: RESYNCING HARD 2: age 25259us, latency 592987098169us, free 28556, largest block 13824, 35, rssi: -76
I (13024) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (13024) PLAYER: RESYNCING HARD 2: age 25322us, latency 592987098169us, free 30576, largest block 18432, 34, rssi: -76
E (13127) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (13128) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (13130) PLAYER: RESYNCING HARD 2: age 26810us, latency 592987098169us, free 33208, largest block 18432, 34, rssi: -74
E (13247) PLAYER: Failed to allocate IRAM memory for pcm chunk payload
I (13259) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (13259) PLAYER: RESYNCING HARD 2: age 25241us, latency 592987098169us, free 25360, largest block 10496, 35, rssi: -76
I (13363) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (13363) PLAYER: RESYNCING HARD 2: age 25270us, latency 592987098227us, free 33192, largest block 9216, 34, rssi: -74
I (13468) PLAYER: initial sync age: 2us, chunk duration: 26000us
W (13468) PLAYER: RESYNCING HARD 2: age 25251us, latency 592987098227us, free 28560, largest block 15360, 35, rssi: -77
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4000c2e0  PS      : 0x00060830  A0      : 0x800e8b78  A1      : 0x3ffc0040  
A2      : 0x3ffbdc98  A3      : 0x0000090c  A4      : 0x000008f4  A5      : 0x3ffbdc98  
A6      : 0x00000000  A7      : 0x0000008f  A8      : 0x00000000  A9      : 0x3ffbfff0  
A10     : 0x3ffb4040  A11     : 0x3ffbb3a4  A12     : 0x3ffbf80c  A13     : 0x00000000  
A14     : 0xfffffffd  A15     : 0x00000002  SAR     : 0x00000004  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x0000090c  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x0000008e  

Backtrace:0x4000c2dd:0x3ffc0040 0x400e8b75:0x3ffc0050 0x400de98a:0x3ffc0090
0x400e8b75: i2s_custom_write at /home/jakob/develop/git/snapclient-CarlosDerSeher/components/custom_driver/i2s.c:1149 (discriminator 15)

0x400de98a: player_task at /home/jakob/develop/git/snapclient-CarlosDerSeher/components/lightsnapcast/player.c:1189

ELF file SHA256: 76d602c9e1dc9a00

Rebooting...

Any idea what is going on here?

CarlosDerSeher commented 1 year ago

@gh7531 maximum supported buffer length is around 500ms if psram is disabled. You could enable psram from menuconfig which should work but I didn't test for a long time because my aim was always to get it to work without psram

velaar commented 1 year ago

(previously posted under the wrong issue)

Should we include a reference snapserver.conf somewhere? I'm not sure how well it is tuned to ESP32 but seems to work well for me:

chunk_ms = 24
codec = flac
sampleformat = 48000:16:2
buffer = 408

Update: Just tested on my setup - setting sampleformat to 44100:16:2 breaks sound as per OP.

CarlosDerSeher commented 1 year ago

@velaar I didn't see that sample rate was set to 44.1kHz. Probably we should change snapserver.conf located in snapclient/snapserver.conf. Maybe also the folder should be renamed and README.MD edited to make it more clear there is the reference config file for the server. I really want to merger NETCONN into master too but didn't find the time to do it yet.

@gh7531 Please use 48000:16:2 and flac (as suggested by @velaar) on snapserver for now as all other settings are either not implemented or hardly tested. At some point I will also look into different sample rate settings too but as I always like to state, I dind't have much use for it till now. Still I'd like to see a fully compatible snapclient at some point to be available on esp32 platform. Hopefully, as there are getting more people involved, this will be achievable soon :)

jhuber-de commented 1 year ago

Thank you both for your help.

The sample rate of 48000 does indeed work. My issue now is that I can't get my source for the snapcast server (in my case librespot) to output at this sample rate properly. But this is not related to your project.

Thank you for your time working on this project

CarlosDerSeher commented 1 year ago

checkout https://github.com/badaix/snapcast/blob/master/doc/configuration.md and jump to the Alsa section. I guess you'll find your solution there

velaar commented 1 year ago

checkout https://github.com/badaix/snapcast/blob/master/doc/configuration.md and jump to the Alsa section. I guess you'll find your solution there

Sadly no solution there. They suggest to use snd-aloop but it doesn't do any resampling. I tried to resample it with this;

pcm.!snapcast {
    type plug
    slave.pcm hw:1,1,0
    slave {
        pcm rate48000Hz # Direct default output to the below converter
    }
}

pcm.rate48000Hz {
     type rate
     slave {
          pcm writeFile # Direct to the plugin which will write to a file
          format S16_LE
          rate 48000
     }
}

pcm.writeFile {
    type file
    slave.pcm null
    file "/tmp/snapfifo48"
    format "raw"
}

But shairport-sync refuses to play into snapcast output, It might help @gh7531 though.

Ideally would love to learn how to resample a pipe into a pipe on Linux but that is definitely not related to project. Fixing 44100 on ESP32 might be nice at some point as well. Sadly, I'm far from your level of programming so can only offer testing. Presently running the latest pull request on my hardware.

CarlosDerSeher commented 1 year ago

Maybe this can be of help? https://github.com/badaix/snapcast/blob/master/doc/player_setup.md Also see the alsa section

Maybe you can playback to the loopback device and use snapcast process to start arecord with 48khz from the loopback device. I did such a thing in the past successfully although I believe I started arecord manually und piped its output into snapfifo

CarlosDerSeher commented 1 year ago

Ideally would love to learn how to resample a pipe into a pipe on Linux but that is definitely not related to project.

Probably cpiped from the line in example in combination with the alsa example can achieve what you want? Let shairport do its playback at 44.1khz and capture with cpiped at 48khz from the loopback device.

I will definitly try to fix the samplerate problem at some point but at the moment i am designing a custom PCB which will run snapclient so i can spread it around the house. Time is scarce with a two year old at home so this can take a while :)

Great to have someone else to test and find my errors.

CarlosDerSeher commented 1 year ago

Ok, just tested with sample rate 44.1kHz and found there is a problem with chunk duration detection in http_get_task() around line 1387. size_t decodedSize = pcmData->totalSize; // pFlacData->bytes; scSet.chkDur_ms = (1000UL * decodedSize) / (uint32_t)(scSet.ch * (scSet.bits / 8)) / scSet.sr; decodedSize results in 4608 bytes which are 1152 frames using 44100:16:2 setting. When calculating scSet.chkDur_ms this results in a fractional number (26.122ms) while scSet.chkDur_ms is an uint32_t from there on all other calculations using scSet.chkDur_ms will be wrong and we will get memory allocation/access errors at some point.

I am currently not sure how to handle that though.

CarlosDerSeher commented 1 year ago

found that dsp_processor() causes kernel panic with sample rate set to 44.1kHz and if disabled "only" syncing isn't working because of above reason.

luar123 commented 1 year ago

found that dsp_processor() causes kernel panic with sample rate set to 44.1kHz and if disabled "only" syncing isn't working because of above reason.

I did not test, but stereo flow should work even with soft volume enabled. The other flows use the buffer that is created with dsp_setup_flow(500, scSet->sr, scSet->chkDur_ms), so probably the buffer is too small.

Could you simply change scSet.chkDur_ms to float and use ceil() for memory allocation?

CarlosDerSeher commented 1 year ago

I'll try when I got time. Maybe it's as easy as that :)