If you don't mind using the system speaker...
Beep(freq, duration); from windows.h would be suffice.
Portable? No. Cross compiler compatible? Yes (at least for windows compilers).
What about using a sine curve? Sound waveforms for a set frequency use sine curves. If your audio file is 44,100 Hz sample rate, the typical used with audio CD's, you'd have a full loop every 44,100 samples at 1 Hz. Frequency is how many loops you can get in that 44,100 samples. For 500 Hz pitch, you'd need 88.2 samples per loop. Note that samples divided by pitch gives the span between wave crests. To reproduce this sample 500 Hz wave, you'd need to determine the location of each sample and a basic sine curve answers this. You'd need to cover 360 degrees in a span of 88.2 samples This makes each sample cover 360/88.2 or 4.08163265 degrees per sample. Starting the loop at 0 degrees, you increment based on that and multiply this result by the range of the samples, like 32767 for a 16-bit audio file (which is what audio CD's use. The first is obvious - 0. The next is the sine of 4.08163265 degrees, or 0.07117769. Multiply this by 32767 and that's the position of that sample. Increment the angle for the next sample and keep going for as long as you want. That's the basic pure tone.
I don't know what a squarewave is, but if it's just basic linear increments, a similar system applies but no sine curves are used. Determining the span between crests is still the same. Instead of using a sine curve, you'd have the top part of the wave as one quarter of the way through, or 22.05 samples then the bottom part as 3/4 of the way through, or 66.15 samples (for the same 500 Hz sound).
Hopefully this will give some insight to help write your own function if nothing else is available or works for you.
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
when you say portable what do you mean?
is this 'beep' similar to the sound() and nosound()
see i came up with something using he sound(), delay() and nosound(). but it just seemed to produce a one second note and not more than one note. this was the code which i attempted:
do you know what is the best way to produce sequence of notes in C is?Code:void my_sounds(void) { sound(500); /* make a sound at 500 Hz.*/ delay(2000); /* pause for 2000 milliseconds = 2 seconds */ sound(1000); /* generate next sound at 1000Hz */ delay(2000); sound(1500); delay(2000); sound(2000); delay(2000); nosound(); /* turn off sound */ }
many thanks
Google is your friend:
http://www.harmony-central.com/Compu...gramming/#more
Also, I'd check out code depot places like Sourceforge.net, etc, and see what someone might have going there that you could learn from.
Good luck!