Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 13th December 2007, 05:18 PM   (permalink)
Experienced Member
Fred.Amoson is on a distinguished road
Default Capturing and reproducing audio with a PIC

Hello,

I am trying to capture the audio waveform from a cheap toy, and reproduce it with a PIC. The sound I am trying to capture is about a second long.

Right now I have the toy speaker output hooked up to an input of the PIC, and the actual speaker of the toy connected to an output of the PIC. For the code I am just using "output = input" and it makes an acceptable reproduction of the sound. Is there a way to capture this sound on the PIC, save it, and play it back at a later time?

Ideally I would like to capture the sound (series of 1s and 0s) to RAM, then save to EEPROM, then pull the data from the computer and add to the code of a PIC to reproduce the sound when I wanted to.

Right now I am limited by the small amount of RAM on the PIC. I was thinking that maybe instead of capturing the data straight, and outputting straight, I could instead capture the time between a 0 and 1, and 1 and 0, basically just capture the delays?

Please let me know if you have any bright ideas! I will continue messing with it.
Fred.Amoson is offline   Reply With Quote
Old 13th December 2007, 05:28 PM   (permalink)
Experienced Member
 
dknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to behold
Default

By your description (all this talk about 1s and 0s), it sounds like you are trying to reproduce a square wave...and nothing but a square wave. To Reproduce a sound you need more data than that. FOr example, 8-bit values sampled consecutively in time. Sound is more than just high or low (1 or 0).

FOr example if I wanted to reproduce a tone (sin wave) I would store a bunch of 8-bit values at different points in time, each value being the magnitude of the sinusoid at that point in time. You may need to use some other form of external memory...
dknguyen is offline   Reply With Quote
Old 13th December 2007, 05:30 PM   (permalink)
Experienced Member
Fred.Amoson is on a distinguished road
Default

You can certainly make a sound with a square wave. The toy is cheap, and makes the sound with a square wave. So that is all the PIC needs to do.
Fred.Amoson is offline   Reply With Quote
Old 13th December 2007, 05:35 PM   (permalink)
Experienced Member
 
dknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to behold
Default

I still don't see how it would work, but assuming that is the case, then you'd have to try both methods and see which one takes less memory. Since the period of time would have to be stored as a byte (or so), and if there are enough transitions during the sound then you could be using up to 8x more memory than if you went the other way. Or you could filter out transistions that are too short to reduce the number of transistions in the sound to reduce memory size.
dknguyen is offline   Reply With Quote
Old 14th December 2007, 12:11 AM   (permalink)
Experienced Member
 
mramos1 is a jewel in the roughmramos1 is a jewel in the rough
Default

Took a bit to find this, but some reading.

http://www.romanblack.com/picsound.htm
mramos1 is offline   Reply With Quote
Old 14th December 2007, 04:42 PM   (permalink)
Experienced Member
Fred.Amoson is on a distinguished road
Default

Thanks for the suggestion. I found that link a while ago, but didn't look into it too much. After you suggesting it, I looked into it some more, and it is actually exactly what I need. Thanks!
Fred.Amoson is offline   Reply With Quote
Old 14th December 2007, 05:00 PM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

What is the actual audio you're trying to capture?, originally I presumed you needed analogue to digital conversion and storage, for an analogue audio signal. But then it seemed like it was a simple digital 'beep' type noise, where you could easily duplicate it without any analogue techniques.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 14th December 2007, 05:40 PM   (permalink)
Experienced Member
Fred.Amoson is on a distinguished road
Default

It is a beep, but is is a weird beep that I could not figure out how to duplicate with just a simple coded square wave. Using Roman's audio program I have been able to make an acceptable copy of the sound, but it takes up a lot of room.

I've attached a .wav of the sound, have a crack at it and see if you can duplicate it, if you want. Remove .zip, it isn't a zip file.
Attached Files
File Type: zip firstbeep.wav.zip (9.1 KB, 15 views)
Fred.Amoson is offline   Reply With Quote
Old 14th December 2007, 06:08 PM   (permalink)
3v0
Moderator
 
Blog Entries: 3
3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold
Default

You can make a lot of interesting sounds by banging on a pin. What is so special about this sound. If it is for a toy you should have some creative wiggle room.

A for loop with a math function to determine freq can be fun.
3v0 is offline   Reply With Quote
Old 14th December 2007, 06:10 PM   (permalink)
Moderator
 
Blog Entries: 1
Krumlink is a glorious beacon of lightKrumlink is a glorious beacon of lightKrumlink is a glorious beacon of lightKrumlink is a glorious beacon of lightKrumlink is a glorious beacon of light
Send a message via Skype™ to Krumlink
Default

The .zip is corrupted. Upload it to the forum as an audio file
__________________
MechTronics
Krumlink is online now   Reply With Quote
Old 14th December 2007, 06:15 PM   (permalink)
Experienced Member
Fred.Amoson is on a distinguished road
Default

Quote:
Originally Posted by Krumlink
The .zip is corrupted. Upload it to the forum as an audio file
It's not a zip. It's a .wav, like I specified in my above post.
Fred.Amoson is offline   Reply With Quote
Old 14th December 2007, 06:16 PM   (permalink)
Experienced Member
Fred.Amoson is on a distinguished road
Default

Quote:
Originally Posted by 3v0
You can make a lot of interesting sounds by banging on a pin. What is so special about this sound. If it is for a toy you should have some creative wiggle room.

A for loop with a math function to determine freq can be fun.
There is nothing special about the sound, it is just a fun task to try to reproduce it as best as possible.

I did what you mentioned with a for loop a while ago, and never found a frequency that sounded like I wanted it to.
Fred.Amoson is offline   Reply With Quote
Old 14th December 2007, 06:31 PM   (permalink)
Experienced Member
 
dknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to beholddknguyen is a splendid one to behold
Default

Quote:
Originally Posted by mramos1
Took a bit to find this, but some reading.

http://www.romanblack.com/picsound.htm
Oh! You were talking about PWM+LP DAC! I guess that could be considered a series of 0s and 1s, or a bunch of HIs and LOs of varying delays. It just never registered in my head when it was worded the way it was because I think about it as PWM, hehe. I get your drift now. I was thinking you were driving a speaker directly with a square wave and scratching my head how it would be able to make tones and stuff. But the memory thing I said above still applies.
dknguyen is offline   Reply With Quote
Old 14th December 2007, 06:32 PM   (permalink)
New Member
Fire_Leon is on a distinguished road
Default

did u get this working man? im really interested in this audio rec and play issue but i dont really understand how to reproduce the tables, or how to connect the outputs to the speaker, if some one could explain that for me i would thank you a lot, really, thanks ^^
Fire_Leon is offline   Reply With Quote
Old 14th December 2007, 08:21 PM   (permalink)
Experienced Member
 
mramos1 is a jewel in the roughmramos1 is a jewel in the rough
Default

dknguyen, I had to read it a couple times myself before I got it.

Fred, post the project (code at least) when you are done. I too have thought about doing it and never did. I recalled that site from way back, was hard to find. But it is a neat idea for sounds from the pic/uC.

Also, the bit bang might be fine. I did that with the old TRS-80 way back. It did not sound great but was clear enough.
mramos1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 02:14 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.