Jump to content
  • Advertisement
Sign in to follow this  
The__Void

multiple sound cards

This topic is 3706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone I'm developing an aplication that needs to use multiple sound devices at the same time, I search several websites and googled for a few hours trying to find a solution and I didn't find anyting being able to change the device would also work, but using both would be great any ideas? thanks in advance edit: oh ya and it's for win xp

Share this post


Link to post
Share on other sites
Advertisement
that was a fast reply :)

well it's a simple voip phone, using sip messages

I'm using C# and the OS is win XP

not using any API, just the .net framework soundPlayer

Share this post


Link to post
Share on other sites
DirectSound should allow opening multiple devices without a hitch. OpenAL should also handle multiple devices.

Share this post


Link to post
Share on other sites
Quote:
Original post by SnotBob
DirectSound should allow opening multiple devices without a hitch. OpenAL should also handle multiple devices.


I'll be killing a bug with a bazzuka using those :D

I'll check out the DirectSound

know any websites with examples? I never used those

Share this post


Link to post
Share on other sites
http://www.codeproject.com/KB/audio-video/DirectSound9p1.aspx

this should do it :)

thanks alot guys, you saved me a few hours of pain

Share this post


Link to post
Share on other sites
Are you already using multiple sound cards?
Last time I put two sound blasters on the same PC the driver went crazy and took quite a while to go back to a predictable state.

Please, give me good news!

Share this post


Link to post
Share on other sites
not yet, I'll do it tomorow
and actualy it's not 2 sound cards, it's a onboard sound card and an usb phones

I'll post the code here once I'm done

Share this post


Link to post
Share on other sites
as promised here is the code

it's only used to play a sinlge audio file, but it's easy to change to play more them one

have fun and good coding ;)



using System;
using System.Collections.Generic;
using System.Text;
using System.Media;
using System.Runtime.InteropServices;
using System.Management;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;

namespace audio_device_changer
{
static class player
{
//primary device (headphones)
private static Device dSound = null;
private static SecondaryBuffer sound = null;

//secondary device (speakers)
private static Device dSound2 = null;
private static SecondaryBuffer sound2 = null;

private static BufferDescription d = null;
private static DevicesCollection devList = null;
internal static DevicesCollection DevList
{
get { return devList; }
}
/// <summary>
/// true if ringing is playing
/// </summary>
internal static bool Playing
{
get { return playing; }
}
private static bool playing = false;
/// <summary>
/// if true the secoundary device will also play
/// </summary>
internal static bool PlaySecondary
{
get { return playSecondary; }
set
{
if (!value && Playing)
if (sound2 != null)
sound2.Stop();
if (value && Playing)
if (sound2 != null)
sound2.Play(0, BufferPlayFlags.Looping);
playSecondary = value;
}
}
private static bool playSecondary = false;

/// <summary>
/// setups the player
/// </summary>
/// <param name="FilePath">path to the rining wave file</param>
/// <param name="owner">onwer form</param>
/// <returns></returns>
internal static bool SetStuff(string FilePath, System.Windows.Forms.Form owner)
{
try
{
devList = new DevicesCollection();
d = new BufferDescription();
d.Flags = BufferDescriptionFlags.ControlVolume | BufferDescriptionFlags.ControlFrequency | BufferDescriptionFlags.ControlPan | BufferDescriptionFlags.ControlEffects;

if (DevList.Count >= 2)
{
dSound = new Device(DevList[1].DriverGuid);
dSound.SetCooperativeLevel(owner, CooperativeLevel.Priority);
sound = new SecondaryBuffer(FilePath, d, dSound);
}
if (DevList.Count >= 3)
{
dSound2 = new Device(DevList[2].DriverGuid);
dSound2.SetCooperativeLevel(owner, CooperativeLevel.Priority);
sound2 = new SecondaryBuffer(FilePath, d, dSound2);
}

return true;
}
catch (Exception ex)
{
return false;
}
}
/// <summary>
/// starts ringing
/// </summary>
internal static void PlayRing()
{
try
{
if (sound != null)
{
sound.Play(0, BufferPlayFlags.Looping);
}
if (sound2 != null && PlaySecondary)
{
sound2.Play(0, BufferPlayFlags.Looping);
}
playing = true;
}
catch (Exception ex)
{
if (true)
{

}
}
}
/// <summary>
/// stopts ringing
/// </summary>
internal static void StopRing()
{
try
{
if (sound != null)
{
sound.Stop();
}
if (sound2 != null)
{
sound2.Stop();
}
playing = false;
}
catch (Exception ex)
{
if (true)
{

}
}
}
/// <summary>
/// stops sound and disposes objects
/// </summary>
internal static void Destroy()
{
try
{
if (playing)
StopRing();
if (devList != null)
devList = null;
if (d != null)
d.Dispose();
d = null;
if (dSound != null)
dSound.Dispose();
dSound = null;
if (dSound2 != null)
dSound2.Dispose();
dSound2 = null;
}
catch (Exception ex)
{
}
}
}
}



Share this post


Link to post
Share on other sites
ok I have a small problem

the sound works fine but when I minimize my Form the sound stops

I know this is suposed to happen, but is there anyway around it?

also find something about using Microsoft.DirectX.AudioVideoPlayback, but I can't find it

any ideas?
thanks in advance

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!