tags:

views:

1189

answers:

4

hi whatsup? im making a SAMPLER program where each key from 1 to 9 will make a different sound. everything is working great, But.. when i press two (or more) sounds at the same time, the second one "kills" the first one im playing the sounds from .WAV files, using SoundPlayer. how can i solve this? thanks!

+1  A: 

You'll need to use DirectX (DirectSound) or some similar API that is designed to allow the playing of multiple sounds at the same time.

Robert Harvey
A: 

I'm guessing that in your KeyPress event (or whatever you're using) you're creating a new instance of SoundPlayer using the constructor that takes a path to the WAV file, and then calling its Play method. In theory this shouldn't cause the "mono" effect that you're encountering, since Windows has been capable of playing multiple WAV files simultaneously since Windows 98. What I think you're hearing (based on my own use of this class) is not a cutoff of the first sound when the second starts, but actually a glitch that results from overall playback pausing as the WAV file is loaded from disk.

Instead of loading up a new instance of SoundPlayer on each key press, try creating an array of class-scoped SoundPlayer objects and pre-loading them from disk in your form's Load event. Then just call each SoundPlayer's Play method when the key is pressed. This may fix your problem, although I think you will still get occasional glitches this way.

MusiGenesis
A: 

Please see example http://alvas.net/alvas.audio,tips.aspx#tip77

ava
A: 

@MusiGenesis I tried what you suggest with no succeed, It seems that this problem is in the SoundPlayer API itself that not allowing you to play multiple sound at the same time, "The new wav will play and will stop the old wav..".

Jalal Aldeen Saa'd