How to get audio output from dac pins on T3.5/3.6?

Status
Not open for further replies.
I came in here with a very similar question.

I'll be joining a Teensy-based project soon. I'm an electronics noob, but I'll be doing the software/DSP development. To already get started I'd like to create a most minimal setup that would allow me to do some testing...

Is the following layout a correct interpretation of the above posts?

Note, pin 14 is different from pin A14, which unfortunately is different from the first DAC pin in the 3.5/3.6.

Pin 14 is a digital pin, and it is the 13th pin on the right (starting with the USB up top). While in theory you can use it for output, because it is a PWM pin, you want to use the the first DAT (digital to analog) pin, which is A21, which is the 17th pin on the right.

Unfortunately, the Teensy models don't use the same pin number for the DAT, so which analog pin you use depends on the model:
  • The original Teensy 3.0 did not have a DAT pin;
  • The Teensy 3.1 and 3.2 have a single DAT pin, which is A14, and the pin is on the back row (replacing the reset pin on the Teensy 3.0);
  • The Teensy LC has a single DAT pin, which is A12, and it is in the same location as A14 on the Teensy 3.1/3.2 (the LC doesn't have the underneath pads like the 3.1/3.2 does, so it loses 2 analog pins);
  • The Teensy 3.5 and 3.6 have a pair of DAT pins, which are A21 and A22, and are now on the main row of pins.

Typically, you would want to feed the Teensy DAT pins through an amplifier before hooking them to an output device.

The original Arduino microprocessors did not have any DAT pins, and they created the function analogWrite which you could write to a PWM pin and it would rapidly turn it on/off. For LEDs, it gave the appearance of adjusting the strength of the light, since your brain would average out the on and off periods of the light. Similarly for sounds, it could allow you to think a particular tone was being generated if you feed a PWM pin to a speaker.

When the first Arm Arduino (zero) came out, and then the Teensy 3.1, the same analogWrite function was used. If you did analogWrite to a DAT pin, instead of rapidly turning a digital pin on/off, it changes the voltage that the pin generates, so it generates a smoother tone.
 
Last edited:
The Teensy 3.5 and 3.6 have a pair of DAT pins, which are A21 and A22, and are now on the main row of pins.
[/list]

Typically, you would want to feed the Teensy DAT pins through an amplifier before hooking them to an output device.

Thanks for the detailed response, Michael.

Two additional questions:
- if I only need mono output, simply hooking up one of the DAC pins is sufficient, right?
- would the extra amplification also be needed for line-level output?
 
- if I only need mono output, simply hooking up one of the DAC pins is sufficient, right?

Yes, use only DAC0/A21 on Teensy 3.6 if you only need a mono audio output.

- would the extra amplification also be needed for line-level output?

Generally the DAC pins are able to drive the 10K to 100K input impedance of typical line-level inputs on amplifiers & computer speakers.

They aren't able to drive headphones or speakers, or inputs which emulate the 33 ohm load of a headphone jack.
 
Yes, use only DAC0/A21 on Teensy 3.6 if you only need a mono audio output.

Generally the DAC pins are able to drive the 10K to 100K input impedance of typical line-level inputs on amplifiers & computer speakers.

That's great, thanks. So for my minimal test setup I would still only need a jack port and a capacitor.

In terms of software framework I'm intrigued by the 'queue' mechanism in the Audio library, which I assume will let me hook up my own existing synth engine. Is there any source code I could peruse to figure out how it works?
 
I see in the examples, there are various examples under the Analysis, Effects, Synthesis, and Tutorial headings.

Thanks, I found the Play Queue sourcecode. I didn't find an example file using it, but if I study the other library objects I can probably reverse engineer how I'm supposed to use it.

Cheers!
 
probably reverse engineer how I'm supposed to use it.

Maybe also look at the right-side panel documentation in the design tool.

Hopefully you can understand from those descriptions that you call getBuffer() when you wish to send some data. The fill the buffer with 128 samples, and called playBuffer() to tell the library when you're done putting samples into the buffer it gave you.

I didn't find an example file using it

On that documentation panel, try clicking the link under "Examples".
 
Thanks, that's very helpful. Is there some kind of callback or notification when the buffer is done playing? Or do I need to manage the timing myself using an IRQ?

By the way, well done on the Audio Library, Paul. This is refreshingly easy to use after the AVAudioEngine spaghetti that Apple created on iOS ;-)
 
No, there's no callback or notification.

But it does work as a queue. If you give it many blocks, they go into a queue and get played as the audio library can process them. The idea is to decouple the Arduino side from real-time requirements.

If you want feedback to limit your rate, you can keep giving it blocks until you get a null pointer, meaning the library can't supply you with a block to for more data. Or you can call the memory usage functions to see how much memory the library is using. Each time you get another block, that usage will increase. You can use that increase (compared to calling it before you send anything) as your feedback signal.
 
Status
Not open for further replies.
Back
Top