Results 1 to 11 of 11

Thread: [RESOLVED] Directsound question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    London, England
    Posts
    6

    Resolved [RESOLVED] Directsound question

    Hi All,

    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.

    I hope that makes sense?!

    Any ideas welcomed!!

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Directsound question

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    London, England
    Posts
    6

    Re: Directsound question

    Hi CVMichael,

    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!

    Thanks again.

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Directsound question

    Let me understand how you want the tracks to play...

    1) You want wav-1 to play on one sound card
    and wav-2 to play on a second sound card ?

    2) You want to mix wav-1 and wav-2 on the same sound card and play ?

    3) You want to play wav-1 and wav-2 os 2 separate instances of the same application on the same sound card ?

    amm... I can't think of any other way to play 2 wave files

    So, wich way do you want to do ?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    London, England
    Posts
    6

    Re: Directsound question

    Sorry, I was not very descriptive!

    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!

    Thanks!

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Directsound question

    OK, can you post some code to see what you have tried to do ?

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    London, England
    Posts
    6

    Re: Directsound question

    Here is my simple program to load 2 wavs and play them.
    Individually they play ok but together.... like a chipmunk!

    Thxs!
    Attached Files Attached Files

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Directsound question

    Your code is too confuzing, you sould not have combined the events on both sounds into one.

    Why did you not follow what I have said in post #2 ??

    Anyways, here is the code to play on 2 separate sound cards at the same time.

    I just did everything 2 times (but in an array)

    Anyways, take a look at the attachment
    Attached Files Attached Files

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    London, England
    Posts
    6

    Re: Directsound question

    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!!!

  10. #10
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Directsound question

    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:
    1. Dim BuffWave1() As Integer
    2. Dim BuffWave2() As Integer
    The formula is simple, add the 2 sounds then divide by 2 (average)
    VB Code:
    1. Dim K as Long
    2.  
    3. For K = 0 To UBound(BuffWave1)
    4.      MixedSound(K) = (CLng(BuffWave1(K)) + CLng(BuffWave2(K))) \ 2
    5. Next K
    The only problem is that both sounds HAVE to be EXACT format, otherwise you have to convert from one format to the "common" one.

    You can see how to change the format of the wave in my sound tutorial in my last post

  11. #11

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Location
    London, England
    Posts
    6

    Re: Directsound question

    Thanks CVMicheael that was exactly what I needed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width