'Using beep(freq,duration) Repeatedly

I am trying to create a piano that will play the correct note by either pressing the assigned key or clicking the buttons.

It works so far using the beep(freq, duration) function, but that command has a limitation of one note at a time. So if I run through all the notes, it will lag behind until it has played every note at the set duration.

I want to play the note only as long as the button is pressed or the key is pushed down, and also have the ability to play more than one note at a time. I know of the hardware limitations of most keyboards, but I would at least like to be able to press 3 keys at once, and have all three notes generate and play at the same time, not back to back after it has been through its set duration.

The code I have been using:

Beep(GlobalVariables.frqD, intDuration)

with Beep declared as:

Private Declare Function Beep Lib "kernel32" (ByVal soundFrequency As Int32, ByVal soundDuration As Int32) As Int32 


Solution 1:[1]

Playing as long as the key is pressed should be easy.

while(keypressed)
{
    beep(freq,millisecond);
}

the frequency of the really short beeps should make it sound like a single note(temporal frequency, not auditory frequency, aha).

The thing about the beep method though, is last I checked it used the speaker on the motherboard, not your actual speakers. I could be wrong, but it seems as though you can't get more than one tone at a time. Try something like this, or just google yourself a proper audio playing library. That should be possible to create chords with.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1