Fun with Beep(), Windows API.

I am a complete novice, but I found the Beep() function as part of the win api and instantly got exited at the creative possibility's as far as adding sound to my programs.

I decided to make some simple loops to see how well I could blend individual beeps in to one smooth sound.

I came up with the following code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    //ascending pitch beep
    for (int i=0; i<3000; i+=10){
    Beep (i,100);
    }
    //descending pitch beep
    for (int i=3000; i>0; i-=10){
    Beep (i,100);
    }

}


This is definitely not blending the beeps together as I would like, it appears to be very sluggish and jumpy. I am coding on a very low performance laptop, but is there any way to improve the speed/performance of this?

Thanks.

you can increase duration of sound by like this Beep(i,1000).
Here is also a similar type program you can compile http://codeincodeblock.blogspot.com/2011/10/playing-sound-source-code-in-c.html
yeah, I tried different durations, the beeps were still choppy because there is a very small pause in between loops. I guess what I am really trying to do is speed up the time in between beeps so it is as close to seamless as possible.

PS:
Although the code you linked doesn't help answer my question, it was very interesting. I did have to fix it though because it was not playing the melody. (there was a problem with the comparison in the if else). I did still notice that the beeps where being played very jumpy even in that program.
Last edited on
I don't think that this is software issue, more like hardware limitations. I don't think that speakers, that produce beeps, can create this effect
Last edited on
www.un4seen.com
Still "Bass Audio Library" beats Windows API.
In their examples (You have to download the archive) there is a nice Console-based Musical Keyboard.
Check it out.
Topic archived. No new replies allowed.