generate tone with specified pitch, amplitude, and duration

Posted By: pfeldman

generate tone with specified pitch, amplitude, and duration - 07/29/08 20:27

I'd like to see a function similar to beep() that (A) works and (2) allows the caller to specify pitch, amplitude, and duration. With a sequence of calls to such a function, simple musical melodies could be generated.

Dr. Phillip M. Feldman
Posted By: jcl

Re: generate tone with specified pitch, amplitude, and duration - 07/30/08 09:22

Take a basic sine wave of 440 Hz, play it in a loop, and use snd_tune to adjust it to the frequency you need.
Posted By: pfeldman

Re: generate tone with specified pitch, amplitude, and duration - 08/10/08 19:02

I've looked at the documentation at the following URL:

http://www.xuduo.cn/Tutorial/Manual_en/asnd_tune.htm

It's not clear how this is working. I assume that snd_tune changes the frequency by simply modifying the playback rate. If so, this will also change the duration, which is undesirable. I suppose that I could make the sound longer than what's needed, and then use a combination of snd_tune() and snd_stop() to achieve the effect that I want, but this would be ugly. I'd like to see a cleaner mechanism for producing a sequence of tones.

Thanks!
Posted By: Shadow969

Re: generate tone with specified pitch, amplitude, and duration - 08/10/08 19:09

not sure about the way snd_tune is working, but i used it to achieve the similar effect - in a piano simulator. i took 15 real note sounds of one octave and then changed their pitch with snd_tune, without noticing difference in duration.
i suppose you can make a simple loopable sound of 440 Hz and play it in the loop, use snd_tune to transpose it and snd_stop to stop it (or snd_tune to lower the volume till silence)
Posted By: FBL

Re: generate tone with specified pitch, amplitude, and duration - 08/10/08 20:49

use snd_loop() and when the sound has played long enough, then use snd_stop().
This way you can tune the frequency as you wish without having to worry about playback length.
Posted By: pfeldman

Re: generate tone with specified pitch, amplitude, and duration - 08/14/08 03:41

OK. Both of these sound like workable solutions. If anyone is willing to post a sample of code, that would be even better, but I think that I can take it from here.

Thanks!

Phillip
© 2024 lite-C Forums