nrf5340: How to Play audio from file

Hello devzone

I am developing on the nrf5340 audio dk using nrfConnect SDK (NCS) 2.3. I need to play audio using only 1 device, by loading an audio file into memory, and am looking for samples / documents, preferably with just the required parts. I have browsed the applications/nrf5430_audio but it needs 2 devices, is streaming audio over usb-c . I am new to NCS,  want to find a simple, effective way to do this use-case .

1. How do I load an audio file from storage into a memory buffer ?
2. How do I play this buffer ?
3. What is the audio format to be used, and are there sample audio files ?

Any pointers are appreciated. 

Thanks

Parents
  • Hi,

    I do not believe we have any out of the box solution for playing audio from a file. Is it so that you want to stream the data over USB, or do you want to transport a file to the nRF, and then play it?

  • Hi Einar,

    I'm trying to load a small audio file from internal storage into a memory buffer , on bootup.
    Then play the sound from the memory buffer , say from a button press. Not wanting to stream over USB.

    Q) How do I generate a sample LC3 audio file that I can test with?
    Q) What is the API to -play audio & stop audio, on a single device? 

    Q) Is there a way from a Nordic desktop tool to copy this audio file from Linux into the 5340 internal storage?
     
    Q) I'm seeing a size error when saving a blob of 4200 bytes using settings_save_one() . (Works for 3600 bytes though)
    Q) the value saved using settings_save_one is lost when I update using buildprog. How do I keep it persistent across flashes?
    What is the recommended way to save a binary file to storage, and is there a size limit?

    Let me know what ideas can work for this use case?

  • Hi,

    Samd said:
    Q) How do I generate a sample LC3 audio file that I can test with?

    You can send data to the encoder thread (located in audio_system.c), but you'll have to route the data to your storage if you intend to save it for later playback.

    Samd said:
    Q) What is the API to -play audio & stop audio, on a single device? 

    This is all contained in the streamctrl files, if you are referring to how play/pause button presses etc. are handled.

    Samd said:
    Q) Is there a way from a Nordic desktop tool to copy this audio file from Linux into the 5340 internal storage?

    No, but you could make use of the SD card holder on the Audio DK to play stored data. This is not part of the default nrf5340_audio application, but the Audio DK does have a SD card reader that you can use - you'll just have to add its use into your application yourself. Please see the sd_card files in the nrf5340_audio repository for the API you should use, and let us know if you run into any issues.

    Samd said:
    Q) I'm seeing a size error when saving a blob of 4200 bytes using settings_save_one() . (Works for 3600 bytes though)
    Q) the value saved using settings_save_one is lost when I update using buildprog. How do I keep it persistent across flashes?
    What is the recommended way to save a binary file to storage, and is there a size limit?

    Use the SD card to make sure that you are keeping the data between flashes.

  • Thanks Einar,
    I see that when I have a 32GB, or 2GB  FAT32 SD card inserted, sometimes it gets stuck at the log 

    <inf> sd_card: SD card volume size: 30528 MB

    And the LED light does not turn on. When I remove the SD card, led turns on, and connects

    I repeat error case by Inserting the SD cards, reboot.. boards get stuck at the same sdcard log

    Is there an optimal size range (e.g 2/8/32/64GB) , Speed, Class (e.g Class10, UHS.. etc) of SD card to be used?

    Also, I have seen that if I use a k_thread to load an sdcard file 120kb, the thread gets stuck with no errors. if the STACK_SIZE is not large enough. When I made the STACK_SIZE 120kb, the k_thread loaded the file ok.

  • I am not aware of any optimal SD card size. Similarly, as long as the card support the speed you are using on the SPI interface (which should not be a practical problem with an nRF), a higher speed class is not a problem (it is the reader/nRF that decide what is being used).

    Regarding stack size that depends on how you are doing this. If you are using an array on the stack to hold the data you read (?), then if you build your app with a larger array to hold a larger file, that is expected. 

Reply
  • I am not aware of any optimal SD card size. Similarly, as long as the card support the speed you are using on the SPI interface (which should not be a practical problem with an nRF), a higher speed class is not a problem (it is the reader/nRF that decide what is being used).

    Regarding stack size that depends on how you are doing this. If you are using an array on the stack to hold the data you read (?), then if you build your app with a larger array to hold a larger file, that is expected. 

Children
No Data
Related