Close

Audio Injector Octo working with Circle port of Teensy Audio Library

A project log for rPi bare metal vGuitar rig

An attempt to create a working live guitar rig that includes effects, midi synthesizers, loopers, controllers, and user feedback systems.

patrickPatrick 06/13/2019 at 13:580 Comments

Got the 6-in, 8-out, Audio Injector Octo sound card working with my bare metal Circle port of the Teensy Audio Library !!   Here's a link to the Audio Injector Forum:  forum

(this log entry has been edited to add a picture of the Octo sound card in-vivo, below):

The source code is posted here, but there's a caveat:  It's in a high state of flux, so I don't currently recommend branching it.  However if you are looking for those 3 lines of code that do something that I might have already done, it's there.

After much consideration, I finally decided about two weeks ago to port Paul's Teensy Audio Library to work with RST's bare metal Circle framework on the rPi.   I retain my desire to avoid using linux and the complicated driver layers it presents,  His library is far simpler, easier to understand and port, and provides a good basic starting point for doing sound projects.

The initial steps of the port, using the Audio Injector Stereo soundcard, went well as I already had a working bi-directional Circle i2s device written from previous experiments. Within an evening I had the three most basic classes working: AudioInputI2s, AudioOutputI2s, and AudioControlWm8731.  After that It only took a few hours to port a couple more interesting example classes including the Mixer and Reverbs.   The Mixer ported directly, in 5 minutes, with no source level mods !  To get the reverbs to compile I had to dig up and add some arm-math libraries to Circle, but even that only took a few hours, but they also basically compiled without source level mods.. 

I even created an arduino-like framework for running the programs within Circle, so the following working source code will look familiar to anyone who has worked with the Teensy Audio Library before.  But please understand that the following program is not an Arduino sketch.  It runs on an rPI within the Circel bare metal framework!

//-----------------------------------------------------------
// reverb_test.cpp

#include <Arduino.h>
     // Arduino.h is not needed but it is fun to list it
     // here as if it were a real arduino program 

#include <audio\Audio.h>

#define I2S_MASTER  0

#if I2S_MASTER
     AudioInputI2S input;
#else
     AudioInputI2Sslave input;
#endif

AudioEffectReverb   reverb1;
AudioEffectReverb   reverb2;
AudioMixer4         mixer1;
AudioMixer4         mixer2;

#if I2S_MASTER
     AudioOutputI2S output;
     AudioControlWM8731 control;
#else
     AudioOutputI2Sslave output;
     AudioControlWM8731master control;
#endif


AudioConnection  c3(input,   0, mixer1, 0);
AudioConnection  c4(reverb1, 0, mixer1, 1);
AudioConnection  c5(input,   1, mixer2, 0);
AudioConnection  c6(reverb2, 0, mixer2, 1);
AudioConnection  c7(mixer1,  0, output, 0);
AudioConnection  c8(mixer2,  0, output, 1);


void setup()
{
     printf("reverb_test::setup()\n");

     reverb1.reverbTime(0.6);
     reverb2.reverbTime(0.6);

     AudioMemory(20);

     control.enable();
     control.inputSelect(AUDIO_INPUT_LINEIN);
     control.inputLevel(1.0);
     control.volume(1.0);

     mixer1.gain(0, 0.6);
     mixer1.gain(1, 0.3);
     mixer2.gain(0, 0.6);
     mixer2.gain(1, 0.3);

     printf("reverb_test::setup() finished\n");
}


void loop()
{
}

I figured it would then be pretty easy to implement the Audio Injector Octo, as Paul already had a ControlCS42448 class in the library.

However, it turns out that the Octo is not really a "standard" CS42448.  Flatmax has implemented an FPGA on the board that becomes the BCLK and LRCLK master for both the cs42448 and the rpi i2s (which are both slaves), and it took some digging to figure out how to initialize it and get it working.  For better or worse, Flatmax used an additional FIVE gpio pins to communicate with the fpga.  One for a reset signal, and four to set a 4 bit sample rate.    Although I'm not terribly thrilled with the extra gpio pin usage, and wonder why he did not perhaps just piggyback the fpga control as an additional i2c device on the existing bus, by and large the board is impressive with it's 6 (six) ins and 8 output channels, and sounds pretty clean at 44.1K 16bit.

Below is an image showing the 176KHz LRCLOCK being produced by the Octo card:

I still have some reservations about moving forward with the Teensy Audio Library ... namely that it IS more or less limited (constructed) to 16 bit 44.1K sound, but for the time being it is what I have.  I can change that if I really want.  I am also still considering porting JACK to the Circle framework, as it *might* provide more compatibility with existing other code (i.e. Zynthian, FluidSynth, etc) that I might want to try to port to the bare metal framework later.  

Who knows?  :-)

But as of today the Octo works with the Teensy Audio Library on a Circle Bare metal rPi, and that's what I wanted to post.

- Patrick

Discussions