//UpdateFSKFrameDecodeStats public static string[] EnumeratePlaybackDevices() { // Get the Windows enumerated Playback devices adding a "-n" tag (-1, -2, etc.) if any duplicate names Microsoft.DirectX.DirectSound.DevicesCollection cllPlaybackDevices = new Microsoft.DirectX.DirectSound.DevicesCollection(); //DeviceInformation objDI = new DeviceInformation(); int intCtr = 0; int intDupeDeviceCnt = 0; string[] strPlaybackDevices = new string[cllPlaybackDevices.Count]; foreach (DeviceInformation objDI in cllPlaybackDevices) { DeviceDescription objDD = new DeviceDescription(objDI); strPlaybackDevices[intCtr] = objDD.ToString().Trim(); intCtr += 1; } for (int i = 0; i <= strPlaybackDevices.Length - 1; i++) { intDupeDeviceCnt = 1; for (int j = i + 1; j <= strPlaybackDevices.Length - 1; j++) { if (strPlaybackDevices[j] == strPlaybackDevices[i]) { intDupeDeviceCnt += 1; strPlaybackDevices[j] = strPlaybackDevices[i] + "-" + intDupeDeviceCnt.ToString(); } } } return(strPlaybackDevices); }
public void AudioDeviceEnumeration() { Microsoft.DirectX.DirectSound.DevicesCollection devices = new Microsoft.DirectX.DirectSound.DevicesCollection(); directSoundDevices = new Guid[devices.Count]; // Gets the Guid and populates the associated descritption for each sound device for (int i = 0; i < devices.Count; i++) { DeviceInformation devInfo = devices[i]; cmbDevices.Items.Add(devInfo.Description); directSoundDevices[i] = devInfo.DriverGuid; } // Setup the selected audio device, by enumerated value globalSettings.aDC.selectedAudioDevice = 0; try { // Load the audio device from the last session audioDeviceLoad(); }catch { // Create the settings file if it doesn't exist and save with the default audioDeviceSave(); } // Sets to the default value of 0 (Should be Primary) or the previously selected value if it was different cmbDevices.SelectedIndex = globalSettings.aDC.selectedAudioDevice; }
public bool StartCodec(ref string strFault) { bool functionReturnValue = false; //Returns true if successful Thread.Sleep(100); // This delay is necessary for reliable starup following a StopCodec lock (objCodecLock) { dttLastSoundCardSample = Now; bool blnSpectrumSave = MCB.DisplaySpectrum; bool blnWaterfallSave = MCB.DisplayWaterfall; System.DateTime dttStartWait = Now; MCB.DisplayWaterfall = false; MCB.DisplaySpectrum = false; string[] strCaptureDevices = EnumerateCaptureDevices(); string[] strPlaybackDevices = EnumeratePlaybackDevices(); functionReturnValue = false; DeviceInformation objDI = new DeviceInformation(); int intPtr = 0; // Playback devices try { cllPlaybackDevices = null; cllPlaybackDevices = new Microsoft.DirectX.DirectSound.DevicesCollection(); if ((devSelectedPlaybackDevice != null)) { devSelectedPlaybackDevice.Dispose(); devSelectedPlaybackDevice = null; } foreach (DeviceInformation objDI in cllPlaybackDevices) { DeviceDescription objDD = new DeviceDescription(objDI); if (strPlaybackDevices(intPtr) == MCB.PlaybackDevice) { if (MCB.DebugLog) Logs.WriteDebug("[Main.StartCodec] Setting SelectedPlaybackDevice = " + MCB.PlaybackDevice); devSelectedPlaybackDevice = new Device(objDD.info.DriverGuid); functionReturnValue = true; break; // TODO: might not be correct. Was : Exit For } intPtr += 1; } if (!functionReturnValue) { strFault = "Playback Device setup, Device " + MCB.PlaybackDevice + " not found in Windows enumerated Playback Devices"; } } catch (Exception ex) { strFault = Err.Number.ToString + "/" + Err.Description; Logs.Exception("[StartCodec], Playback Device setup] Err: " + ex.ToString); functionReturnValue = false; } if (functionReturnValue) { // Capture Device CaptureBufferDescription dscheckboxd = new CaptureBufferDescription(); try { functionReturnValue = false; cllCaptureDevices = null; cllCaptureDevices = new CaptureDevicesCollection(); intPtr = 0; for (int i = 0; i <= cllCaptureDevices.Count - 1; i++) { if (MCB.CaptureDevice == strCaptureDevices(i)) { objCaptureDeviceGuid = cllCaptureDevices(i).DriverGuid; devCaptureDevice = new Capture(objCaptureDeviceGuid); stcSCFormat.SamplesPerSecond = 12000; // 12000 Hz sample rate stcSCFormat.Channels = 1; stcSCFormat.BitsPerSample = 16; stcSCFormat.BlockAlign = 2; stcSCFormat.AverageBytesPerSecond = 2 * 12000; stcSCFormat.FormatTag = WaveFormatTag.Pcm; objApplicationNotify = null; objCapture = null; // Set the buffer sizes intCaptureBufferSize = intNotifySize * intNumberRecordNotifications; // Create the capture buffer dscheckboxd.BufferBytes = intCaptureBufferSize; stcSCFormat.FormatTag = WaveFormatTag.Pcm; dscheckboxd.Format = stcSCFormat; // Set the format during creatation if ((objCapture != null)) { objCapture.Dispose(); objCapture = null; } //objCapture = New CaptureBuffer(dscheckboxd, devCaptureDevice) intNextCaptureOffset = 0; WriteTextToSpectrum("CODEC Start OK", Brushes.LightGreen); while (Now.Subtract(dttStartWait).TotalSeconds < 3) { Application.DoEvents(); Thread.Sleep(100); } objCapture = new CaptureBuffer(dscheckboxd, devCaptureDevice); InititializeNotifications(); objCapture.Start(true); // start with looping InititializeSpectrum(Color.Black); functionReturnValue = true; } } if (!functionReturnValue) { strFault = "Could not find DirectSound capture device " + MCB.CaptureDevice.ToUpper; //Logs.Exception("[Main.StartCodec] Could not find DirectSound capture device " & MCB.CaptureDevice & " in Windows enumerated Capture Devices") } } catch (Exception ex) { strFault = Err.Number.ToString + "/" + Err.Description; functionReturnValue = false; //Logs.Exception("[Main.StartCodec] Err: " & ex.ToString) } } if (functionReturnValue) { if (MCB.DebugLog) Logs.WriteDebug("[Main.StartCodec] Successful start of codec"); objProtocol.ARDOPProtocolState = ProtocolState.DISC; } else { if (MCB.DebugLog) Logs.WriteDebug("[Main.StartCodec] CODEC Start Failed"); WriteTextToSpectrum("CODEC Start Failed", Brushes.Red); objProtocol.ARDOPProtocolState = ProtocolState.OFFLINE; while (Now.Subtract(dttStartWait).TotalSeconds < 3) { Application.DoEvents(); Thread.Sleep(100); } tmrStartCODEC.Interval = 5000; tmrStartCODEC.Start(); } InititializeSpectrum(Color.Black); MCB.DisplayWaterfall = blnWaterfallSave; MCB.DisplaySpectrum = blnSpectrumSave; } return functionReturnValue; }
//UpdateFSKFrameDecodeStats public static string[] EnumeratePlaybackDevices() { // Get the Windows enumerated Playback devices adding a "-n" tag (-1, -2, etc.) if any duplicate names Microsoft.DirectX.DirectSound.DevicesCollection cllPlaybackDevices = new Microsoft.DirectX.DirectSound.DevicesCollection(); //DeviceInformation objDI = new DeviceInformation(); int intCtr = 0; int intDupeDeviceCnt = 0; string[] strPlaybackDevices = new string[cllPlaybackDevices.Count]; foreach (DeviceInformation objDI in cllPlaybackDevices) { DeviceDescription objDD = new DeviceDescription(objDI); strPlaybackDevices[intCtr] = objDD.ToString().Trim(); intCtr += 1; } for (int i = 0; i <= strPlaybackDevices.Length - 1; i++) { intDupeDeviceCnt = 1; for (int j = i + 1; j <= strPlaybackDevices.Length - 1; j++) { if (strPlaybackDevices[j] == strPlaybackDevices[i]) { intDupeDeviceCnt += 1; strPlaybackDevices[j] = strPlaybackDevices[i] + "-" + intDupeDeviceCnt.ToString(); } } } return strPlaybackDevices; }