How to route signal from A14 to Headphones [Teensy 3.1 + audio Shield]

Status
Not open for further replies.

GhostofJohnToad

New member
I am messing with some of the sound stuff from Mozzi http://sensorium.github.io/Mozzi/. I am really new to programming so I am just trying to dig in and mess with some examples. So for instance the example code below for a sine wave routes the output signal to A14/DAC. I can get this to work as it is. What I am trying to accomplish is to somehow route this signal from A14 to the headphones on the audio shield. How do I do this?

Code:
/*  Example playing a sinewave at a set frequency,
    using Mozzi sonification library.
  
    Demonstrates the use of Oscil to play a wavetable.
  
    Circuit: Audio output on digital pin 9 on a Uno or similar, or
    DAC/A14 on Teensy 3.0/3.1, or 
    check the README or http://sensorium.github.com/Mozzi/
  
    Mozzi help/discussion/announcements:
    https://groups.google.com/forum/#!forum/mozzi-users
  
    Tim Barrass 2012, CC by-nc-sa.
*/

#include <ADC.h>  // Teensy 3.0/3.1 uncomment this line and install http://github.com/pedvide/ADC
#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator

// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);

// use #define for CONTROL_RATE, not a constant
#define CONTROL_RATE 64 // powers of 2 please


void setup(){
  startMozzi(CONTROL_RATE); // set a control rate of 64 (powers of 2 please)
  aSin.setFreq(440); // set the frequency
}


void updateControl(){
  // put changing controls in here
}


int updateAudio(){
  return aSin.next(); // return an int signal centred around 0
}


void loop(){
  audioHook(); // required here
}
 
Unfortunately, there isn't any easy way to do this. The DAC (A14) is on the main MK20 chip. The audio shield is separate hardware, without any analog connection. It only connects to the digital pins.

The "right" approach would be to add a small analog amplifier.

The SGTL5000 chip on the audio shield does have an analog headphone amp inside, but it has a lot of other stuff too. Normally, it's meant for digital signals to convert to analog output. However, if you use the I2C port (Wire library), it's possible to control the SGTL5000 directly. The audio lib's SGTL5000 object does this, so it's source code would be a good starting point. If you look at the SGTL5000 datasheet, it's possible to configure the SGTL5000 internal analog path to route the line inputs to the headphone output, completely bypassing any digital stuff. Unfortunately, the audio lib object doesn't have a function to put the SGTL5000 chip into this mode. But if you added that, you could probably get the chip into that mode, where it'd act as just an analog amplifier without any digital path. Then you could connect a wire from DAC/A14 to the line in.

But just using a regular audio amp chip would be much simpler.
 
I am not sure what you want. I interpret as routing the mozzi audio to the audio shield, not necessarily pin A14.
You could add the following Audio library objects: an AudioPlayQueue connected to an AudioOutputI2S.
Then replace the contents of the teensyAudioOutput function of the Mozzi library with a function that insert the samples into the queue and release this queue every 128 samples.
Furthermore you also need to adjust the i2s master clock to 16/32 kHz.(See this thread)
 
Status
Not open for further replies.
Back
Top