Question

I've tried using Console.Beep() at low millisecond rates two play two frequencies 'at once', but the pause between beeps ruins it. I have tried researching it but I've found nothing, and don't know where to start, aside from DirectSound, which I'm looking in to. All I need is to make a program that plays two or more frequencies simultaneously out of one speaker, in C#.

Thanks.

Was it helpful?

Solution

I suggest you look at DirectSound, which has nice .NET bindings. You can use two (or more) Buffer objects and invoke their Play methods to play them simultaneously.

This tutorial shows how to implement a simple drum machine in C# by synthesising sounds on the fly. Hope it helps.

OTHER TIPS

Try looking at using MIDI. This example should get you started. It uses a MIDI library that several people recommend highly.

Console.Beep() is synchronous and does not return until the sound is finished.

Try Simple DirectMedia Layer (SDL.net).

Here's some very simple sample code that will let you play a WAV or MIDI file. This way you can write your code once then just maintain the wav or mid file if you want to make changes to the sound effect.

Play Any Sound File - C# ( Uses DirectX 9.0 for Managed Code )

If you know the frequencies beforehand you can synthesize them into a wave file (audacity or another similar program) and then play the wave file with the SoundPlayer class.

string path = /*path goes here*/;
player = new SoundPlayer(path);
player.Play();

If you need to synthesize them at runtime you would have to write the file by hand. Here's a SO question that you can reference to build the wave files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top