Concatenating Console.Beep sounds

I played with some C # and created sounds on purpose ... because it's fun . So everything works for me, but I have something to joke with Console.Beep()

: it does not directly concatenate sounds. For example, running the code below will result in a series of 250ms bursts of sound, but instead of being fired together and sounding as if they were one, they become scattered with ~ 50ms pause between each sound.

for(int i = 0; i < 11; i++)
{
    Console.Beep(980, 250);
}

      

So the question is, is there a programmatic way to make the system run sounds together? I have to say that I really don't expect this to happen, but I thought it might be worth asking as many other resources seem to simply admit the fact that it is not.

+3


source to share


1 answer


You cannot, this method uses kernel functions. I'll prove:

[SecuritySafeCritical]
[HostProtection(SecurityAction.LinkDemand, UI = true)]
public static void Beep(int frequency, int duration)
{
    if (frequency < 37 || frequency > 32767)
    {
        throw new ArgumentOutOfRangeException("frequency", frequency, Environment.GetResourceString("ArgumentOutOfRange_BeepFrequency", new object[]
        {
            37,
            32767
        }));
    }
    if (duration <= 0)
    {
        throw new ArgumentOutOfRangeException("duration", duration, Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
    }
    Win32Native.Beep(frequency, duration);
}

      

This is the code Console.Beep

it uses Win32Native.Beep

to actually execute the beep (besides the checks above) and this method results in:

[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool Beep(int frequency, int duration);

      



Function imported from the kernel.

Unless you copy and modify your kernel, you cannot. (Which I'm sure you don't want)

I can give you an alternative: http://naudio.codeplex.com/ , instead you can manipulate your sound with this tool and give it a stream. (You can create a stream that doesn't use the file as source)

+3


source







All Articles