How to get simple sounds?

Hi,
I guess this is a very common noob question but I am not able to Google any hint.

In many cheap toys doing sounds there is a piezo speaker and a chip that drives the piezo with a square wave. Depending on application they are able to do a lot of different sounds such as playing a melody, animal sounds or various beeps. In general I think I understand how to generate such sounds in Arduino using tone() function. I do not know where to find templates for those sounds. I can imagine how to rewrite a song when given sheet of music. It would be time consuming - I am sure someone did it before. Moreover I do not know what tones and how long to play for to get i.e. sound of a bird or a barking dog. Is there a file format encoding monophonic sound that has encoding usable with Arduino - note & duration? When I tried to Google for monophonic sounds I managed only to find old phone ringtones but even those are in MP3.

In general I think I understand how to generate such sounds in Arduino using tone() function. I do not know where to find templates for those sounds. I can imagine how to rewrite a song when given sheet of music.

Right. See the [u]Play Melody Example[/u].

It would be time consuming - I am sure someone did it before.

Yes it's time consuming. If it's something popular like "Happy Birthday", it's probably been done.

There is something called [u]MIDI[/u]. A MIDI file is a standardized file-format for "notes & timing" (and some other information). (I call it "sheet music for the computer".) You can find TONs of MIDI files on the Internet and there is a MIDI library for the Arduino. But, most of the MIDI files you find are polyphonic and multi-instrument and that takes more hardware & software (more than an Arduino & piezo transducer). And since it's a computer file, a computer is usually involved or you need a way to store & read the file. (i.e. A MIDI keyboard usually has memory, and/or it can read a USB thumb drive, etc.)

Moreover I do not know what tones and how long to play for to get i.e. sound of a bird or a barking dog.

That's not a square wave like tone(). You'll need an audio shield, which has a DAC, memory for the audio files, a clock for the digital audio, and a chip that can read the file and sometimes decode MP3, etc. (These shields/boards can generally operate without an Arduino. The Arduino is just a "controller" to select the sound file and start/stop the sound, etc.)

There is also a library called [u]TMRpcm[/u] that can read files from an SD card and simulate a DAC with fast PWM.

Thank you!
I will look into the MIDI format.

To the dog barking: I don't want nice sound of real dog barking. I mean the sound super cheap toys do. Only because the toy looks a bit like a dog you may guess it should be barking. But other sounds should be more easily done - for example our cat has a mouse toy that squeaks when touched. The chip was flawed (sometimes got stuck doing endless pitch) so I recorded the sound, found that it is made by a simple sequence of decreasing frequencies and replaced the chip with an ATTiny doing the same sound. It woks well except for the mouse is no longer interesting for the cat... So I believe other "more melodic" sounds should be quite well created with mere square waves (birds, cat, maybe a cow).

Good luck with that. Most cheap toys that I've seen use a dedicated sound chip with the sounds already encoded on it. I can't imagine anything even resembling a bird sounds from just square waves without some clever modulation but if you do get anywhere I'd like to hear your results.

Steve