Close

Teensy Audio Engine Changes

A project log for NanoEgg Music Synthesizer

A powerful little music synthesizer with a classic look!

t-b-trzepaczT. B. Trzepacz 01/30/2017 at 22:160 Comments

I had a question from Paul Stoffregen, creator of the Teensy series and most of the other components of this project, and I realized that I never talked about the changes I made to his audio engine. I answered in a comment, but realized it would be a good project log, so here you go!

Paul Stoffregen wrote:

I'm curious what you've done with the audio library improvements. Are they published as open source? Anything I should merge back into the library?

Tim Trzepacz wrote

Great to hear from you Paul!

It wasn't so much "improvements" as "bypass most of it". Ultimately, I just needed a way to bang precalculated words as directly to the D/A on the Teensy audio board as possible. After a lot of puzzling about, I found the part that does that and rather messily replaced it with the final stage of my synth engine.

Since my synth engine is integrated with it, I can't share that part, but I can give the details on what I did.

The part that I modified was AudioOutputI2S::isr in output_i2s.cpp . I actually made my own version in "buffer_output_i2s.cpp" called "BufferOutputI2S", so as not to disturb the actual library code. Essentially, I made a new component for the Teensy Audio Library.

I ripped out everything after it sets up "dest" and just dropped my calculation loop right in there, writing the results directly to the buffer at "dest". I skip all of the stuff with blockL, blockR, offsetL, offsetR, "AudioStream::release", etc.
I end up with a loop that looks like this:

for( int j=0; j<AUDIO_BLOCK_SAMPLES/2; j++){
    //Calculate all the things
    *dest++=(int16_t) left_channel;
    *dest++=(int16_t) right_channel;
}

Originally I did this because I was having some trouble with the libraries that I originally attributed to my code not being fast enough when using the libraries, but later determined was due to an error in how my code was calling the Teensy Audio Library. Still, having done this, I *am* saving a few cycles, so I decided to stick with it.

I'm still running a lot of the Teensy Audio Library setup just to make sure my stuff gets called, although I'm not sure how much of it I still need.

The whole thing is going to undergo a pretty heavy rewrite when I move it to Teensy 3.6. I'm planning to make the modulation routings much more flexible, and possibly support output through the built-in D/A either in addition to, or instead of the Teensy audio board. The original version of this was written for the Arduino, and now that I have a lot more power at my disposal, I can re-examine many of my assumptions.

Thanks for making great hardware for me to work with, Paul! Your efforts have made all of this possible!

Discussions