Sign in to follow this  

multiple sound cards

This topic is 3485 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
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
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
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
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

This topic is 3485 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this