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.

Play a WAV sound using a PIC?

Status
Not open for further replies.

davepusey

Member
Is it possible to save a WAV sound onto a pic and write a program that loops it when a specific input is high. The sound would have to be stored digitally in the EEPROM i suspect and use a DAC to output it. If it can be done i would like some help in doing it please.
 
davepusey said:
Is it possible to save a WAV sound onto a pic and write a program that loops it when a specific input is high. The sound would have to be stored digitally in the EEPROM i suspect and use a DAC to output it. If it can be done i would like some help in doing it please.

EEPROM is fairly slow, you would probably be better storing it in tables in program memory - how many bytes are you talking about?.
 
The file is 0.877 seconds long. I've encoded it into a WAV as small as possible without losing quality and it is now 9,724 bytes at 11,025hz 8bit mono.

What i wanna do is output it (looped) to a minature speaker (on of those little 8ohm jobs) so that it only plays when a specific input pin is sent high.
 
davepusey said:
The file is 0.877 seconds long. I've encoded it into a WAV as small as possible without losing quality and it is now 9,724 bytes at 11,025hz 8bit mono.

Far too big for program memory, I should check how fast you can read serial EEPROM's, reading is a lot faster than writing them - but at 11,025Hz you need to read and output a value every 90uS.
 
Use a pic18 with more program memory...
Or use parallel eeprom...

What are you trying to do? This isn't really what a pic was meant to do, maybe there's a better solution
 
Exo said:
What are you trying to do? This isn't really what a pic was meant to do, maybe there's a better solution

Well it dificult to explain but i do need to use a PIC. How do i store the WAV data and how do i make it play looped only when input is high?
 
Well, you store data as a set of RETLW commands, but each RETLW is a instruction word, and you need 9724 of 'em. So you'll need a pic with more then 9724 program memory words. That's only available in the PIC18 series...

Another solution would be parallel eeprom. Eeprom is fast enough for this, but it is the serial link (I²C for example) that makes it slow. Parallel eeprom can be read 'instantly' but, of course, takes up a lot of IO pins.
 
USE MP3 or midi

if you use a MP3 file or midi file..!!

i'm sure it will be easyer for you and better suiting you needings..


and there are a hole bunch of projects on the net whit that..

TKS
 
:idea:

I have had a quick look at your code (in another thread), as you are only using a cheap 8ohm speaker job, why not resample the audio to a lower bitrate?

Can you not get the pic to generate this alarm sound (or V.similar) as an alternative?

I know I you are going against the "established" way of doing things, and I applaude you for this, don't give up on it..... Yes it's "easier" to do this other ways, but then it's "easier" to go and buy an alarm buzzer for £2.50ish from Maplin (<UK electonics shop).

You will learn alot more by attempting this than giving up, you may fail, but at least you will understand why.

I feel some backlash coming on :wink: .........

Another thing to look at in your code...... if you look at the data, a lot of the numbers are very similar, if you change tactic slightly..... instead of reloading portb every sample, why not "add" or "subtract" a value from it..... the reason?? Well look at the values, you can (almost!!) add or subtract not more than 16 from each value to achive the next "sample" this means you can store 2 "samples" in each lookup element, this will halve you lookup size.......

Another "poormans" DAC can be made, with a saving on code space by shifting the data out of 1 pin, to a resistor/cap network, the more "1's" the voltage rises the more "0's" the voltage drops....... just food for thought really!!! :wink: Go for it!! :lol:

I hope I have "re-inspired" you, good luck, let us know how you get on!
 
Re: USE MP3 or midi

TKS said:
if you use a MP3 file or midi file..!!

A midi file can only contain musical instruments, and you need a special midi chip to make it sound acceptable.
An MP3 would require an mp3 decoder, wich makes the circuit and code much more complicated.

Surely, just using a parallel eeprom is a lot simpler then all these solutions.

This one for example AT28HC256 is 32Kb large (thats more then 3 times what you need), from atmel https://www.electro-tech-online.com/custompdfs/2004/05/doc3446.pdf

You find a lot of these on harddisks (or a similar SGS device).
The ones on harddisks are usually PLCC (smd), but there are sockets for these the convert the pinning to normal spacing

A pic16F could do the job easy this way, the only thing your pic needs are enough pins... though, you could always use a set of simple 4094 shift registers to drive the address lines, this way you would only need a pin or 3 for the address in stead of 14...

Ad if you add a serial interface to your pic it will be easy to connect to a pc com port to download new sound samples
 
MIDI

i don't know how good the quality has to be but..

i know that you can convert midi files to data arrays..

and that when you hear that you recognize the song..

soow..

it should be possible to do..

TKS
 
...

i just sample some serial memories but instead of 400Khz..

they have 3Mhz..soow that could boost the read speed i think..

i sample some SPI from microsoft..

25xx etc..offcourse biggest...


TKS
 
Matt(Pic progger) said:
:idea:

I have had a quick look at your code (in another thread), as you are only using a cheap 8ohm speaker job, why not resample the audio to a lower bitrate?

Resampling to a lower bitrate causes sound to become distorted. I have it at the lowest i can get it.

Matt(Pic progger) said:
go and buy an alarm buzzer for £2.50ish from Maplin (<UK electonics shop).

That's all very well but i need the exact sound featured in that WAV file. The sound is from end of 24 Season 3 Episode 14 (2am to 3am) when nina myers escapes and the building is locked down.

Matt(Pic progger) said:
Another "poormans" DAC can be made, with a saving on code space by shifting the data out of 1 pin, to a resistor/cap network, the more "1's" the voltage rises the more "0's" the voltage drops

Yes, I saw that idea at **broken link removed** and wanted to use that method, but his encoder program freezes when i try to run it. Both on my XP2500 running xp pro and my p100 running 98. If you know how to get it to work i would be very very very very grateful.
 
davepusey said:
Matt(Pic progger) said:
:idea:

I have had a quick look at your code (in another thread), as you are only using a cheap 8ohm speaker job, why not resample the audio to a lower bitrate?

Resampling to a lower bitrate causes sound to become distorted. I have it at the lowest i can get it.
quote]

I agree with Matt, I don't think reducing the sample rate would have any detrimental effect on the sound - it's basically only a 'beep' anyway 8)
 
Nigel Goodwin said:
davepusey said:
Matt(Pic progger) said:
:idea:

I have had a quick look at your code (in another thread), as you are only using a cheap 8ohm speaker job, why not resample the audio to a lower bitrate?

Resampling to a lower bitrate causes sound to become distorted. I have it at the lowest i can get it.
I agree with Matt, I don't think reducing the sample rate would have any detrimental effect on the sound - it's basically only a 'beep' anyway 8)

Well it aint just a beep. I will see if i can get it down any further with some tweaking. Also, i got that encoder to work. You have to go into pure dos (boot disk) to do it. Not dos within windows. But even with the encoder the code is far to long.
 
I've just been fiddling with the WAV file and have managed to get it down to a bitrate of 8,000Hz. File size is now 7,070 bytes. Is that small enough to fit onto a 16F84A? If i take it below 8000 Hz the sound doesnt sound how i want it.
 
Like i said before, 16F84 only has room for 1024 instructions...

7070 bytes would fit into a 16F876 with some thinkering, but then again, the 16F876 has enough pins to use external eeprom...
 
Exo said:
Like i said before, 16F84 only has room for 1024 instructions...

7070 bytes would fit into a 16F876 with some thinkering, but then again, the 16F876 has enough pins to use external eeprom...

Dont want an external eeprom. That adds cost, complexity and more components to project.

EDIT: Does the 16F876 have an 8-bit digital to analog convertor output?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top