CarlosDerSeher / snapclient

snapclient on ESP32
GNU General Public License v3.0
125 stars 16 forks source link

TAS5805M Driver #52

Closed DerPicknicker closed 8 months ago

DerPicknicker commented 9 months ago

Hi,

as discussed. Here are my changes. It contains:

Currently not tested. Please take a look @CarlosDerSeher :)

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ,

I made hopefully all changes as discussed. Please have a look 👀

Edit: Some changes aren't uploaded. Sorry. I have to made them again. Give me some time.

DerPicknicker commented 9 months ago

@CarlosDerSeher ..

Could you help me again. I made the changes which you requested. The Build-Process is working fine (No errors at all) but I cannot see in the Output if my changes are included in the Build-Process. How can I check that?

EDIT: To be more precise: I think the Files aren´t used at all.

CarlosDerSeher commented 9 months ago

I see, you have to add everything to cmake https://github.com/CarlosDerSeher/snapclient/blob/master/components/custom_board/CMakeLists.txt

DerPicknicker commented 9 months ago

I see, you have to add everything to cmake https://github.com/CarlosDerSeher/snapclient/blob/master/components/custom_board/CMakeLists.txt

I will do that... And do my commits again with the provided fixes. Big thanks for the support you give me to get this running...

DerPicknicker commented 9 months ago

Current Status of 55745c1

If you have the time link me into the right direction what the problems are:

/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0x4): undefined reference to `tas5805m_deinit'
/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0x8): undefined reference to `tas5805m_ctrl'
/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0xc): undefined reference to `tas5805m_conig_iface'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
CarlosDerSeher commented 9 months ago

You get these errors because you just declare these functions as prototypes but never define their bodies, just define them returning ESP_OK https://github.com/CarlosDerSeher/snapclient/blob/d3e20fe0eb4d8d562d97a02f43cbccb79e9c8505/components/custom_board/adau1961/adau1961.c#L611

DerPicknicker commented 9 months ago

Hi again,

I was so blind. Thank you for pointing to this. Sadly this doesn't fixes the issue at all.

esp_err_t tas5805m_deinit(void) {
  // TODO
  return ESP_OK;
}

esp_err_t tas5805m_ctrl(audio_hal_codec_mode_t mode,
                        audio_hal_ctrl_t ctrl_state) {
  // TODO
  return ESP_OK;
}

esp_err_t tas5805m_config_iface(audio_hal_codec_mode_t mode,
                                audio_hal_codec_i2s_iface_t *iface) {
  // TODO
  return ESP_OK;
}

Here you see the Issue stays the Same:

/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0x4): undefined reference to `tas5805m_deinit'
/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0x8): undefined reference to `tas5805m_ctrl'
/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0xc): undefined reference to `tas5805m_conig_iface'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

I tested both: tas5805m_conig_iface and tas5805m_config_iface issue is the same. I added them also to the header file and removed them from the .C File but this doesn't help at all. Oh man, this is why I don't use C and the IDF stuff more often than required ;-)

Edit: Could you clone my changes and try to build it on your side. To see if my docker setup or other circumstances are not the problem.

CarlosDerSeher commented 9 months ago

Ok, I think I found your problem, if you look at the compiler error

/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/audio_hal/libaudio_hal.a(tas5805m.c.obj):(.data.AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE+0x4): undefined reference to `tas5805m_deinit'

You did some changes in audio_hal component which you definitely shouldn't touch. Please revert these changes and it most certainly will compile fine. At least CMakeLists.txt in audio_hal was changed: https://github.com/DerPicknicker/snapclient/blob/3e240bad8a89e4bebb8ec5d1f5398b7476fd1e26/components/audio_hal/CMakeLists.txt#L8C15-L8C15

Also you did add your driver in the driver folder of audio_hal. Please remove all this. You shouldn't touch audio_hal in any way

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ,

thank you very much for looking into it. So I will restore audio_hal to the default ones (from your current master) and it should work right?

Is there a "simple" way to use the IDF menuconfig to use it in the Init-Functions of the dac? I want to check if a bool is selected.

CarlosDerSeher commented 9 months ago

Yes and yes.

Just use the name of the menuconfig entry and prepend it with CONFIG_

look at sdkconfig.h to see all menuconfig defines

DerPicknicker commented 9 months ago

I think we did a lot of work which is not needed 🤯

See here https://github.com/CarlosDerSeher/snapclient/blob/master/components/audio_hal/driver/tas5805m/tas5805m.c

Espressif already published a driver for TAS5805M so it should be already available...😅 Is that already included in the project or its not available because you removed the ADF dependencies?

CarlosDerSeher commented 9 months ago

Oh well... that is really unfortunate.

Yes when I started development for this project I removed a lot of stuff related to ADF, just left lyrat because this was my development platform at the time.

Sorry about that, I didn't realize this driver was already available either, maybe just re-add it and look at lyrat to see how to make it compatible

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ,

I will see how it goes. First I will made my current branch compiling. And second I will see what's the best option. I think the Espressif Code has one problem, it doesn't support the "bridge" mode. But I have to verify it.

What is your preferred choice add a custom board as the lyrat or Add this as a driver.

CarlosDerSeher commented 9 months ago

Personally I think a driver provides more flexibility. Maybe just add it as a driver because you already wrote the code and at some point we could readd the espressif board again too.

DerPicknicker commented 9 months ago

Okay .. Restoring the folder makes the code compiling. I will fix some issues this weekend and update here.

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ...

I did some changes and now the Code is compiling. I flashed it to the Device and the device is connecting to the Wifi and Snapserver is recognising the Board. But the I2C communication is not working. The log tells me just: I2C Driver is not installed. Could you check or give me a hint why this happens?

EDIT: I am testing currently the Driver of espressif in the meantime. Let's see if this works.

CarlosDerSeher commented 9 months ago

You forgot to init the GPIOs needed for i2c

DerPicknicker commented 9 months ago

You forgot to init the GPIOs needed for i2c

Oh well. Stupid mistake. I will fix it... Let's see if music works after fixing it.

DerPicknicker commented 9 months ago

Would you help me with that?

For me this code looks fine.

esp_err_t tas5805m_write_byte(uint8_t register_name, uint8_t value)
{
  esp_err_t ret;
  int i2c_master_port = 0;

    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = CONFIG_DAC_I2C_SDA,
        .scl_io_num = CONFIG_DAC_I2C_SCL,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master.clk_speed = I2C_MASTER_FREQ_HZ,
    };

  i2c_param_config(i2c_master_port, &conf);

  if(i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0) != ESP_OK){
    ESP_LOGW(TAG, "INIT i2C FAILED");
  }
  i2c_cmd_handle_t cmd = i2c_cmd_link_create();
  i2c_master_start(cmd);
  i2c_master_write_byte(cmd, TAS5805M_ADDRESS << 1 | WRITE_BIT, ACK_CHECK_EN);
  i2c_master_write_byte(cmd, register_name, ACK_CHECK_EN);
  i2c_master_write_byte(cmd, value, ACK_CHECK_EN);
  i2c_master_stop(cmd);
  ret = i2c_master_cmd_begin(I2C_TAS5805M_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
  i2c_cmd_link_delete(cmd);

  return ret;
}

I don't know why the install_driver call is not successful. If you have the time. Could you send me an example how to init the I2c. I used the Example from here: https://github.com/espressif/esp-idf/blob/master/examples/peripherals/i2c/i2c_simple/main/i2c_simple_main.c

but for me it looks the same. Would be great if you can support me here :)

CarlosDerSeher commented 9 months ago

Please se the other i2s drivers as a reference ma120 does it similar than you want to.

You may call the install function only once so write_byte isn't a good spot to call it.

DerPicknicker commented 9 months ago

Please se the other i2s drivers as a reference ma120 does it similar than you want to.

You may call the install function only once so write_byte isn't a good spot to call it. Okay I will check. Where is a good spot? In the init function?

CarlosDerSeher commented 9 months ago

Okay I will check. Where is a good spot? In the init function?

As already wrote, please see ma120 it is all there. Init function it should be.

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ..

in the meantime I fix the i2c issue. Thank you for pointing me into the right direction. I will comeback to you asap. But I think I have to talk to the board designer first. Which Pins are used in his code (the init function is mainly based on his first implementation). I already heard sound but it was really distorted and at 100% it was REALLY LOUD. So I think the issue is currently the not clear pin-mapping.

BTW: Here is the Log does it look Okay? I can't see any information about PSRAM (this board offers psram) could you explain if there is any log output about PSRAM?

entry 0x400806a0
I (29) boot: ESP-IDF v4.3.5 2nd stage bootloader
I (29) boot: compile time 13:11:25
I (29) boot: chip revision: v3.1
I (32) qio_mode: Enabling default flash chip QIO
I (37) boot.esp32: SPI Speed      : 80MHz
I (42) boot.esp32: SPI Mode       : QIO
I (47) boot.esp32: SPI Flash Size : 4MB
I (51) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (68) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (75) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (82) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (90) boot:  3 factory          factory app      00 00 00010000 00120000
I (97) boot:  4 ota_0            OTA app          00 10 00130000 00120000
I (105) boot:  5 ota_1            OTA app          00 11 00250000 00120000
I (112) boot:  6 storage          Unknown data     01 82 00370000 00090000
I (120) boot: End of partition table
I (124) boot: Defaulting to factory image
I (129) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=23928h (145704) map
I (178) esp_image: segment 1: paddr=00033950 vaddr=3ffb0000 size=03880h ( 14464) load
I (182) esp_image: segment 2: paddr=000371d8 vaddr=40080000 size=08e40h ( 36416) load
I (195) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=b9bc8h (760776) map
I (405) esp_image: segment 4: paddr=000f9bf0 vaddr=40088e40 size=0b6d4h ( 46804) load
I (431) boot: Loaded app from partition at offset 0x10000
I (431) boot: Disabling RNG early entropy source...
I (442) psram: This chip is ESP32-D0WD
I (442) spiram: Found 64MBit SPI RAM device
I (442) spiram: SPI RAM mode: flash 80m sram 40m
I (445) spiram: PSRAM initialized, cache is in low/high (2-core) mode.
I (453) cpu_start: Pro cpu up.
I (456) cpu_start: Starting app cpu, entry point is 0x40081210
0x40081210: call_start_cpu1 at /opt/esp/idf/components/esp_system/port/cpu_start.c:150

I (0) cpu_start: App cpu up.
I (1328) spiram: SPI SRAM memory test OK
I (1336) cpu_start: Pro cpu start user code
I (1336) cpu_start: cpu freq: 240000000
I (1336) cpu_start: Application information:
I (1339) cpu_start: Project name:     snapclient
I (1344) cpu_start: App version:      5495ad5-dirty
I (1350) cpu_start: Compile time:     Dec 17 2023 13:10:40
I (1356) cpu_start: ELF file SHA256:  63abb3e6e6462e8f...
I (1362) cpu_start: ESP-IDF:          v4.3.5
I (1367) cpu_start: Min chip rev:     v0.0
I (1372) cpu_start: Max chip rev:     v3.99 
I (1376) cpu_start: Chip rev:         v3.1
I (1381) heap_init: Initializing. RAM available for dynamic allocation:
I (1389) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (1395) heap_init: At 3FFB9B30 len 000264D0 (153 KiB): DRAM
I (1401) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (1407) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1414) heap_init: At 40094514 len 0000BAEC (46 KiB): IRAM
I (1420) spiram: Adding pool of 4096K of external SPI memory to heap allocator
I (1429) spi_flash: detected chip: generic
I (1433) spi_flash: flash io: qio
I (1438) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (1453) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (1488) c_I2S: already uninstalled
I (1489) c_I2S: DMA Malloc info, datalen=blocksize=512, dma_buf_count=2
I (1491) 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 (1503) GENERIC_BOARD: I2S0, MCLK output by GPIO0
I (1508) SC: Start codec chip
I (1512) HAL: INIT
Driver param setup : 0
Driver installed   : 0
I (2219) HAL: codec_hal done
I (2219) AUDIO_BOARD: board-handle done
I (2219) SC: Audio board_init done
I (2220) AUDIO_HAL: Codec mode is 3, Ctrl:1
I (2225) SC: init player
I (2233) PLAYER: player_setup_i2s: dma_buf_len is 576, dma_buf_count is 4
I (2236) c_I2S: DMA Malloc info, datalen=blocksize=2304, dma_buf_count=4
I (2244) c_I2S: APLL: Req RATE: 48000, real rate: 47999.961, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 12287990.000, SCLK: 1535998.750000, diva: 1, divb: 0
I (2257) GENERIC_BOARD: I2S0, MCLK output by GPIO0
I (2262) PLAYER: Start player_task
I (2266) PLAYER: init player done
I (2266) PLAYER: started sync task
I (2273) wifi:wifi driver task: 3ffca558, prio:23, stack:6656, core=0
I (2281) system_api: Base MAC address is not set
I (2286) system_api: read default base MAC address from EFUSE
I (2300) wifi:wifi firmware version: 9ec65ef
I (2300) wifi:wifi certification version: v7.0
I (2300) wifi:config NVS flash: enabled
I (2304) wifi:config nano formating: disabled
I (2308) wifi:Init data frame dynamic rx buffer num: 64
I (2313) wifi:Init management frame dynamic rx buffer num: 64
I (2318) wifi:Init management short buffer num: 32
I (2323) wifi:Init static tx buffer num: 8
I (2327) wifi:Init tx cache buffer num: 32
I (2331) wifi:Init static rx buffer size: 1600
I (2335) wifi:Init static rx buffer num: 8
I (2339) wifi:Init dynamic rx buffer num: 64
I (2343) wifi_init: rx ba win: 16
I (2347) wifi_init: tcpip mbox: 32
I (2351) wifi_init: udp mbox: 6
I (2354) wifi_init: tcp mbox: 10
I (2358) wifi_init: tcp tx win: 11680
I (2363) wifi_init: tcp rx win: 11680
I (2367) wifi_init: tcp mss: 1460
I (2371) wifi_init: WiFi RX IRAM OP enabled
I (2378) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (2466) wifi:mode : sta (a0:a3:b3:26:77:6c)
I (2466) wifi:enable tsf
I (2468) WIFI: wifi_init_sta finished.
I (2474) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
I (2475) wifi:state: init -> auth (b0)
I (2489) wifi:state: auth -> assoc (0)
I (2500) wifi:state: assoc -> run (10)
I (2569) wifi:connected with FRITZ!Box 7590, aid = 2, channel 11, BW20, bssid = 44:4e:6d:20:fa:5b
I (2570) wifi:security: WPA2-PSK, phy: bgn, rssi: -66
I (2575) wifi:pm start, type: 1

I (2586) wifi:<ba-add>idx:0 (ifx:0, 44:4e:6d:20:fa:5b), tid:6, ssn:2, winSize:64
I (2639) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (3577) WIFI: Connected with IP Address:192.168.178.187
I (3577) esp_netif_handlers: sta ip: 192.168.178.187, mask: 255.255.255.0, gw: 192.168.178.1
I (3581) WIFI: connected to ap SSID: FRITZ!Box 7590
I (3586) SC: Connected to AP
I (3590) HTTP: Initializing SPIFFS
I (3637) HTTP: Partition size: total: 534881, used: 50200
I (3637) HTTP: Mount /html to storage success
I (3638) HTTP: d_name=/html/favicon.ico d_ino=0 d_type=1
I (3643) HTTP: d_name=/html/index.html d_ino=0 d_type=1
I (3649) HTTP: d_name=/html/ESP-LOGO.txt d_ino=0 d_type=1
I (3672) NETF: Setup mdns
I (3672) HTTP: Start http task=192.168.178.187
I (3673) HTTP: Starting server on 192.168.178.187:8000
I (3676) HTTP: Starting HTTP Server on port: '8000'
I (3685) SC: try connecting to static configuration 192.168.178.188:1704
E (3694) esp_ota_ops: Running firmware is factory
I (3696) OTA: idf.py build ; curl snapclient.local:8032 --data-binary @- < build/snapclient.bin
I (3703) wifi:<ba-add>idx:1 (ifx:0, 44:4e:6d:20:fa:5b), tid:0, ssn:0, winSize:64
I (3713) SC: netconn connected
I (3718) SC: netconn sent hello message
I (3728) SC: Buffer length:  1000
I (3728) SC: Latency:        0
I (3729) SC: Mute:           0
I (3732) SC: Setting volume: 0
I (3737) SC: fLaC sampleformat: 48000:16:2
I (3930) SC: latency buffer full
W (10988) PLAYER: pcm chunk queue not created
W (10991) PLAYER: pcm chunk queue not created
W (10992) PLAYER: pcm chunk queue not created
W (11007) PLAYER: pcm chunk queue not created
W (11017) PLAYER: pcm chunk queue not created
W (11044) PLAYER: pcm chunk queue not created
W (11063) PLAYER: pcm chunk queue not created
I (11090) PLAYER: player_setup_i2s: dma_buf_len is 576, dma_buf_count is 4
I (11090) c_I2S: DMA Malloc info, datalen=blocksize=2304, dma_buf_count=4
I (11095) c_I2S: APLL: Req RATE: 48000, real rate: 47999.961, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 12287990.000, SCLK: 1535998.750000, diva: 1, divb: 0
I (11108) GENERIC_BOARD: I2S0, MCLK output by GPIO0
I (11115) c_I2S: APLL: Req RATE: 48000, real rate: 47999.961, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 12287990.000, SCLK: 1535998.750000, diva: 1, divb: 0
W (11127) PLAYER: no pcm chunk queue created?
I (11132) PLAYER: created new queue with 40
I (11137) PLAYER: snapserver config changed, buffer 1000ms, chunk 1152 frames, sample rate 48000, ch 2, bits 16 mute 0 latency 0
I (12053) PLAYER: initial sync age: 2us, chunk duration: 24000us
W (28227) PLAYER: get_diff_to_server: can't take semaphore. Old diff retrieved
W (28227) PLAYER: server_now: can't get current diff to server. Retrieved old one
I (48868) SC: Buffer length:  1000
I (48868) SC: Latency:        0
I (48868) SC: Mute:           0
I (48869) SC: Setting volume: 14
I (48877) SC: Buffer length:  1000
I (48877) SC: Latency:        0
I (48880) SC: Mute:           0
I (48884) SC: Setting volume: 14
I (48893) SC: Buffer length:  1000
I (48893) SC: Latency:        0
I (48896) SC: Mute:           0
I (48900) SC: Setting volume: 7
I (48905) SC: Buffer length:  1000
I (48908) SC: Latency:        0
I (48912) SC: Mute:           0
I (48915) SC: Setting volume: 4
I (48945) SC: Buffer length:  1000
I (48945) SC: Latency:        0
I (48945) SC: Mute:           0
I (48946) SC: Setting volume: 1
I (48950) SC: Buffer length:  1000
I (48954) SC: Latency:        0
I (48957) SC: Mute:           0
I (48961) SC: Setting volume: 0
I (49688) SC: Buffer length:  1000
I (49688) SC: Latency:        0
I (49688) SC: Mute:           0
I (49689) SC: Setting volume: 4
I (49694) SC: Buffer length:  1000
I (49697) SC: Latency:        0
I (49700) SC: Mute:           0
I (49704) SC: Setting volume: 5
I (49709) SC: Buffer length:  1000
I (49712) SC: Latency:        0
I (49716) SC: Mute:           0
I (49720) SC: Setting volume: 6
I (49725) SC: Buffer length:  1000
I (49728) SC: Latency:        0
I (49732) SC: Mute:           0
I (49735) SC: Setting volume: 6
I (49740) SC: Buffer length:  1000
I (49743) SC: Latency:        0
I (49747) SC: Mute:           0
I (49751) SC: Setting volume: 7
I (49756) SC: Buffer length:  1000
I (49759) SC: Latency:        0
I (49763) SC: Mute:           0
I (49766) SC: Setting volume: 8
I (49771) SC: Buffer length:  1000
I (49774) SC: Latency:        0
I (49778) SC: Mute:           0
I (49782) SC: Setting volume: 9
I (49807) SC: Buffer length:  1000
I (49807) SC: Latency:        0
I (49807) SC: Mute:           0
I (49808) SC: Setting volume: 10
I (49840) SC: Buffer length:  1000
I (49840) SC: Latency:        0
I (49840) SC: Mute:           0
I (49841) SC: Setting volume: 11
I (50161) SC: Buffer length:  1000
I (50161) SC: Latency:        0
I (50161) SC: Mute:           0
I (50162) SC: Setting volume: 12
I (50226) SC: Buffer length:  1000
I (50226) SC: Latency:        0
I (50226) SC: Mute:           0
I (50227) SC: Setting volume: 13
I (50351) SC: Buffer length:  1000
I (50352) SC: Latency:        0
I (50352) SC: Mute:           0
I (50352) SC: Setting volume: 14
I (50412) SC: Buffer length:  1000
I (50412) SC: Latency:        0
I (50412) SC: Mute:           0
I (50413) SC: Setting volume: 15
I (50442) SC: Buffer length:  1000
I (50442) SC: Latency:        0
I (50442) SC: Mute:           0
I (50443) SC: Setting volume: 16
I (50473) SC: Buffer length:  1000
I (50473) SC: Latency:        0
I (50473) SC: Mute:           0
I (50474) SC: Setting volume: 17
I (50525) SC: Buffer length:  1000
I (50525) SC: Latency:        0
I (50525) SC: Mute:           0
I (50526) SC: Setting volume: 18
I (50576) SC: Buffer length:  1000
I (50576) SC: Latency:        0
I (50576) SC: Mute:           0
I (50577) SC: Setting volume: 19
I (50644) SC: Buffer length:  1000
I (50644) SC: Latency:        0
I (50644) SC: Mute:           0
I (50645) SC: Setting volume: 20
I (50697) SC: Buffer length:  1000
I (50697) SC: Latency:        0
I (50697) SC: Mute:           0
I (50697) SC: Setting volume: 21
I (50779) SC: Buffer length:  1000
I (50780) SC: Latency:        0
I (50780) SC: Mute:           0
I (50780) SC: Setting volume: 22
W (55660) PLAYER: RESYNCING HARD 2: age 2us, latency 940382362423us, free 4325138, largest block 4128768, 0, rssi: -71
I (56624) PLAYER: initial sync age: 2us, chunk duration: 24000us
W (58974) PLAYER: RESYNCING HARD 2: age -88311us, latency 940382362403us, free 4167050, largest block 3997696, 34, rssi: -72
I (59136) PLAYER: initial sync age: 2us, chunk duration: 24000us
CarlosDerSeher commented 9 months ago

Look for

I (442) spiram: Found 64MBit SPI RAM device

And the log is OK if you changed volume a lot at the end.

DerPicknicker commented 9 months ago

Look for

I (442) spiram: Found 64MBit SPI RAM device

And the log is OK if you changed olime a lot at the end.

Yes I did it. I was blind reading the logs. Sorry for that. I will do my homework and comeback if I have some results

DerPicknicker commented 9 months ago

@CarlosDerSeher ..

Hi,

which I2S mode you're using in the code? Is there a way to change it?

CarlosDerSeher commented 9 months ago

Do you really need to? It will currently not integrate so well. It is possible though, just not in a really clean way

https://github.com/CarlosDerSeher/snapclient/blob/master/components%2Flightsnapcast%2Fplayer.c#L166

From what I can see in the datasheet I2S should be supported

DerPicknicker commented 9 months ago

Hey,

in the sample code of the Board designer he uses Philips mode. I found out that a pin configuration was wrong. I will test it today again. Could you check the volume - set function if it looks okay?

CarlosDerSeher commented 9 months ago

No, your get volume doesn't seem right. You don't pass a pointer so the user will never be able to actually get the volume. Also you have some wrong usage of VolumeLevel there, shouldn't it be passed by reference to the i2c function?

Also I am not sure what's the if in set volume actually for if you do the same call in if and else

https://github.com/DerPicknicker/snapclient/blob/master-tas5805m/components%2Fcustom_board%2Ftas5805m%2Ftas5805m.c#L182

DerPicknicker commented 9 months ago

Good catch!

There is a bug. Is the volume range from 0-100 or from 0-255? ...

The TAS5805M is muted if the volume is set to 255. I will try to make the changes in the getVolume as well.

CarlosDerSeher commented 9 months ago

Volume should be from 0 to 100 in percent

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ..

I worked the whole afternoon + evening to get this thing working. The Board-Designer gave me the hint that the Pin-Numbering in his Code was wrong. So after changing the Pins, adapting the Volume Functions (which you mentioned above) I can now use this Board.

I have only two issues remaining:

Not directly related to this driver:

E (167619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (169619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (171619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (173619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (175619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (177619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (179619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (181619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (183619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms
E (185619) PLAYER: Couldn't get PCM chunk, recv: messages waiting 0, diff2Server: 1122003s, 220.955ms

If a stream ends (only playing one song) I got spammed with this output above. Where does this happen? I think if this happen more than 10x we should remove the queue or not?

CarlosDerSeher commented 9 months ago

If a stream ends (only playing one song) I got spammed with this output above. Where does this happen? I think if this happen more than 10x we should remove the queue or not?

This is intended behavior but will be resolved in the near future. There is a power save pull request in the pipe which will kill player task if there is no music playing. See #49

DerPicknicker commented 9 months ago

That sounds great. I will do some refactoring of the code and implement the mute function.

If you have the time I would appreciate it if you can check why the volume is inverted. I will also check with the board designer how the volume must be set.

CarlosDerSeher commented 9 months ago

Have another look at the datasheet and the volume ctrl register. Your min and max values are inverted.

Also is there a reason why you don't use analog gain for volume control instead of digital gain?

DerPicknicker commented 9 months ago

Have another look at the datasheet and the volume ctrl register. Your min and max values are inverted.

Oh well. I just used the implementation of the board designer. Next time I will trust only myself ;-)

Also is there a reason why you don't use analog gain for volume control instead of digital gain?

Yes, the board designer said that the gain function is not that good. Because it has less range.

CarlosDerSeher commented 9 months ago

Ok so you set AGain to max and from there on use dig gain? Maybe you need to do some measurements to ensure there is no clipping/saturation. You could use a sine wave with amplitude of int16_t_max to ensure you get the maximum dynamic range

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ,

I GOT IT WORKING. The Volume Control is working fine. I made some changes and inverting the min / max values fixes my issues.

There is one Question left:

And should integrate a Volume-Limit-Function? I think it would be great if we can limit inside the Menuconfig the Volume to 80% but reported as 100%. This board I am currently using has so much power and even with 23W at 70%+ its way to loud.

EDIT: Is there a way that I can share the SDK-Config for this Board so a beginner can easily use this?

CarlosDerSeher commented 9 months ago

You could maybe make analog gain configurable through menuconfig for example?

Is there a way that I can share the SDK-Config for this Board so a beginner can easily use this?

I'd just add a file called sdkconfig_board_name and/or sdkconfig_driver_name

CarlosDerSeher commented 9 months ago
esp_err_t
tas5805m_set_mute(bool enable)
{

  if (enable == true)
  {
    return tas5805m_write_byte(TAS5805M_DIG_VOL_CTRL_REGISTER, TAS5805M_VOLUME_MUTE);
  }
  return ESP_OK;
}

Take another look. There is no way you can unmute with this function ;)

CarlosDerSeher commented 9 months ago

I GOT IT WORKING

Oh and congratulations!

esp_err_t
tas5805m_set_mute(bool enable)
{

  if (enable == true)
  {
    return tas5805m_write_byte(TAS5805M_DIG_VOL_CTRL_REGISTER, TAS5805M_VOLUME_MUTE);
  }
  return ESP_OK;
}

Take another look. There is no way you can unmute with this function ;)

And one more thing, you still need to clean up your git tree and remove those unnecessary files/changes from your git cache. Or just start over and create a new branch and pull request and copy your changes there

DerPicknicker commented 9 months ago

And one more thing, you still need to clean up your git tree and remove those unnecessary files/changes from your git cache. Or just start over and create a new branch and pull request and copy your changes there

I will create a new pull request with a new branch but I think it won’t be before Christmas.

CarlosDerSeher commented 9 months ago

No hurries. I've got the flu for an early present so I'll probably won't be in the state to check your work.

Happy holidays and merry Christmas

DerPicknicker commented 9 months ago

Hi @CarlosDerSeher ,

all the best for you. Get well soon :) ..

I worked on another branch and updated the Mute-Function - let's use this PR for the Discussion and I will create a new one with a single commit that it easier to merge. I updated the Readme as well ;-) Here is the Function:

esp_err_t
tas5805m_set_mute(bool enable)
{

  if (enable == true)
  {
    return tas5805m_write_byte(TAS5805M_DIG_VOL_CTRL_REGISTER, TAS5805M_VOLUME_MUTE);
  }
  else{
    int vol; 
    tas5805m_get_volume(&vol);
    return tas5805m_write_byte(TAS5805M_DIG_VOL_CTRL_REGISTER, vol);
  }
  return ESP_OK;
}

The Problem is that if I unmute the Volume is noticeable louder than before the Muting starts. So I assume that the Volume is getting lost somewhere. I tried as you can see to get the last volume and write it to the register but this seems not the right way.

In the new Branch , I updated the SetVolume Function as well. Now you can limit the max Volume inside the MenuConfig but here I encountered a different problem if I limit the Volume Range to big (80-200) I loose resolution and the Volume steps are much bigger than before. So would you be so kind (ONLY IF YOURE HEALTHY) and explain to me what your Idea was with the sine_16? => https://github.com/CarlosDerSeher/snapclient/pull/52#issuecomment-1863854183

This Code has another Bug which belongs to the Limiting the max volume, if I press pause and again play the Volume is set to a much bigger value than before (almost every time to 51%).

Thank you for being so patient with me. I will try to create a small guide next year how to implement a new Board / Driver.

Some Questions not belonging to the PR:

Thank you for reading this long post and merry Christmas to you.

CarlosDerSeher commented 9 months ago

The Problem is that if I unmute the Volume is noticeable louder than before the Muting starts.

When muting you need to store the current volume in a global variable. So you can restore it later.

I'll try to answer your other questions as soon as I can

DerPicknicker commented 9 months ago

@CarlosDerSeher ..

Take your time. Regarding the volume I think there must be a different way. The Log knows the last volume and only updates the mute state. I can implement a global variable but is there not a nicer way? (If the serial output knows it than I miss something...)

CarlosDerSeher commented 9 months ago

What do you mean the log knows the volume? If I understand you correctly you want to have access to the snapcast state variable which holds the volume. This is a thing I would strictly avoid as this makes things kind of complicated because you need to somehow pass this variable down to the driver. You'll need a mutex for accessing it and so on.

Just put a variable in your driver's module which remembers this:

static uint8_t _currentVolume = 0;

This way the code will also stay independent of the rest and could be used by any other project easily.

CarlosDerSeher commented 9 months ago

Is it possible to run two instances of SnapClient on a single ESP32? For example this Board offers 2 Chanels would be a Cool Feature if each Chanel represents one Snapclient

No and not planned by me. You could try duplicate the tasks but I am not sure if it will work, You'll double bandwidth, RAM, and CPU usage.

I played around with this Code and enabled the DSP Functions but I can't really configure a cross-over Frequency (Bi-Amping Flow) and also in the EQ-Part it would be great if you can set a crossover value this would allow to build wireless subwoofers and 2.1 systems. Is there anything in the Pipe that will addresses this things?

No at least not by me. I don't really use the DSP functions, but there is an issue regarding DSP #48, maybe ask there.

I think these question above should be in a separate discussion, could you create one like FAQ? For just chatting and asking some Questions about this Software (I have a bunch of them......)

Maybe open a Discussion with your questions inside and I'll try answer them. You could then collect everything and put it into the documentation by pull request maybe?

I loose resolution and the Volume steps are much bigger than before. So would you be so kind (ONLY IF YOURE HEALTHY) and explain to me what your Idea was with the sine_16?

Don't limit the range of digital gain but use analog gain for that. By using a sine wave @1khz with amplitude 1 ( INT16_MAX) for example as a input you could check with an oscilloscope if there is any saturation at high gain levels. You could generate the sine wave by looping through a lookup table and playing these samples by i2s.

DerPicknicker commented 9 months ago

What do you mean the log knows the volume? If I understand you correctly you want to have access to the snapcast state variable which holds the volume. This is a thing I would strictly avoid as this makes things kind of complicated because you need to somehow pass this variable down to the driver. You'll need a mutex for accessing it and so on.

Yeah you got me right. Okay if you want to stay independent I will follow your advice. I will create a new discussion and reply there to your responses. And in the new pull requests I will link all the questions which you answered me.

Thank you for your time. If you already have some passive speaker this board is really great it cost only 21$ with an 2x23W amp on it. This is really Cool if you want to make your old speakers smart.

DerPicknicker commented 8 months ago

Close here For now. I will create a new one. Today it's planed to finalise it and push the changes .