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

Thread: Real Time Audio Processing

  1. #1

    Real Time Audio Processing

    I've not yet even tried venturing into this area of C++ yet... But do 'the people in the know' see the Teensy 4.1 as a viable microcontroller for a project aimed at real-time audio processing?

    I'm thinking of creating a project that would take in audio via a 1/4" jack, process multiple effects in realtime such as reverb, delays, EQ's, distortions (stacked on top of each other), then output the final audio with, let's call it 'very useable', low latency? Suitable enough in terms of latency/audio quality for live performance, for example? If so I will plan on learning about/writing those effects myself which will be an awesome project to tackle.

    On top of this there would be a display to run, and some buttons/knobs as controls.

    Is the T4.1 geared up for this sort of job already? Or am I being a little too optimistic here?

    Thanks!

    Steve
    Last edited by StevenMartin; 06-18-2021 at 07:43 PM.

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,089
    I'm not really up on the stuff, but I've seen some Teensy sync and sound projects:


    You might want to look through the original video for the audio library. While it used a Teensy 3.2, the Teensy 4.1 should support everything (note, the pinouts for the audio shields are different). Also look at the audio design tool for designing the connections between the inputs, effects, and outputs:

  3. #3
    Senior Member
    Join Date
    Jun 2018
    Location
    USA
    Posts
    192
    It's ok for this but not excellent. ~7ms is the loopback time between analog input and analog output. It's enough for real time musical processing. I use it this way, others use it this way. But I've seen other projects get closer to ~3ms. This is with the audio library by the way. Apparently the hardware is capable of faster speeds, with optimized code. I also think the bitrate (16 bits) has something to do with limiting the theoretical speed of I'm not mistaken.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,190
    The audio block size and latency of the codec contribute to the delay. Bit depth has no effect.
    The default block size is 128 samples which is 2.9ms at 44.1kSPS. You can reduce the block
    size for lower latency(*) at the expense of increased CPU usage. On the T4.x there's usually no
    shortage of processor power.

    (*) Some audio components don't work at different block sizes though.

  5. #5
    Senior Member
    Join Date
    Jun 2018
    Location
    USA
    Posts
    192
    Is there an easy way to test different block sizes?

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,190
    check this thread. https://forum.pjrc.com/threads/55408..._BLOCK_SAMPLES

    I am not totally sure if it has to be a power of two, but I'd assume so.

  7. #7
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    311
    Some of us have done extensions to the audio library in order to support floating point math, instead of just the fixed point math used by the Teensy audio library. In some of these libraries, the sample rate and block size can be changed, unlike the Teensy audio library.

    One such library is the Open Audio library (which helped create originally). Here's an example sketch where you can see where to set the sample rate and block size: https://github.com/chipaudette/OpenA...TestBiquad.ino

    Another library is the Tympan library, which is aimed at supporting the Tympan audio hardware (a Teensy at heart) but it can be used with any hardware. Here's a sketch that shows how to change the sample rate and block size: https://github.com/Tympan/Tympan_Lib...SampleRate.ino

    Minimum latency would be achieved through the shortest block size and fastest sample rate. Tympan can run up to 96 kHz and probably would function at block sizes of 1 or 2 samples (I've only ever gone down to 8). If you're using the Teensy audio adapter (STGL5000), I'm not sure what sample rate you can go up to, but you can totally still use the shorter blocks.

    Have fun!

    Chip

  8. #8
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    311
    I forgot to mention that I did a blog post discussing my latency measurements and the impact of these different system settings. You might be interested:

    http://openaudio.blogspot.com/search/label/latency

    Chip

Posting Permissions

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