SafeDispatch/MotoTrbo_GW/AudioDeviceName.cs

100 lines
2.9 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;
namespace MotoTRBO_GW
{
class AudioDeviceName
{
private const int MAXPNAMELEN = 122;
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct WaveInCaps
{
public short wMid;
public short wPid;
public int vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXPNAMELEN)]
public string szPname;
public int dwFormats;
public short wChannels;
public short wReserved1;
}
[DllImport("winmm.dll")]
public static extern int waveInGetNumDevs();
[DllImport("winmm.dll")]
public static extern int waveOutGetNumDevs();
[DllImport("winmm.dll", EntryPoint = "waveInGetDevCaps")]
public static extern int waveInGetDevCapsA(int uDeviceID, ref WaveInCaps lpCaps, int uSize);
[DllImport("winmm.dll", EntryPoint = "waveOutGetDevCaps")]
public static extern int waveOutGetDevCapsA(int uDeviceID, ref WaveInCaps lpCaps, int uSize);
ArrayList arrLst = new ArrayList();
public int Count
{
get {return arrLst.Count;}
}
public string this[int indexer]
{
get{return (string)arrLst[indexer];}
}
public AudioDeviceName()
{
}
private String trimHi(String s)
{
int index = s.IndexOf("(Hi");
if (index >= 0)
{
return s.Substring(0, index);
}
else
{
return s;
}
}
public ArrayList getInDevices()
{
ArrayList arrLst = new ArrayList();
int waveInDevicesCount = waveInGetNumDevs();
if (waveInDevicesCount > 0)
{
for (int uDeviceID = 0; uDeviceID < waveInDevicesCount; uDeviceID++)
{
WaveInCaps waveInCaps = new WaveInCaps();
waveInGetDevCapsA(uDeviceID, ref waveInCaps, Marshal.SizeOf(typeof(WaveInCaps)));
arrLst.Add(trimHi(waveInCaps.szPname));
}
}
return arrLst;
}
public ArrayList getOutDevices()
{
ArrayList arrLst = new ArrayList();
int waveOutDevicesCount = waveOutGetNumDevs();
if (waveOutDevicesCount > 0)
{
for (int uDeviceID = 0; uDeviceID < waveOutDevicesCount; uDeviceID++)
{
WaveInCaps waveInCaps = new WaveInCaps();
waveOutGetDevCapsA(uDeviceID, ref waveInCaps, Marshal.SizeOf(typeof(WaveInCaps)));
arrLst.Add(trimHi(waveInCaps.szPname));
}
}
return arrLst;
}
}
}