Using AVR for simple sounds

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

Has any one built a model railroad Crossing Signal "with sound"

The "DING-DING" Bell sound is all that's needed..

Actualy just one DING.. as it would be repeated.

I have no clue how to do it, other than I would be using the "PWM" output.

Any links to info on creating self produced
realistic sounds on AVR's would be a help.

Thanks

"We look for things.. Things that make us go."

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

AVR335

To see what that can develop into see:

https://www.avrfreaks.net/index.p...

but sadly the hosted pictures I had in that thread have disappeared on a webserver that no longer exists :-(

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

Well, I've found how to make a "Pop!" but only once.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

Bell sounds have two or more tones, close together in frequency. They decay with time similarly. This article about big bells gives some details. While signal bells are very small, the acoustic principles are the same.

http://www.russianbells.com/acou...

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Search for a ding sound effect, find a waveform editor that can read and save any wav format... try 8 bit mono, 22.050KHz sample rate. There are several wav2c programs here somewhere that will read in the binary wav file and spit out a big initialized array that can be compiled into the c program. Read the samples from the array and write them to the OCR register that you have setup for 8 bit pwm 22KHz sample rate.

Imagecraft compiler user

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

I forgot to mention Roman Black's 1-bit sound which is probably how I'd do it these days.

http://www.romanblack.com/BTc_al...

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

Thanks for the links guys
they will be a great start..

1 bit sound is what I hope for.. but we will see
how nice it sounds for this project.

Was planning to use a ATiny85 at most.

But if a Resistor Ladder is needed that's OK also.

Thanks Again.

"We look for things.. Things that make us go."

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

You could use for example FM synthesis to generate the sound - you just need to tune the parameters of the sound and let it run.
The point is, you generate a tone (sine, but do try square or triangle so you can omit sine lookup table), and you modulate the tone frequency based on another tone, which creates harmonics. Bell sounds should be extremely good to generate with FM.

After you have some audio data to output, you can output it via PWM or R2R DAC.

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

Jepael wrote:
You could use for example FM synthesis to generate the sound.

Do you have an example of this method ??

"We look for things.. Things that make us go."

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

maybe try this

Attachment(s): 

Imagecraft compiler user

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

bobgardner wrote:
maybe try this

Wow !! did you just slap that one together..

You didn't have to do that.. (I'm not worthy)

I'm lost with "C", so it will take
me some time to understand it all..

I guess this is coded for.
Mega 32 (Type) in your remark at the top

I assume 1 bit ??? (But not sure)..

And I'm confused with what looks like rs232 setup.
(why is that needed ?)

Or is that for loading (Sound) data into ROM. ??

I'll guess you tryed it..

Does the "Ding" Sound nice to you. ??

"We look for things.. Things that make us go."

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

Jepael wrote:
You could use for example FM synthesis to generate the sound - you just need to tune the parameters of the sound and let it run.
That seems like very bad advice to me. The OP says he has no clue about audio and you're recommending that he design, develop, and tune an FM synthesizer. Just tuning one of those things is an art all by itself.

Stick with sample playback. It's simple.

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

I searched for "train crossing sound effect". I used goldwave to take 8 of the dings (whole file was dozens of them) and saved it as dings.snd, then used a program I wrote called pcm2c.exe to convert it to an initialized array (down at the end of the file). I can post the vc6 c source to the pcm2c program if anyone is interested. It must be on freaks here somewhere from a couple years ago. If you dl the imagecraft compiler and make a project and add this file to the project it should compile. I play these sounds right from the OC2 output with an rc filter. Choose an RC to give a freq about half of 11025hz. Formula is f=1/(twopi*rc) and I play it into a 32 ohm speaker so it doesnt load down the avr output. I have an ereshop mega32 board. Most of my programs use the serial port to run the test subroutines one at a time. Look down at the end of the c file in main... see the menu? See the switch where I use r for raw?

Attachment(s): 

Imagecraft compiler user

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

Just for testing, OK I'll just disregard RS232 code then..

And nice that it's single bit on an (OCx) Pin
No problem with rc filter, (Thanks for the Fomula)

I plan to use a Audio Amp so no problem with
loading the AVR..

Wish I was set up to test it... (Right Away)

I'll try to find your pcm2c.exe .. for future use.

And if the up-loaded "Wav" - as Text, is what it sounds like.. "Can't get any better than that."

Thank's again Big Time.

"We look for things.. Things that make us go."

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

MurMan wrote:
Jepael wrote:
You could use for example FM synthesis to generate the sound - you just need to tune the parameters of the sound and let it run.
That seems like very bad advice to me. The OP says he has no clue about audio and you're recommending that he design, develop, and tune an FM synthesizer. Just tuning one of those things is an art all by itself.

Stick with sample playback. It's simple.

True, sample playback is simpler, but the sample must be stored somewhere.

FM synth and tuning does sound complex, but in the end, it is nothing more than a DDS synthesizer creating an arbitrary waveform like sine with fixed frequency using lookup table, and then, there just is another DDS synthesizer, whose output then modifies the frequency of the first DDS synth.

Most likely the code takes less space than what is needed to store the PCM wave data.

If more info is needed, wikipedia has great article and links on FM.

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

Jepael wrote:
True, sample playback is simpler, but the sample must be stored somewhere.

FM synth and tuning does sound complex, but in the end, it is nothing more than a DDS synthesizer creating an arbitrary waveform like sine with fixed frequency using lookup table, and then, there just is another DDS synthesizer, whose output then modifies the frequency of the first DDS synth.

Most likely the code takes less space than what is needed to store the PCM wave data.

If more info is needed, wikipedia has great article and links on FM.

Thanks I'll check Wikipedia, I hope it will be simple enough for me to apply to AVR
or with some code examples for either PIC's if not.

"We look for things.. Things that make us go."

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

Torby wrote:
Well, I've found how to make a "Pop!" but only once.

Now was that an Intentional sound or was it
the sound the chip made when it blew up :)

"We look for things.. Things that make us go."

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

Did you listen to the train.wav file yet?

Imagecraft compiler user

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

bobgardner wrote:
Did you listen to the train.wav file yet?

Yes.. Thanks (Sounds Great)

Now comes the Hard part.

Making the LED's blink :D

"We look for things.. Things that make us go."