11 years, 3 months ago.

Function of TLV320

Is the TLV320 able to record and play back nearly at the same time? It should look like a so called loop back mode. This means the received digital data should be send back into the digital input and appears at line-out.

Question relating to:

2 Answers

11 years, 3 months ago.

Yes you can do this, either with bypass mode or with reading and writing back the data. Please check the code bellow:

#include "mbed.h"
#include "TLV320.h"
 
TLV320 audio(p9, p10, 52, p5, p6, p7, p8, p29);         //TLV320 object

/* Buffers, pointers and states */
int circularBuffer[4096];    
volatile int writePointer = 0;
volatile int theta = 0;
volatile long size = 36;

/* Record settings */
unsigned int frequency = 48000;                         //sample rate
unsigned short wordWidth = 16;                          //bits per sample per channel
unsigned short channels = 2;                            //number of channels

/* Function to read content of I2SRXFIFO into circular buffer */
void record(void){ 
    audio.read();
    circularBuffer[writePointer] = audio.rxBuffer[0];
    circularBuffer[++writePointer] = audio.rxBuffer[1];
    circularBuffer[++writePointer] = audio.rxBuffer[2];
    circularBuffer[++writePointer] = audio.rxBuffer[3];

      audio.write(audio.rxBuffer, 0, 4);

      ++writePointer;
    theta += 4;  
    if(writePointer > 4094) writePointer = 0;
}


/* Main */
int main(){   
    audio.power(0x02);                      //power up all TLV320, just not microphone
    audio.inputVolume(0.999, 0.999);        //Set input volume to max - I don't like to use 1.0 due to rounding errors
    audio.frequency(frequency);             
    audio.format(wordWidth, (2-channels));  //note int mode = 2 - channels
//       audio.bypass(true);
//    
//       while(1);
   
      audio.attach(&record);                  //attach record function to audio interrupt
    for(int j = 0; j < 4096; ++j){
        circularBuffer[j] = 0;              //clear circular buffer
    }
//    audio.start(RECEIVE);                   //start recording
    audio.start(BOTH);                   //start RX & TX
      while(1)
      {
         
      }
}

Accepted Answer

Thanks for this useful bit of code. It seems like the perfect jumping block for DSP ideas. However I have some issues and would appreciate a little feedback. In the code block you posted you write out to the i2s byy taking the rxBuffer and directly writing this back to the tx FIFO. This gives great smooth sound reproduction. If instead you transfer the contents of the rxBuffer into a local buffer, as you actually did with the circularBuffer, and then use this to fill the tx FIFO, even with no manipulation of this data, just for example a 128 sample window, the playback is choppy. It seems that I can not get smooth playback at any samplerate if I first move the data between rx fifo >>> local buffer >>> tx fifo. Do you have any insights into why this happens. I have even tried prefilling the TX FIFO to ensure that it should never be empty between rx interrupt. Am I missing something?

posted by Aidan Walton 03 Jun 2015
11 years, 3 months ago.

Thank you very very much for your fast and great answer, espacialy for the example code.