Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Capturing and reproducing audio with a PIC

Status
Not open for further replies.

Fred.Amoson

New Member
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.
 
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...
 
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.
 
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.
 
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!
 
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.
 
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.
 

Attachments

  • firstbeep.wav.zip
    9.1 KB · Views: 280
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.
 
The .zip is corrupted. Upload it to the forum as an audio file :D
 
3v0 said:
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.
 
mramos1 said:
Took a bit to find this, but some reading.

https://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.
 
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 ^^
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top