This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Play audio snippet via nRF51/52

I am working on a device which also needs to give audio feedback to the user. The app on the mobile phone needs to send a wav (or similar) file (mono, speech) to the device and the device needs to play it through a small speaker.

Is this possible with the nRF51/52 and if so can you direct me in what is needed for it to get it working (DAC, amplifier, how to transfer the data, (external)buffer/memory needed, etc?)

Thanks in advance!

  • We do not have any recommendations when it come to audio playback. This is not a common use-case for the nRF51. However there are several thread on DevZone that ask similar questions, such as this one.

    I think you have already listed the main components you need:

    • DAC
    • Amplifier
    • External memory

    The nRF52 has I2S, which may be the best option for communicating with the DAC, depending on which DAC you choose. You should use EasyDMA so that you do not experience dropouts of the audio when the CPU is busy doing something else. I2C and SPI are other alternatives.

    A alternative for very basic sounds can be to use the PWM peripheral on the nRF52.

  • Thank you for your answer. I came across this site: developer.mbed.org/.../ Where there is an example of playing a .wav file from an SD via DAC output and a transistor (or amp) to a speaker. Is something like this possible with the nRF51 (it doesn not have DAC output right, so I need an external DAC)? And what could be the drawbacks?

    What will be the advantage of i2S on the nRF52 versus i2C or SPI on the nRF51 ?

  • I believe it would be possible to play a basic sound on the nRF51 using PWM via the on-chip timers, but not while the soft device is running( I say this having successfully generated DTMF tones via PWM). I also believe I have read stuff recently relating to timeslots being available between SD operations, so I guess if your sound sample was very short, it might be possible.

  • So the main problem would be timing issues because the SOC is busy with BT handling? In my case I first wanted to get the wav data from the mobile phone onto the device and then play it. But now I am looking into putting all wav files I need on an SD card and then just get a trigger message over BT to play a certain file. Let's say the wav file is 1 minute long, would this be a problem? Or can this run in a separate process so I can still connect to the device via BLE to control it? (I am talking about SPI interface now not PWM).

  • It should be possible on the nRF51, using a low sampling rate. The details depend on the DAC, how you communicate with it, the sample rate, the bits per sample etc. Moreover, unless you can transfer data to the DAC using DMA you will get gaps in the sound. You can also try to use PWM as described by JohnBrown on the nRF51. On the nRF52 you have more options and EasyDMA on most relevant peripherals regardless of going with an external DAC or the internal PWM peripheral. I think you need to specify the level of quality etc. you need (sampling rate, bits per sample) and duration of the sound clip in order to say anything about advantages/disadvantages of the various solutions.

Related