Play audio from temporary memory with nrf5340_audio LE code

Hello,

I am using an LE audio code "nrf5340_audio" code from nRF SDK v2.8.0 to play a beep tone. I want to play a tone from a temporary memory, so I have created a logic for the same and converted a beep.wav file (16bit-mono@48khz) to a beep.h file.

I have also created a new file named as temp_mem_plaback.c inside src/modules and included the beep.h file inside it.

Then inside unicast_server -> main.c, I have defined a separate thread for the temporary playback function temp_mem_playback_start() and used the thread after audio_system_init() inside main() function.

After flashing the code on nrf5340 audio DK, I am getting few prints but unable to hear the beep tone and even "playback finished" print is also not appearing from

temp_mem_playback_start() function.
Note:
In the above logic, the UART displays prints as mentioned in temp_mem_playback.log

But, If I compile a disabled section of  hw_codec_default_conf_enable() and audio_datapath_start(&fifo_txinside temp_mem_playback_start() function, the print appears as mentioned in temp_mem_playback(audio_datapath_failed).log

Please share a solution to this issue.

Attachments:
1. nf5340_audio_DBG.rar
2. beep.wav (size: 681 kb, 16bit-mono@48khz) -- inside src/modules
3. beep.h -- inside src/modules
3. Log files:
  • temp_mem_playback.log
  • temp_mem_playback(audio_datapath failed).log

Thank you.

4846.Files.rar

  • Hi,

    As you mentioned, I have used the Nordic default APIs to play audio from SD card. Before that, I have performed few changes in the code which is different from the previous code.

    1. I have exported the wav audio from “Audacity” audio tool in this format.

    Format: WAV (Microsoft)

    Channels: Mono

    Sample Rate: 48000 Hz

    Encoding: Signed 16-bit PCM

    With this, my UART log shows these new details which are now different from the old logs and is expected:

    Old wav log:

    1. Data header: LIST
    2. Data bytes: 16

    New wav log:

    1. Data header: data
    2. Data bytes: 7964632

     File changes:

    2. sd_card_playback.c

    2.a. Removed mutex LOCK/UNLOCK from ringbuf_read() and ringbuf_write() functions and replaced them with semaphores, as they were throwing errors during execution.

    3. audio_datapath.c

    3.a. Added a patch to play SD card audio when available and remain silent when not with existing ble audio playback.

    main.c

    4.a. SD card initialization and playback have been done from main.c and work handler and delayed work handler is also implemented inside main.c

     Problem: SD card playback is happening in fast-forward mode and when le audio is played (youtube/spotify), SD card playback speed gets reduced than original. But in both the cases, SD card audio is noisy.

    Note: If I build and run the nrf5340_audio code as it is, with SD card mount and playback initialized, I will get mutex related errors (from sd_card_playback.c), which was the base error in my development. 

    2275.nrf5340_audio_release_sdcard.zip

    *** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    HL [00:00:00.260,742] <inf> fw_info:
             nRF5340 Audio nRF5340 Audio DK cpuapp
             NCS base version: 2.8.0
             Cmake run : Tue Nov 18 18:26:15 2025
    HL [00:00:00.260,742] <inf> fw_info: ------- DEBUG BUILD -------
    HL [00:00:00.260,742] <inf> fw_info: HEADSET left device
    HL [00:00:00.283,843] <inf> sd_card: SD card volume size: 127999672320 B
    HL [00:00:00.288,238] <inf> sd_card: SD card mounted
    HL [00:00:00.288,665] <inf> sd_card: Listing directory: /
    HL [00:00:00.289,764] <inf> sd_card: [DIR ] System Volume Information
    HL [00:00:00.289,855] <inf> sd_card: [FILE] Arattai - Coco 2 - 20kbps.wav
    HL [00:00:00.289,947] <inf> sd_card: [FILE] Arattai - Coco 2 - 44.1kbps.wav
    HL [00:00:00.291,076] <inf> sd_card: [FILE] Arattai - Coco 2 - 48kbps.wav
    HL [00:00:00.291,137] <inf> sd_card: [FILE] Arattai - Coco 2 - 96kbps.wav
    HL [00:00:00.291,259] <inf> sd_card: [FILE] ANDROMEDA & KVRXD - NO FEAR! [Brazil
    HL [00:00:00.292,358] <inf> sd_card: [FILE] beep.wav
    HL [00:00:00.292,419] <inf> sd_card: [FILE] No Era Amor (Slowed).wav
    HL [00:00:00.292,480] <inf> sd_card: [FILE] No Era Amor.wav
    HL [00:00:00.292,541] <inf> sd_card: [FILE] No Era Amor Clean.wav
    HL [00:00:00.292,785] <inf> sd_card: Found 9 WAV files on SD card
    HL [00:00:00.293,060] <inf> bt_mgmt: UART initialized
    HL [00:00:00.316,497] <inf> bt_mgmt: Bluetooth initialized
    HL [00:00:00.363,281] <inf> bt_mgmt_ctlr_cfg: Controller: SoftDevice: Version 6.
    HL [00:00:00.363,494] <inf> bt_mgmt: Local identity addr: D7:36:91:65:08:6E (ran
    HL [00:00:00.395,690] <inf> hw_codec: hw_codec_default_conf_enable() called
    HL [00:00:00.400,573] <inf> audio_system: audio_datapath_start() succeeded
    HL [00:00:00.400,573] <inf> audio_system: audio_datapath_start() completed succe
    HL [00:00:00.400,573] <inf> main: Wait for the audio to stabilize...
    HL [00:00:02.400,695] <inf> main: Audio system started and stabilized.
    HL [00:00:02.401,397] <wrn> unicast_server: CSIP using the default SIRK, must be
    HL [00:00:02.405,120] <inf> bt_mgmt_adv: Local addr: 53:69:9F:77:4E:82 (random)
    HL [00:00:02.405,609] <inf> bt_mgmt_adv: Advertising successfully started
    HL [00:00:05.404,388] <inf> main: AUTO: Starting SD card operations...
    HL [00:00:05.404,418] <inf> sd_card_playback: sd_card_playback_wav called with f
    HL [00:00:05.404,449] <inf> sd_card_playback: WAV playback started - PCM data wi
    HL [00:00:05.404,449] <inf> main: WAV Playback Started Successfully
    HL [00:00:05.404,510] <inf> sd_card: abs path name:     /SD:/No Era Amor.wav
    HL [00:00:05.414,276] <inf> sd_card_playback: ===== WAV Header Analysis =====
    HL [00:00:05.414,306] <inf> sd_card_playback: RIFF header: RIFF
    HL [00:00:05.414,306] <inf> sd_card_playback: WAV size: 7964772
    HL [00:00:05.414,306] <inf> sd_card_playback: WAV header: WAVE
    HL [00:00:05.414,337] <inf> sd_card_playback: Format header: fmt
    HL [00:00:05.414,337] <inf> sd_card_playback: Chunk size: 16
    HL [00:00:05.414,367] <inf> sd_card_playback: Audio format: 1
    HL [00:00:05.414,367] <inf> sd_card_playback: Num channels: 1
    HL [00:00:05.414,367] <inf> sd_card_playback: Sample rate: 48000
    HL [00:00:05.414,367] <inf> sd_card_playback: Byte rate: 96000
    HL [00:00:05.414,367] <inf> sd_card_playback: Block align: 2
    HL [00:00:05.414,367] <inf> sd_card_playback: Bit depth: 16
    HL [00:00:05.414,398] <inf> sd_card_playback: Data header: data
    HL [00:00:05.414,398] <inf> sd_card_playback: Data bytes: 7964632
    HL [00:00:05.414,428] <inf> sd_card_playback: WAV file accepted: 1 ch, 48000 Hz,
    HL [00:00:05.414,428] <inf> sd_card_playback: Using frame size: 960 bytes

  • Hi, 

    The SD card playback module is designed to play WAV/LC3 files while streaming. Trying to mimic the "dummy streaming state" would be a better approach.

    -Amanda H.

Related