Audio data through shield to Teensy

Status
Not open for further replies.

Nate_Fritz

New member
Hi all,

I am pretty good at working with hardware but when it comes to coding I am like a lost puppy in the woods. I am doing a project for school where I have to create a music reactive lighting system that analyzes frequency content from LINE IN (not microphone), performs an FFT, and makes the lights respond in different ways depending on frequency and magnitude(volume) content of a song.

Anyways, I'm trying to break it down into small stages. I have soldered together my Teensy 4.0 and my Rev D audio shield, alond with a female TRS jack onto the LINE IN terminals of the shield. Currently, all I am trying to do is come up with some code that will allow me to plug in my phone to the jack, play a song, route the analog data (from the phone) through the shield's ADC, and send it to the Teensy in the form of an i2s signal. Then, I would like to display that data if possible. From there, I will be performing my FFT algorithm to separate the frequency into bins and then define the bands and so on, but thats a whole nother story. One stipulation for this project, however, is that I am not allowed to use the PJRC audio design tool, which makes things quite a bit more difficult.

I am very confused on how exactly to tell the shield to send the data through the ADC and then to the Teensy, and I have no idea what I am doing when it comes to the code. Please let me know if you have any suggestions.

Thanks,

Nate
 
Yes, several times. But as I was saying, I am not allowed to utilize the Teensy audio design tool for this project as it is for a college class. It says on the Audio shield page (on PJRC) that audio data is transmitted from the shield to the Teensy via pin 8. What I am trying to understand right now is how do I retrieve that data from pin 8? With digitalRead? And what type of data comes from that pin? Is it i2s? And does the audio data automatically go from the line in terminals on the shield to the ADC or do I have to specify that? And is there a way for me to "split" the audio data so that it goes straight through the shield to the output jack (to a speaker) and also send it through ADC and then to the Teensy at the same time?
 
Anyways, I'm trying to break it down into small stages. I have soldered together my Teensy 4.0 and my Rev D audio shield, alond with a female TRS jack onto the LINE IN terminals of the shield. Currently, all I am trying to do is come up with some code that will allow me to plug in my phone to the jack,

The jack on the audio shield is output only, meant for headphones. To get a signal into the audio shield, you need to connect it here:

audioshield_inputs.jpg


What I am trying to understand right now is how do I retrieve that data from pin 8?

Probably best to start with this 31 page tutorial.

https://www.pjrc.com/store/audio_tutorial_kit.html

You can probably skip most of section 1, but it's a good idea to at least get a WAV file playing from the SD card. You probably only need the first several pages of section 2 to learn how the design tool works. Maybe do the microphone check part of section 2, but edit the code to take input from the line in pins rather than the mic. Do that part so you know you have a valid signal input, then skip the rest of section 2 and go to section 3 which is all about analyzing audio.

There's also a full walkthrough video, in case you get stuck on any part. But best to actually *DO* the tutorial rather than just watch.

And directly answer your "how do I retrieve that data from pin 8" question, usually you don't. Typically you would use the design tool to craft a system that routes the audio data to a FFT1024 analysis, any maybe other stuff too. That will make much more sense after you've done even the first little part of the tutorial section 2. But if you *really* want to get the raw audio samples, the "queue" feature in the audio library is meant to all your program to tap into the raw audio samples. It's a fairly advanced usage that's not very beginner friendly, and it's not covered by the tutorial. But again, you would normally not use the queues. The normal way is to create an audio processing system using the design tool and then use code like the section 3 examples to obtain the live analysis data as the audio library takes care of streaming the actual audio samples.


And since you mentioned making lights respond, just in case you're planning to use the very common WS2812 or "NeoPixel" addressable LEDs, be sure to use either the WS2812Serial or OctoWS2811 libraries for those types of LEDs. Those libs are non-blocking and won't cause the audio processing to stop while the LEDs update. If you use the Adafruit_NeoPixel library, it will block the audio streaming.
 
I am not allowed to utilize the Teensy audio design tool for this project as it is for a college class.

That tool is only a convenience and is not required at all to build Audio lib programs. Find one of the example programs for the
Audio library such as examples>Audio>HardwareTesting>PassThroughStereo, and work from there. The library exists to hide
all the details of the I/O hardware amongst other things. The audio shield itself does the analog->digital conversion.
 
How would the teacher know if you used the Design tool?
It only generates the code for the structure, if you just remove all the x,y comments and the other generated comment, no one can then say that you did not do it yourself.
you can even rename all the audio connections to something else.
I don't encourage you to cheat, but in this case it's just about learning how the structure works.
 
Status
Not open for further replies.
Back
Top