Best place for audio processing adjustments.

Hello all,

I am working on a project with 2 nrf5340 Audio DK's, and I have been working for a while now on getting myself familiar with the audio application, but I have a few questions. First of all I assumed it would be wise to develop on top of the provided audio application since writing the entire pairing and data transmission yourself would be near impossible, is this a correct assumption?

Secondly I have the walkie talkie demo running, and am now trying to encode and decode the data that I am sending over the line, for now I just want a simple xor operation to encrypt the data and decrypt it. Right now I am doing it before the codec encode in the audio_system.c and decrypting it after the decode, but I just get a horrible noise instead of the orginal audio. I tried a few other spots like inside the callback, but I saw another thread saying this was ill advised.

So my question is what would be the correct places to place the encrypt and decrypt of the data? 

  • Hi,

    The codec is a lossy codec, so you cannod encrypt (with simple xoring or any other method) before coding. Any such operations will have to happen after coding, and then the reverse operation must be performed before decoding. (If you were doing simple one way audio processing where the output signal is also an audio signal, and there is no reverse operation in the other end, that could have been doen before encoding).

  • That makes a lot of sense, thank you.

    So I implemented it the way you are saying, and it seems to work. However if I only implement the encoding side without the decoding to check if the audio gets scrambled it doesn't output anything anymore. This feels like a checksum of some sort is being implemented somewhere.

    Do you have an idea of why this doesn't audio anymore? I would like to check wether the audio gets encrypted correctly, so it would be nice if it still reaches the speaker of my headset.

    Thank you.



    P.S.

    I placed a very simple

    const uint16_t xor_key = 0xAA;
    
    for (size_t i = 0; i < audio_frame->len; i++) {
    	audio_frame->data[i] ^= xor_key;
    }


    before the sw_codec_decode in audio.datapath.c and the same after the sw_codec_encode in audio_system.c.

  • Hi,

    I would have expected that to work. Have you done any debugging to see what happens to the data and why there is no audio output? (Start with seeing if there are errors in the log, then move deeper from there)?

    PS: I assume this is just for experimentation, but to be on the safe side, I want to mention that if the end goal is encrypting the data, you should proably use standard Bluetooth security.

  • Hi,

    First of all thank you for your help.



    So I tried to follow the audio path because there were no warnings or errors. I found the 

    sw_codec_lc3_dec_run function, which I assumed makes the PCM signal, to return only zeroes as PCM signal. I can not figure out why, but it seems to happen at LC3DecodeSessionData (I might be wrong). Also it is not noted anywhere as a bad frame so it seems like the codec is decoding it but just writes all zeroes.

    The only other maybe notable thing is that I set CONFIG_SW_CODEC_LC3=y in my conf.

    Any help is appreciated, thank you in advance. 
  • Hi,

    I am not sure I understand. Can you elaborate, and perhaps show which changes you made in the codet?

Related