PDA

View Full Version : Solved Looking for example where Propeller can monitor audio frequency and volume.



RobotWorkshop
11-18-2011, 03:04 PM
I think I've seen something similar in the forum before but don't recall exactly where....

I want to use the Propeller to monitor an audio (line level out of a laptop sound card) to read the approximate frequency of the audio signal and also the volume. At the very least just the volume level. I have a Propeller acting as the co-processor on a new robot and it is handling all the lighting effects on the robot. If the Propeller can monitor the audio signal I can use the values for the frequency and volume to help control the lights.

If you know of any similar examples or have seen them in the forum please let me know.

Robert

Bobb Fwed
11-18-2011, 04:12 PM
I created and use this object in a number of projects. It can measure the frequency and amplitude from an input on a microchip ADC. I've never used it for audio, but the sample rate is fast enough to use it for that. I would recommend a 10-bit ADC (MCP3008/4/2/1), since it will sample a fair amount faster than the 12-bit counterparts. The object allows you to alter the precision vs. speed of the frequency measuring and manage noise compensation by reducing the maximum frequency the object will detect. Keep in mind, if the audio source is more than a well defined single frequency (like a single tone), there might be issues tweaking it to get the value you want.

http://obex.parallax.com/objects/488/

Phil Pilgrim (PhiPi)
11-18-2011, 04:27 PM
If it's any help, my Goertzel object can monitor audio volumes in eight frequency bands simultaneously. The zip in the following link includes an Excel spreadsheet that lets you adjust and visualize the passbands:


http://forums.parallax.com/showthread.php?119568-Propeller-DTMF&p=876749&viewfull=1#post876749

-Phil

RobotWorkshop
11-18-2011, 06:10 PM
Thank you both for the suggestions. I think that either method will may work for me. I've already installed an MCP3208 chip on the board which still has most of the inputs open so that may be the best option since I won't have to use up any extra Propeller pins. If I didn't have that then I think the code from the thread that Phil suggested would be the best option.

I really don't need a ton of accuracy on this. I'm just going to use the data to control a set of 7 LED's used as the mouth display on a robot. There are 32 LED's on the head that the Propeller is controlling (as well as 20 on the body, head movement control, and other misc functions. I want the Propeller to monitor the audio line so it can control the lighting on the mouth LED's depending upon the volume and frequency. I'd just like it to look like it is talking when it is talking. All of the speech is generated from the laptop that is running the overall robot.

Since I am much more comfortable working on the digital aspects of the wiring do either of you happen to have an example schematic on how the MCP3208 chip or Propeller would be wired to monitor the Audio line?

Robert

Bobb Fwed
11-18-2011, 06:34 PM
I use something very similar for a high impedance input (I also put a 3X gain using the opAmp), but for anything that has more than a couple hundred ohms of impedance on the input, you'll likely want to run it through an opAmp as a voltage follower (like I show).

86989

I'm not sure what the impedance is on a headphone jack, or the voltage swing, or if you are planning on having the jack going to another audio output... so that information would help a bit.

RobotWorkshop
11-18-2011, 06:43 PM
I am going to take the audio output line from the laptop. I have a small Y adapter that will plug in the back of the laptop computer. One will go to the amplified speakers on the robot and the other can go to the Propeller board. I think it should work.

Robert

RobotWorkshop
11-18-2011, 08:49 PM
I use something very similar for a high impedance input (I also put a 3X gain using the opAmp), but for anything that has more than a couple hundred ohms of impedance on the input, you'll likely want to run it through an opAmp as a voltage follower (like I show).

What is the # of the OpAmp that you are using in the schematic? I think there is still room on my protoboard where I can add one.

Robert

Bobb Fwed
11-18-2011, 09:45 PM
I'm using TSV914IPT, but that is surface mount only.
Here are a couple that should function the same: 2CH: MCP6282-E/P or TLV2772CP -- 4CH: MCP6284-E/P or TLV2774CN

RobotWorkshop
11-22-2011, 02:54 PM
Hello Bob,

Do you think something like a TL082/TL082CP Wide Dual JFET Input Op Amp would work instead? I have a couple of those on hand. I probably also have many of the older classic op-amps in the junk drawer too. If possible I'd like to use a common part and one that I may already have here.

Robert

Circuitsoft
11-23-2011, 02:15 AM
Looks like the TL082 won't work well below +/-6v (12V total), so I wouldn't count on it unless you have a high supply voltage available.

Notes on Audio Op-Amps (http://tangentsoft.net/audio/opamps.html#072)

tdlivings
11-23-2011, 03:17 AM
Robert
OPA350 will work, in fact has way to much bandwidth so you will want to limit it with that part.
It fits the voltages however.
Also the Lm324 and Lm358 and the other versions in that family.

I would run the op-amp off of the 3.3 supply and for the bipolar type of parts you will need to
reduce the 2.2M divider resistors down to like 22K and raise the coupling cap to 10uf.
220K's and 1uf if the offset caused by input bias currents does not bother you.

The ref for the A/D would now also be 3.3v, I am assuming this part Ref is an input and not
the A/D putting out a Ref which is about a diode drop below it's supply. I am not sure why
the 2.5 volts in Bobb's circuit, but am open to learning.

From what you describe your not looking to make a high quality audio preamp just detect
audio range signals to light some led's so you do not need audio grade op-amps , anything
will do as long as it works down to 3.3v

Tom

RobotWorkshop
11-23-2011, 03:53 AM
Hello Tom,

I just found some LM358 chips and they may be a better choice for this circuit. I'm going to try and wire it up to see how it reacts and if I can get a reading on the propeller. Since it is a dual unit I can wire up the same thing for the other channel so I can pickup any sounds on that one too.

Thanks for the suggestions.

Robert

frank freedman
11-23-2011, 06:07 AM
Hello Tom,

I just found some LM358 chips and they may be a better choice for this circuit. I'm going to try and wire it up to see how it reacts and if I can get a reading on the propeller. Since it is a dual unit I can wire up the same thing for the other channel so I can pickup any sounds on that one too.

Thanks for the suggestions.

Robert
Yes and single supply 3-32v.. for those less lucky nte928 is the cross on that one.

Bobb Fwed
11-24-2011, 04:22 AM
Sorry, I don't have time to input too much here (vacationing and all), but I use 2.5V because I use the ADC for some high precision measuring. So I have a 2.5V precision reference voltage supply that I also run the OpAmp off of because I don't want the outputs to run higher than the ADC reference. 4.096V references are more common, but then you need to run that circuitry at 5V.

RobotWorkshop
11-25-2011, 02:28 AM
Still no luck monitoring the audio signal. As far as I can tell I have the MCP3208 ADC chip wired up properly. As a control I connected some of the other ADC channels to +3.3v, ground, etc and I can get readings that I expect on those channels.

I'm trying to use a LM358 since I had some spares on hand. It is running at 3.3V. I'm bringing the left and right channels to the chip and then the outputs from there to channel 0 and 1 on the ADC chip. I've tried a couple different resistor/cap combinations but I can't seem to pick up anything yet. The most recent was two 22K ohm resistors with 10uf cap. I'm going to re-check all my wiring on the LM358 again in case I've overlooked something.

I may have some other op-amps if anyone happen to know of others with the same pinout and would operate on a single 3.3v supply. That chip is in a socket so it is easy to swap out.

I'd really like to get this working over the weekend if I can.

Robert

frank freedman
11-25-2011, 04:15 AM
Still no luck monitoring the audio signal. As far as I can tell I have the MCP3208 ADC chip wired up properly. As a control I connected some of the other ADC channels to +3.3v, ground, etc and I can get readings that I expect on those channels.

I'm trying to use a LM358 since I had some spares on hand. It is running at 3.3V. I'm bringing the left and right channels to the chip and then the outputs from there to channel 0 and 1 on the ADC chip. I've tried a couple different resistor/cap combinations but I can't seem to pick up anything yet. The most recent was two 22K ohm resistors with 10uf cap. I'm going to re-check all my wiring on the LM358 again in case I've overlooked something.

I may have some other op-amps if anyone happen to know of others with the same pinout and would operate on a single 3.3v supply. That chip is in a socket so it is easy to swap out.

I'd really like to get this working over the weekend if I can.

Robert

Can you post schematic of analog ckt? Also, what is your sample freq ? By expected values on 3.3 and gnd you mean FFF and 000? Thinking on this as I write, need to see the input analog ckt gain too high hitting rails no values in between?

Bobb Fwed
11-25-2011, 04:15 AM
Don't forget this circuit will only shows you a change in voltage on the input. So unless you are taking continuous samples, you may continue to get the same result. The normal value you get (without changes) should be around 2048.

RobotWorkshop
11-25-2011, 04:16 AM
I think I found a small wiring error on the negative input of the op-amp. Going to re-wire that and give it another shot. Each channel has a different set of resistors and cap so I can see which one works best.

Robert

RobotWorkshop
11-25-2011, 12:02 PM
I have it working! There were two issues. First was a wiring error. I had the - input of the op-amp going to ground instead of tied to the output of the op-amp. Once I did that I could see a little movement on the adc but most of the time it was hovering around 0 which didn't seem right. After looking at examples of how others used the MCP3208 object I found a programming error. Initially I had been using the example from one of the Propeller books that used the MCP3208_fast object. At the moment I am just using the regular MCP3208 object. When I started the object the start parameter was -1. In other examples I found it showed 255 as the start parameter. Once I changed that to 255 I started getting what I expected out of it.

So, now all I need to do is tweak my code to get the effects that I want but so far it seems to work well.

Thanks to everyone for the suggestions.

Robert

RobotWorkshop
11-25-2011, 08:06 PM
Here is a picture of the wiring for the Op-Amp. It is a bit tight but everything fit. I'm using small surface mount resistors that fit between the ,100: pin spacing. There are also some larger 1206 surface mount parts on the back of the board for other sections.

87190

RobotWorkshop
12-12-2011, 04:21 PM
Here is a small video showing how I am using this on the robot. I still need to re-write the code to control the rest of the LED's but this is a good start. I may tweak the lighting for the speech but the initial effects are promising:

http://www.youtube.com/watch?v=3MTEQHUQRlQ&feature=youtu.be

http://www.youtube.com/watch?v=ExrksOLL3vc&feature=youtu.be

Robert

Bobb Fwed
12-12-2011, 04:52 PM
That's pretty cool.

Phil Pilgrim (PhiPi)
12-12-2011, 05:28 PM
Robert,

Wow! Can you tell us more about the speech recognition and generation?

-Phil

RobotWorkshop
12-12-2011, 06:32 PM
Hello Phil,

This is for an old Android Amusement DC-2 robot that I picked up. There was a write up on these robots in the latest issue of Robot Magazine. All of the original electronics had been stripped out (and thrown away) by the previous owner. I had to start from scratch on the electronics. It was originally a remotely controlled showbot but now it will be a fully autonomous robot that can be remotely controlled if desired. I'm using a Propeller to control all the lighting, some I/O, and control of a hacked Logitech Orbit MP camera. It can also display things on the touchscreen in the chest and I'll probably have the Propeller do a few other things as well. The robot never had a display for the mouth. I really thought it should have some so I built that mouth display from a piece of plexiglass. I was able to make it without drilling or altering the robot so I could undo it if I wanted to. I think it adds a lot so it will stay.

The main brain of the robot is running on a Windows XP based laptop. The laptop a bad LCD screen but I didn't care because that was being removed since a 10.4" touch screen in the chest of the robot would be used instead. The software is based on the software from the Leaf project:

http://www.leafproject.org/

It uses the Microsoft speech engine . None of the built-in voices seemed to fit so I bought one from:

https://www.cepstral.com/

It is pretty reasonable in cost for a license to use on an individual system. You can also tweak the effects to give it a more robot sounding voice.

The LISP code running on the laptop is looking for words it recognizes and will process them accordingly. Once I finish some of the hardware side of the project there are quite a few routines I want to add to the higher level LISP code.

I've been trying to take a lot of pictures along the way and am going to document the whole project. I just thought it would be cool to at least get a quick video up of the project so far. Still lots to do. It has been keeping me busy!

Robert