Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: AudioInputAnalog Resources?

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    9

    AudioInputAnalog Resources?

    Hi,

    The Audio System Design Tool mentions the AudioInputAnalog object, and I was hoping someone could point me to any resources that outline how this object functions. In particular, any pointers about how AudioInputAnalog and analogRead() do/don't work together would be most helpful. So far, I've only been able to find a few forum posts about specialized topics, and no general overviews (besides what's in the Audio System Design Tool).

    I'm starting a project where I'd like to use just a Teensy 3.6 and its built in ADCs to receive 1 audio-rate analog input and 3 sub-audio-rate analog inputs (as well as 4 digital ins and 1 audio out). In addition, I'm hoping to record from the audio in, then use the sub-audio ins to control playback parameters, so I won't need to access the audio in and the sub-audio ins at the same time.

    If I'm understanding things correctly, AudioInputAnalog is the best ready-made way to handle audio-rate signals, and it only makes use of 1 of the Teensy's 2 ADCs. From the forum posts I've read so far, I can't tell whether it's possible to set things up so that 1 ADC is dedicated to the audio in using AudioInputAnalog while the other is split between the 3 sub-audio ins using analogRead(). Is this possible, and if so does anyone know of some example code that outlines how to do it?

    Alternatively, is it possible to reconfigure the ADCs on the fly, so that during loop() my code normally uses analogRead() to access only the sub-audio ins, until a button is pushed and loop() calls a function that (1) sets up an AudioInputAnalog, (2) uses it to access only the audio in, then (3) destroys the AudioInputAnalog and returns to loop()? (Not sure if that makes complete sense, so let me know if there's more I can say to flesh this out). Again, if this is possible does anyone have example code showing how to do it?

    Best!

  2. #2
    Junior Member
    Join Date
    Feb 2019
    Posts
    9
    Bump if anyone knows anything?

  3. #3
    Lot going on in your post, kinda hard to parse.

    I would say, for the audio recording and playback, it's best not to use the onboard ADC and DAC at all, as you're probably not going to get the fidelity you want. You almost certainly want to use a codec, like what is offered on the official audio board.

    The other part - low frequency analog inputs - I believe you would be fine to use the onboard ADCs for that, probably with a library like Pedvide's (https://github.com/pedvide/ADC/tree/master/examples) since it seems like you want to do some "stuff" which I couldn't quite follow.

    There's one thing I noticed: "use the sub-audio ins to control playback parameters". It would be very good for you to start digging into the Audio library and take a look at what facilities exist for working with recorded audio. The current situation for working with recorded audio is pretty much "play/stop" and if your needs are more advanced than that, you may end up needing to implement new capabilities in the library code.

  4. #4
    Junior Member
    Join Date
    Feb 2019
    Posts
    9
    Thanks for the reply, and sorry for the 'lot going on' phenomenon. I'm new to Teensy and to digital audio projects, so I'm still learning the language so to speak. I've responded to each of your points, hopefully to give more clarity about where I'm coming from, and then added what I take to be my main question at the end.

    I'm not too worried about the fidelity for this project. I'm looking to make a eurorack module that records short scratch/bump sounds from a contact microphone and plays them back into a resonator module, so since the original sound isn't particularly hi-fi and it's is going to get mangled by the resonator anyways I figured I could save some money and design complexity by using the built in ADC. I also figured it could be an interesting distortion/bitcrush effect if I ever want to record percussive sounds. So warning about fidelity 100% heard and appreciated, but the low fidelity is neutral to slightly positive for me in this project.

    For the low frequency analog inputs, all I'm looking to do is have the Teensy read from three potentiometers. I've seen quite a few examples of how to do this normally, using analogRead(). If I weren't also trying to record audio with the Teensy, I wouldn't need anything more complex than that. After poking around in Pedvide's library, it looks like it gives me more control over the ADC than analogRead() would, so I'll be looking further into that, as I'm guessing that's the sort of functionality I'll need to read from the pots and record audio. Thanks for the pointer!

    For the playback parameters, I'm really just thinking about play and volume level. I'm going to use the digital inputs to start playback of different audio samples, and the low frequency analog inputs to control the volume of the samples. Again, I have a decent idea about how to normally do this (using if (digitalRead(x) == HIGH) and AudioPlaySdRaw.play(y) for playback and AudioMixer4.gain(z, z') for volume), just worried about how recording audio might affect that.

    So, my main question is: how, if at all, can I record audio with one of the Teensy's ADCs while keeping the second ADC available to read values from 3 pots? Any resources from the Teensy site, or this forum, or from code examples, or.. that might point me in a good starting direction would be a huge help.

  5. #5
    There are two ADC modules in the Teensy: ADC0 and ADC1. When you add an AudioInputAnalog object to your project, it configures ADC0 for audio use, but leaves ADC1 alone.

    So for your project, it sounds like you need an AudioInputAnalog object, and then to use ADC1 for your 3 pot readings. ADC1 would be configured using "regular ADC code" for lack of a better term. Just make 3 different readings on 3 different pins to get your pot values. The real catch is, I don't know if the blocking read on ADC1 would cause audible glitches while the audio library is doing it's thing. It may be best to put ADC1 into continuous read mode so the audio library can execute without being blocked. I would suggest to try it and see what happens.

  6. #6
    Junior Member
    Join Date
    Feb 2019
    Posts
    9
    Gotcha. That makes sense to me, so I'll try that and touch base back here if anything goes wrong. Also, I just saw Pedvide's post here (https://forum.pjrc.com/threads/25532...for-Teensy-3-1) where they include a picture of which pins from the 3.6 are connected to which ADCs. I'll plan on connecting the pots to pins that only use ADC1, and connect the audio in to one that only uses ADC0.

    Thanks for the help!
    Last edited by gtrmstr53; 08-05-2019 at 06:57 PM. Reason: Edit to say 'one that only uses ADC0'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •