using System; using System.Runtime.InteropServices; using System.Collections.Generic; using NAudio.Wave; namespace NAudio.Mixer { /// Represents a Windows mixer device public class Mixer { private MixerInterop.MIXERCAPS caps; private IntPtr mixerHandle; private MixerFlags mixerHandleType; /// The number of mixer devices available public static int NumberOfDevices { get { return MixerInterop.mixerGetNumDevs(); } } /// Connects to the specified mixer /// The index of the mixer to use. /// This should be between zero and NumberOfDevices - 1 public Mixer(int mixerIndex) { if(mixerIndex < 0 || mixerIndex >= NumberOfDevices) { throw new ArgumentOutOfRangeException("mixerID"); } caps = new MixerInterop.MIXERCAPS(); MmException.Try(MixerInterop.mixerGetDevCaps((IntPtr)mixerIndex,ref caps,Marshal.SizeOf(caps)),"mixerGetDevCaps"); this.mixerHandle = (IntPtr)mixerIndex; this.mixerHandleType = MixerFlags.Mixer; // TODO: optionally support really opening the mixer device //MmException.Try(MixerInterop.mixerOpen(out mixerHandle, mixerIndex, IntPtr.Zero, IntPtr.Zero, 0), "mixerOpen"); } /// The number of destinations this mixer supports public int DestinationCount { get { return (int) caps.cDestinations; } } /// The name of this mixer device public String Name { get { return caps.szPname; } } /// The manufacturer code for this mixer device public Manufacturers Manufacturer { get { return (Manufacturers) caps.wMid; } } /// The product identifier code for this mixer device public int ProductID { get { return caps.wPid; } } /// Retrieve the specified MixerDestination object /// The ID of the destination to use. /// Should be between 0 and DestinationCount - 1 public MixerLine GetDestination(int destinationIndex) { if(destinationIndex < 0 || destinationIndex >= DestinationCount) { throw new ArgumentOutOfRangeException("destinationIndex"); } return new MixerLine(mixerHandle, destinationIndex, mixerHandleType); } /// /// A way to enumerate the destinations /// public IEnumerable Destinations { get { for (int destination = 0; destination < DestinationCount; destination++) { yield return GetDestination(destination); } } } /// /// A way to enumerate all available devices /// public static IEnumerable Mixers { get { for (int device = 0; device < Mixer.NumberOfDevices; device++) { yield return new Mixer(device); } } } } }