Teensy 4.0 increase AUDIO_BLOCK_SAMPLES to 512

Status
Not open for further replies.
Hi,

i am using my custom audio codec and sampling at 192kHz.
After sampling i am doing an average/downsampling to 48kHz and my audio signal goes to the PC.
Everything is working fine. But now i want to increase the sampling rate to 384kHz but the signal is not the same:

This is a picture of a 1kHz sine wave at 192kHz with average to 48kHz:
Screenshot 2021-04-29 at 15.56.06.png

This is a picture of a 1kHz sine wave at 384kHz with average to 48kHz:
Screenshot 2021-04-29 at 15.57.13.png

This is a picture of a 1kHz sine wave at 768kHz with average to 48kHz:
Screenshot 2021-04-29 at 15.58.00.png

Is the interrupts load for the Teensy 4.0 too much?
To reduce the interrupt event i would like to increase the AUDIO_BLOCK_SAMPLES. If i set it to 512 at 768kHz Sampling Rate with 48kHz average the signal looks like this:
Screenshot 2021-04-29 at 16.02.04.png

Any idea? What could be the problem?
 

Attachments

  • Screenshot 2021-04-29 at 14.29.52.png
    Screenshot 2021-04-29 at 14.29.52.png
    317.7 KB · Views: 51
Hi Frank B,

here is the plot with 48kHz Sampling rate with no average with AUDIO_BLOCK_SAMPLES 512:
Screenshot 2021-04-29 at 16.20.58.png

It looks the same issue with the AUDIO_BLOCK_SAMPLES on 768kHz right?

I want to go for 768kHz to have a higher SNR with decimation/average down to 48kHz.
 
Probably a bug in your code.

Not sure what you expect.. without knowing anything about the code or even what you're doing or about the hardware you use .. it's impossible to answer.
The photos look like you're processing only a small part (128?) of your samples.
 
Hi Frank B,

i am using the Teensy 4.0 with external ADC TLV320ADC6140.

Here is my code:

Code:
#define SAMPLERATE      48000 
#define OVERSAMPLING    48000//96000 192000 384000 768000

#include <Audio.h>
#include <Wire.h>
#include <SerialFlash.h>
#include <usb_names.h>
#include "TLV320ADC6140.h"
#include "utility/imxrt_hw.h"
#include "Filter_FFT.h"

int ADC3206_RESET_PIN=17;     
AudioControlTLV320ADC6140     tlv320adc6140(OVERSAMPLING);

AudioInputI2S           i2s;           
Filter_FFT              filter1(SAMPLERATE , OVERSAMPLING, true); 
Filter_FFT              filter2(SAMPLERATE , OVERSAMPLING, false); 
AudioOutputUSB          usb;   
        
AudioConnection          patchCord1(i2s, 0, filter1, 0);
AudioConnection          patchCord2(i2s, 1, filter2, 0);
AudioConnection          patchCord3(filter1, 0, usb, 0);
AudioConnection          patchCord4(filter2, 0, usb, 1);

void setup()
{
  setFrequency(OVERSAMPLING);
  pinMode(7, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  
  AudioMemory(40);
  tlv320adc6140.enable();

}

void loop()
{
}



void setFrequency(int frequency)
{       
  // PLL between 27*24 = 648MHz und 54*24=1296MHz
  int n1 = 4; //SAI prescaler 4 => (n1*n2) = multiple of 4
  int n2 = 1 + (24000000 * 27) / (frequency * 256 * n1);
  double C = ((double)frequency * 256 * n1 * n2) / 24000000;
  int c0 = C;
  int c2 = 10000;
  int c1 = C * c2 - (c0 * c2);
  set_audioClock(c0, c1, c2, true);
  CCM_CS1CDR = (CCM_CS1CDR & ~(CCM_CS1CDR_SAI1_CLK_PRED_MASK | CCM_CS1CDR_SAI1_CLK_PODF_MASK))
       | CCM_CS1CDR_SAI1_CLK_PRED(n1-1) // &0x07
       | CCM_CS1CDR_SAI1_CLK_PODF(n2-1); // &0x3f 

}

Here is my custom class:

Code:
Filter_FFT::Filter_FFT(int samplerate , int oversample, bool debug): AudioStream(2,inputQueueArray)
{
  printvalues = debug;
  countAVG=0;
  SAMPLE_RATE=samplerate;
  oversampling = oversample/samplerate;
}


void Filter_FFT::update(void)
{
  audio_block_t *block;
  block = receiveWritable();//receiveReadOnly(); receiveWritable
  if (!block) return;

  for(int i=0; i<AUDIO_BLOCK_SAMPLES;i=i+oversampling)
  {
    array_avg[countAVG] = (int16_t)block->data[i];
    
    countAVG++;
  }
  
  if(countAVG >= AUDIO_BLOCK_SAMPLES)
  {
    
    memcpy(&block->data[0],&array_avg[0],AUDIO_BLOCK_SAMPLES * sizeof(int16_t));
    
    countAVG=0;

    transmit(block);
    release(block);
    return;
  }
  else
  {
    release(block);
    return; 
  }
}
 
Is this an audio system ?

Oversampling will reduce random uncorrelated noise, but it will not affect/improve any non-linearities in the system.
 
Please provide FULL code to reproduce the problem
(including the routines you modified in TD)

I'm using the same ADC, it may not be the same connection but rest could be similar
 
See my recent response in your other thread. Your oversampling loop in that thread is not the same as in this one.

Pete
 
Looking quickly through your code (have no time now to run program, adapt to my hardware) could not see a smoking gun.
Obviously you know that for 384 and 768 kHz you must reconfigure your channels to (4 up to 192 kHz, 2 up to 384 and 1 up to 768 kHz, addresses 0x73, 0x74)
 
Have you used AudioProcessorUsage/AudioProcessorUsageMax/AudioMemoryUsage/AudioMemoryUsageMax?
Always worth chucking this in when experimenting:
Code:
void loop ()
{
  static unsigned long last_time = millis();
  if(millis() - last_time >= 5000) 
  {
    Serial.print("Proc = ");
    Serial.print(AudioProcessorUsage());
    Serial.print(" (");    
    Serial.print(AudioProcessorUsageMax());
    Serial.print("),  Mem = ");
    Serial.print(AudioMemoryUsage());
    Serial.print(" (");    
    Serial.print(AudioMemoryUsageMax());
    Serial.println(")");
    last_time = millis();
  }
}
It won't catch all the resource usage, but its definitely worth checking.
 
Hi WMXZ,

i didnt found anything saying in the datasheet about the sample rates restriction with the amount of channels.
Only restriction of the processing blocks in this document.
I dont use the processing block features.


Hi MarkT,

here are the results:

1-Samplerate 48kHz with AUDIO_BLOCK_SAMPLES 128:

AudioProcessorUsage()= 0.59 AudioProcessorUsageMax()= 0.59 Memory: 2,4

2-Samplerate 96kHz and average to 48kHz with AUDIO_BLOCK_SAMPLES 128:

AudioProcessorUsage()= 0.57 AudioProcessorUsageMax()= 0.57 Memory: 2,4

3-Samplerate 192kHz and average to 48kHz with AUDIO_BLOCK_SAMPLES 128:

AudioProcessorUsage()= 0.56 AudioProcessorUsageMax()= 0.56 Memory: 2,4

4-Samplerate 384kHz and average to 48kHz with AUDIO_BLOCK_SAMPLES 128:

AudioProcessorUsage()= 0.54 AudioProcessorUsageMax()= 0.55 Memory: 2,4

5-Samplerate 768kHz and average to 48kHz with AUDIO_BLOCK_SAMPLES 128:

AudioProcessorUsage()= 0.53 AudioProcessorUsageMax()= 0.63 Memory: 2,4


What do you think? Is it to much interrupt for the processor?
 
Hi WMXZ,

i didnt found anything saying in the datasheet about the sample rates restriction with the amount of channels.
Only restriction of the processing blocks in this document.
I dont use the processing block features.


Hi MarkT,

here are the results:

1-Samplerate 48kHz with AUDIO_BLOCK_SAMPLES 128:

AudioProcessorUsage()= 0.59 AudioProcessorUsageMax()= 0.59 Memory: 2,4
...
...

What do you think? Is it to much interrupt for the processor?
The CPU values are percent, so if there was an overload it would have to be in the low-level
DMA interrupt(s). From the low and constant value is suggests no processing is done in
the Audio library at all. The memory figures also show no problem as 4 is <= 40
 
Hi MarkT,

AudioProcessorUsage()= 0.59 means 0.59% or 59%?


" The memory figures also show no problem as 4 is <= 40" Do you mean 2,4 <= 40 right?

Best regards
 
"The CPU values are in percent" means the units are percent. So 0.59 means 0.59%, or as a fraction 0.0059 of the time.

2,4 means 2 blocks live last time, 4 blocks live being the maximum ever observed in this run.
 
Status
Not open for further replies.
Back
Top