guidance needed for: basic stereo audio input and output, no processing.

Status
Not open for further replies.

nagual

Well-known member
Hi,

I know what I have are two great products, the Teensy 3.1 and the Teensy 2++.
However, I am still sitting on the outside of the walls of the awesome 24/7 rave that is microcontroller nirvana.

Today I would like to put audio input and output on either the 3.1 or the 2++, Analog to digital, and then digital to analog, without even any additional processing.

I know there is a shield, but I do not have that. I have almost nothing since I don't know what I need and can't really afford to buy every possible component that the electronics elves tell me they need. This is why I am making this thread. I want to plug in one of these microcontrollers and digitally pass an analog signal through one of them or both, however crudely.

I need to know if I will need op amps, preamps, special grounding, voltage tolerances (what's the hottest signal that can go to the teensy?)

does the 2++ and 3.1 equal one another in the ADC/DAC department?

Basically, to sum up in the simplest way possible: can I do this today, with either or both of these two microcontrollers?
 
The 3.1 and the 3.2 have 2 16bit ADCs (from which 12 bit are really usable, the remaining bits are noise) and 1 12bit DAC. The Teensy 2++ has no DAC, only PWM outputs, thus your Audio project will not work with satisfying quality on the latter.

On the Teensy 3.x, the basic procedure is
=> setAnalogReadResolution(12)
=> setAnalogWriteResolution(12)
=> choose the reference voltage Vref (1.2V or 3.3V)
=> instatiate an intervalTimer with an interval corresponding to your desired sample rate which triggers the IST
=> write an ISR which reads the ADC value with analogRead() and outputs it with analogWrite

The ADC inputs can only read positive voltages while audio signals have positive and negative halves. Thus, a pre-amplifier/buffer circuit which adds a DC offset of Vref/2 will be required. At the DAC output, the DC offset has to be taken off again. That can be done by a simple coupling capacitor, or better by a difference amplifier which buffers the signal and filters the sampling frequency at the same time.
 
thanks for your reply. wow, i don't know where to begin...

The 3.1 and the 3.2 have 2 16bit ADCs (from which 12 bit are really usable, the remaining bits are noise) and 1 12bit DAC. The Teensy 2++ has no DAC, only PWM outputs, thus your Audio project will not work with satisfying quality on the latter.

On the Teensy 3.x, the basic procedure is
=> setAnalogReadResolution(12)
=> setAnalogWriteResolution(12)

I guess this needs to go in the program at the top. I will check the audio code generator page to see if this is generated by that.

=> choose the reference voltage Vref (1.2V or 3.3V)

I am presuming this also is designated in the software I need to write.

=> instatiate an intervalTimer with an interval corresponding to your desired sample rate which triggers the IST

I'll look up 'intervalTimer' never seen that before. Also will google IST, since I've never seen that acronym either. New stuff!

=> write an ISR which reads the ADC value with analogRead() and outputs it with analogWrite

Never heard of ISR either, will add to my search tasks.

The ADC inputs can only read positive voltages while audio signals have positive and negative halves. Thus, a pre-amplifier/buffer circuit which adds a DC offset of Vref/2 will be required. At the DAC output, the DC offset has to be taken off again. That can be done by a simple coupling capacitor, or better by a difference amplifier which buffers the signal and filters the sampling frequency at the same time.

that's actually really interesting. I bet this is going on in all ADC's but I just never got to get near this level of depth. Guess I need to know how many ohms the input and outputs are if I am going to attach capacitors to the terminals. wondering which direction they should go in... does teensy both receive and send voltage? need to set the polarity of the caps I guess.

ouch! Uncle!! haha, I wonder if I should be at a better forum for learning the basics before I bother this forum with electronics questions? suggestions for a good goo goo ga ga baby electronics and math forum where I can learn all this basic stuff? I can Google but I don't have 100 years to learn this stuff.

thanks again!
 
yeah, use teensy 3.x

as for how-to-do-it, the audio library comes to mind ... (?)

the ADC side of things is fairly well covered here, incl a note on external circuitry/hardware:

http://www.pjrc.com/teensy/gui/?info=AudioInputAnalog

DAC is here:

http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog

in fact, there's an example sketch called PassThroughMono.ino in Examples>Audio

hm, ok so now it's easy... gotcha.

but the pages that you showed me have only blank sketches. no modules are displayed in the modular code designer windows. does that mean i don't need any code to get this to work? i disabled my adblock and I just have white squares where there should be 'modules'

edit: ok i see there are no sketches at those links.

I will be adding code to the Teensy, but I need somewhere to start, and it looks like even starting at the very most basic step is really a formidable challenge.
 
Last edited:
hm, ok so now it's easy... gotcha.

yep, it's easy. if you'd prefer to understand what you are doing, you're better off following the advice given by Theremingenieur. if you just want it to work, use the audio library.


but the pages that you showed me have only blank sketches. no modules are displayed in the modular code designer windows. does that mean i don't need any code to get this to work? i disabled my adblock and I just have white squares where there should be 'modules'

edit: ok i see there are no sketches at those links.

i meant to link to the stuff in the window on the right, you should see some sort of description and a circuit diagram. that's sort of doing what the Ingenieur described verbally. the ADC, for example: there's said coupling capacitor (10uF, in series with Audio input) and something that pulls up the signal to VREF/2. that's the voltage divider, which is formed by the 10k and 2.2k resistors: (2.2/10+2.2)*3.3 ~0.6V. depending on which parts you have handy, it'll probably be easier to work with VREF = 3v3.

the sketch is in Examples>Audio>HardwareTesting>PassThroughMono
 
ISR is a very common acronym for "Interrupt Service Routine".

Concerning the intervalTimer object and the different commands to set resolutions, references, read and write data, you have to learn the Teensy programming language which is a superset of Arduino's C/C++ with additional functions, objects and macros. These are documented on the PJRC Teensyduino website. The intervalTimer object for example is described in the subcategory Timing => IntervalTimer. For most common Arduino (and identical Teensy) functions, the Arduino reference Website is a good starting point. The basic use of teensy-specific functions and objects can be understood by studying the source code of the Teensyduino core files, example programs, and libraries. (This is the diplomatic version of RTFM)

IMNSHFO, one should familiarize with a specific processor and its programming environment first, before one starts doing more complex tasks like digitalizing and re-converting audio signals which requires some knowledge in electronics, in the Teensy 3.x hardware and its H/W-specific programming.
 
Last edited:
i disabled my adblock and I just have white squares where there should be 'modules'

PJRC never displays ads. We don't even use anything like statcounter or newrelic. We've never shown any ads, not even once in the 16 year history of pjrc.com, nor in the 5 years before that when it was hosted at a university site.

Hopefully Adblock doesn't interfere. Can you post a screenshot of the page that's not displaying properly?


Regarding the original question, if you just want to get it working, definitely use the audio library on your Teensy 3.1. That design tool should give you a pallet of many objects on the left, a blank canvas to draw, and documentation on the right side about whatever object is selected. You can compose an audio system by dragging objects onto the canvas and drawing connections between them.

For just passing data through, drag 1 ADC and 1 DAC onto the page and connect them by a single wire. If you later want to make it a delay or filter, just put the processing objects on the canvas and wire the connections. It's meant to make building advanced audio processing easy.
 
Actually the adblock thing was a misunderstanding, I was expecting stuff to be on the blank canvas like a prewired schematic, but there was not of course, and i figured out why: the stuff I was supposed to be looking at was in the module description pane.
 
I'm having trouble with simple audio stereo input using the Line In Pins. I tested two mics one at a time on Audio Shield mic input and could hear the output on my headphones just fine (Microphone_Check.ino), but when I plugged those same mics into the two Line In stereo pins and tried (PassThroughStereo.ino), nothing came through my headphones.

I saw that for Line Out you have to manually unmute the first time you use it, and I was wondering if a similar thing needs to be done for the Line In? Any other thoughts for why the mic would work but the line in doesn't?

From "PassThroughStereo.ino":
const int myInput = AUDIO_INPUT_LINEIN; //doesn't seem to work at all
//const int myInput = AUDIO_INPUT_MIC; // works great
 
If it's a bare mic you are using the output will be very low level, and depending on design will need a bias:

see the schematic
https://www.pjrc.com/store/teensy3_audio.html

and notice the differences in wiring

The line in is expecting a Line level input, which is I think ~1V levels and a basic microphone is not going to natively produce those. To get stereo audio you'll need to add a microphone preamp to get to line levels from the two microphones.

I've used
https://www.adafruit.com/products/1063

Which has in inbuilt amplfier to boost to line levels, though there are many ways to get there trading cost, setup time and quality in varying amounts. If you have audio equipment around already you can probably get line levels from a pair of mics with a bit of rejigging things since it's a fairly common need.
 
Status
Not open for further replies.
Back
Top