I wonder if anyone can tell me if it is possible with DirectSound to play 2 wav files to 2 output devices at the same time?
My problem is to create a workable sound mixer where you can use one output for speakers and one output for headphones, DJ style.
Simply playing 1 track to the speakers and 1 to the headphones and then changing the headphone output over to the speakers when you are ready is not really good enough, as any 'dj' will tell you... you still need to hear the output through the headphones, even when bringing the track in through the speakers.
Take a look at my sound tutorial, it may help you understand DirectX Sound better: VB6.0 – Sound and DirectXSound Tutorial (I'ts still under construction though).
The post you should pay attenction is post #4
Take a look at the attachment at the bottom of that post: DirectSound, Split Buffer Play
If you open the project you will see that there are 2 forms, 1 main form, and 1 form for DirectSound play.
The form for DirectSound play (frmDX_Play.frm), I use like a bas module (or like a class), that is always the same, and I just include it in the projects where I need to use DirectSound.
This form is loaded at run time, and it has the Visible property set to False, so the user won't see it.
I suggest to load this form 2 times in the main form, and use one instance for the main speakers, and second instance of the form for the headphones.
Thanks for the reply. I looked at your tut and it explains how DXSound works very well.
I tried as you suggest to load the form twice and add some new controls for the second track but I can't get it to work fully.
I think the problem is with the DXEvent8 section. It seems I can't trigger individual events for each track and the sound is getting all chopped up.
(for the moment I am concentrating on getting both wavs to play through one output, I will attend to the issue of 2 outputs later!!)
I did manage to split the events to cater for 2 seperate sets of events and managed to get each track to play individually... but as soon as I play the 2 together, it gets all choppy again.
I think I must be missing something vital!
1.I need to have 2 output devices. 1 for Speakers. 1 for Headphones.
2.I will play wav1 to device 1
3.I will play wav2 to device 2
4.When ready, I will change the device 2 on wav 2 to device 1 without stopping the sound.
Then I will have both wav files playing through the same device.
This is basically what i need but to complicate issues, it would be best if at point 4 I could make it play on both devices simultaneously until ready to shut off device 2.
At present I am stuck on making 2 wav's play correctly at the same time, regardless of the device I send it to!
I did try what you mentioned before and had the same results so I simply posted my previous attempt which was more complete, albeit with no documentation!
Thanks for posting the code. It works great for playing the output to 2 devices!
Now my next problem is changing the output of track 2 to the same output device that track 1 is playing on - when i do this, it garbles the sound again
Maybe it is not possible to change the output device on the fly and maybe not possible to play 2 wavs through the same output?
I will keep looking but thank you very much for all your help. Your code and tuts have been a very useful start to DX!!!
You can't change the sound device "on the fly", you have to stop the sound, un-innitialize, then initialize it again with the new device, this takes a lot of time, and you will hear a big gap while doing all that.
The only option is that when you want to switch wave 2 to play on the same device as wave1, is to mix the wave file on the fly.
It is easy to mix sounds.
Lets say you have the buffers:
VB Code:
Dim BuffWave1() As Integer
Dim BuffWave2() As Integer
The formula is simple, add the 2 sounds then divide by 2 (average)