Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 16 of 16

Thread: Teensy 4.0 increase AUDIO_BLOCK_SAMPLES to 512

  1. #1

    Teensy 4.0 increase AUDIO_BLOCK_SAMPLES to 512

    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:
    Click image for larger version. 

Name:	Screenshot 2021-04-29 at 15.56.06.png 
Views:	14 
Size:	318.9 KB 
ID:	24641

    This is a picture of a 1kHz sine wave at 384kHz with average to 48kHz:
    Click image for larger version. 

Name:	Screenshot 2021-04-29 at 15.57.13.png 
Views:	13 
Size:	323.0 KB 
ID:	24642

    This is a picture of a 1kHz sine wave at 768kHz with average to 48kHz:
    Click image for larger version. 

Name:	Screenshot 2021-04-29 at 15.58.00.png 
Views:	11 
Size:	425.6 KB 
ID:	24644

    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:
    Click image for larger version. 

Name:	Screenshot 2021-04-29 at 16.02.04.png 
Views:	18 
Size:	316.0 KB 
ID:	24643

    Any idea? What could be the problem?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screenshot 2021-04-29 at 14.29.52.png 
Views:	10 
Size:	317.7 KB 
ID:	24640  

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,605
    Does 512 work with a lower samplerate?

    And why do you sample with that high speed?

  3. #3
    Hi Frank B,

    here is the plot with 48kHz Sampling rate with no average with AUDIO_BLOCK_SAMPLES 512:
    Click image for larger version. 

Name:	Screenshot 2021-04-29 at 16.20.58.png 
Views:	15 
Size:	281.7 KB 
ID:	24645

    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.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,605
    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.

  5. #5
    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; 
      }
    }

  6. #6
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    419
    Is this an audio system ?

    Oversampling will reduce random uncorrelated noise, but it will not affect/improve any non-linearities in the system.

  7. #7
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,261
    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

  8. #8
    Hi mlu,

    yes it is an audio system.

    Hi WMXZ,

    just upload my code in github with my teensycore changes

    Could anyone make the AUDIO_BLOCK_SAMPLES at 512 work on teensy 4.0?

  9. #9
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,691
    See my recent response in your other thread. Your oversampling loop in that thread is not the same as in this one.

    Pete

  10. #10
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,261
    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)

  11. #11
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,110
    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.

  12. #12
    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?

  13. #13
    So the problem is not Teensy but the TLV320ADC6140.

    WMXZ is right i can only use one channel at 768kHz and two channels at 384kHz.

    Everything is described here:
    https://www.ti.com/lit/an/sbaa381/sb...=1620114197025

    Click image for larger version. 

Name:	Screenshot 2021-05-04 at 09.47.34.jpg 
Views:	10 
Size:	61.5 KB 
ID:	24721


    In my configuration i have enabled 4 differential channels and thats why it isn't working.

  14. #14
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,110
    Quote Originally Posted by Michael Liesenberg View Post
    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

  15. #15
    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

  16. #16
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,110
    "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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •