ringing sound

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

Hello!

I would like to interface a small speaker, with PWM. I need to generate some ringing sound for a door lock, so that it gives audible alert when it's open.

I was going to store a few samples (say 2K) as program memory, and than play that over and over again.

I don't know how to "generate" those samples. 2K ~ 0.25sec @ 8000 samples/sec, and when I tried to just play a wav file, you could hear when it started from the beginning...

If you know any good algorithm to generate such a sound (a fourier transform, or anything else), I would be very happy :)

Thanks,

axos88

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

Quote:

I don't know how to "generate" those samples. 2K ~ 0.25sec @ 8000 samples/sec, and when I tried to just play a wav file, you could hear when it started from the beginning...

Look for audio editors that allow for "looping" - I'm pretty sure Audacity must be able to do this for you - they arrange for the two ends to have an invisible meeting point.

EDIT the top Google hit for "audio loop editor" is:

http://www.audiofile-engineering...

(so you just have to find someone with a Mac - as audio studios tend to use Mac's you are likely to find most of these tools are for Mac)

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

I made some tunes myself on the butterfly using PWM, its not wav files but it plays tunes:

http://www.youtube.com/watch?v=Z...

It started off as a simple tone generator project (source here: https://www.avrfreaks.net/index.p...

The Smiley Micro site has some tune playing source code also.

Maybe you wanted wav files however, if thats the case then sorry

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

Are you aware of the possibility to produce simple monophonic melodies (think cell phones) with a few lines of code? You can loop that too if you like.

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

Thats what I posted above Lennart, with some basic functions its possible to create your own mono tunes like with the old Nokia key pad composer.

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

One of the most brilliant examples of waveform generation with AVR is found on this Elm Chan's page.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

MBedder wrote:
One of the most brilliant examples of waveform generation with AVR is found on this Elm Chan's page.

I wasn't aware of that project by Chan. Thanks for the link.

In the introduction he mentions/implies that there might be an advantage to using an AVR with a hardware multipleir, but a quick scan through the code doesn't have any multiplies that jump out at me. Perhaps it will be a different approach with the hardware MUL?

Anyway, that piqued my interest: What AVRs have high-speed PWM/PLL, and also hardware MUL?

A datasheet search indicates AT90PWMn have it. That is the only family I could find.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

There are some more AVRs which have both high speed PWM and multiplier:

MegaXXC1, MegaXXM1 (aka 90PWMxx4) - up to 64 MHz PWM timebase
MegaXXU4 - up to 96 MHz PWM timebase
XMegaA1/A3/A4 - up to 128 MHz PWM timebase.

BTW, Chan recently introduced another masterpiece - a Tiny25 SD audio player with virtually no extra parts. Besides, his FatFs and Petit FatFs are very compact and reliable file system modules which of course you and others are already aware of.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

Quote:

MegaXXC1, MegaXXM1 (aka 90PWMxx4) - up to 64 MHz PWM timebase
MegaXXU4 - up to 96 MHz PWM timebase

So those are really in the same "family" as AT90PWMn? I guess the "U" are the USB. Aren't the C1 & M1 the automotive models that normal people cannot find a few?

Quote:

XMegaA1/A3/A4 - up to 128 MHz PWM timebase.


Right, I knew the Xmega had the fast PWM. I was thinking of the "lower end" price range since Chan used a Tiny45. But thinking about it the smallest Xmegas are now on that "low end"--lesee, Xmega16A4 is the smallest around right? $4/1; $2.50/100. AT90PWM2 is $3/1; $1.75/100. Not 8-pin-compact, but less than $1 more than a Tiny45.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Here is an excerpt from the M1/C1 DS:

Quote:
Note: On the engineering samples (Parts marked AT90PWM324), the ACMPN3 alternate function is not located on PC4. It is located on PE2.

And yes, the U refers to USB family which fortunately have some members smart enough for not only USB.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

theusch wrote:

I wasn't aware of that project by Chan. Thanks for the link.

In the introduction he mentions/implies that there might be an advantage to using an AVR with a hardware multipleir, but a quick scan through the code doesn't have any multiplies that jump out at me. Perhaps it will be a different approach with the hardware MUL?

Lee, applying the envelope seems to be done with multiply operation.

But as always, in the expense of lookup table size, you can generate sound samples with log-transformed numbers, where multiply and divide operations are sum and subtract operations. Then when finally when linear PCM samples are needed, you run it through an exponent lookup table. This is how good old FM synthesizers on PC soundcards did it before wavetable was invented. It sounded just fine with 256-entry log-sin table and 256-entry exp table, both at around 10 bits per entry, less than uint16_t anyway.

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

Jepael wrote:
theusch wrote:

I wasn't aware of that project by Chan. Thanks for the link.

In the introduction he mentions/implies that there might be an advantage to using an AVR with a hardware multipleir, but a quick scan through the code doesn't have any multiplies that jump out at me. Perhaps it will be a different approach with the hardware MUL?

Lee, applying the envelope seems to be done with multiply operation.

But as always, in the expense of lookup table size, you can generate sound samples with log-transformed numbers, where multiply and divide operations are sum and subtract operations. Then when finally when linear PCM samples are needed, you run it through an exponent lookup table. This is how good old FM synthesizers on PC soundcards did it before wavetable was invented. It sounded just fine with 256-entry log-sin table and 256-entry exp table, both at around 10 bits per entry, less than uint16_t anyway.


Is there somewhere I could read more about this? Is the wavetable changed so that log values are produced? The changing of multiplication operations to addition I would think would result in a very significant performance increase.

It seems as if I need one table that is (I'll do a full cycle) the log (base?) of sin, and another table that is some exponential.

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

Quote:

Is there somewhere I could read more about this?

Did you follow the link given, and examine the discussion and the code?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

http://en.wikipedia.org/wiki/Yamaha_YM3812, especially the "OPLx decapsulated" link.

Yes, instead of sin(x) table, you create log(sin(x)) table.

You only need a quarter sine wave (it is symmetrical), so 256 log(sin(x)) actually gives you 1024 samples per period.

The exponential table is inverse of the log function. Base should not matter as long as both exp and log have the same base. However some base may have nicer number range that would suit better. I only know how the chip in article does it.

Basically you would not even need the logsin table if you like to generate and modulate square waves with ADSR envelope.

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

Thank you theusch and Jepael