How to make sounds

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a project where I want to make little melodies (like a Nokia phone). My knowledge about sound is low so I need help.

1. Does anyone have example software written in C or assembly for AVR?
2. What components should I choose in my design. It mst be small, inexpensive and use very little power (battery driven).
3. Links to similar projects are appreciated.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi

check e-lab avrco compiler

is a pascal compiler tha have a nice sound driver

whit full of fonctional sampel

a frre demo version is douwnlodable from ther web site

marc lalone
alphatronic

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

In the "stock" designs the Apple II series computers, and the IBM PC both just used a single bit of i/o and a buffer tied to a small speaker for sound.

At the time there were many programs floating around for the Apple to make complex sounds and even 'speech' if you can call it that from the speaker. The bios listings (yes they are out there in print), or just poke around in your pc with debug provide a more general purpose single tone based system. I have seen code that can actually simulate harmony (more than one note at a time) as well.

Basically you generate a square wave with the output pin at the fundamental frequency of the note you want to reproduce. For harmony, you pretend to generate multiple versions of this at different frequencies, but internally you sum them before outputting the result on the pin.

For single tones a starting point is output the counter overflows, and just program the divisor latch for frequencies in the audible range.

Cool add-on : Add some capacitors, resistors, chokes, active filters, etc between your output bit, and the speaker and instead of a nice clean square wave, you'll get a more shaped wave that sounds more like an instrument and less electronic.

Also note, a normal speaker has a magnetic voice coil, and a piezo speaker looks more like a capacitor in the circuit. So those elements alone will somewhat filter the pure square wave coming from the i/o pin, and make it sound different.

Cool add on #2 - make a weighted binary d/a with 2 bits of output, and some resistors. This helps a lot when summing waves for harmony. It also makes more shapable waves since you have more than just on/off.

Have fun.

Be nice to see something like this posted as sample code. I may even do it since this seems to be a bragging point on the PIC series, and is not mentioned at all by Atmel that I have seen.

Note: there are more complex ways to do this as well, such as single bit d/a pulses, but in general the code is far more complex, and so is the external circuitry, but it can still be done.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> 3. Links to similar projects are appreciated.
Hi Blake,

I did something similar in a lab assignment. Try http://instruct1.cit.cornell.edu...

Also check out past final projects at
http://instruct1.cit.cornell.edu...

Hope this helps!

eseah

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Blake,

The ATTiny15 is an AVR 8-pin micro. I bought 50 for $1.25 ea. It has an onboard clock, a few AtoD's, and a PWM. It can be used to record sound and play it back. I heard, from someone at Atmel, that there is sample code from Atmel to make this work. I haven't found it yet. Let me know if you find it.

This part should satisfy your criteria.

Scott Pierskalla

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Blake,

I found what I was looking for. See Atmel's AVR335 app notes on how to make sounds. Goto http://www.atmel.com/atmel/acrob...
Perhaps you could scan the code and use it instead of typing it all.

Scott Pierskalla

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Blake,

I wasn't thinking. You can copy and paste from the pdf file instead of typing it all.

The app note uses a different micro than the ATTiny15, the AT90S8535 which runs at 8MHz. I believe that the ATTiny15 can do the job. It has the necessary inputs, outputs, and flash. However, it has it's own internal clock which runs at 1.6MHz (nominal) which is 1/5 the speed of the 8535. This means that you'll need to modify the code to work at the lower clock frequency. To sample at 8K, use 1.6M/200=8K instead of 8M/1K=8K. Besides changing the code for the different inputs and outputs, I'm not sure what else you'll need to do.

You may want to start a new topic asking if anyone has changed code from AVR335 for use with the ATTiny15. If so, a good portion of your work is done.

Scott Pierskalla

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, one thing that comes to mind from the good old days of DOS and lack of sounds in PC is the COVOX SOUND THING. Basically, a D/A conversion from the LPT port for PC.

This should be trivial to attack to an 8-port on an AVR, and play back 8-bit samples. Heck, you can even have 16-bit stereo if you want (Just connect 4 ports) -- the problem is how to connect memory for samples.

Anyway,8-bits should give you decent sound. Lets say, with 2Mbits of eeprom on the STK-500, 8-bit sampling, at 8kHz, and some compression, say we get to 16kbit/s data --> You easily get about 2 minutes of samples into the standard proto board.

If you REALLY work on compression, it should be possible to squeeze about 4 times more with some effort.

If you are really into hard-core sound compresson, with with some spectral analysis, etc, and are willing to drop the bitrate a bit, you could probably squeeze considerably more.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel has some application code for MP3 decoding. It is one of their development tools. I haven't located it yet. It would be good for several minutes or hours of music.

Scott Pierskalla

admin's test signature