/// <summary> /// Prepares wave file for playing. Needs to be called if wavefile or audio device is changed. /// </summary> void InitializeWave() { WaveInitializationInProgress = true; try { DisposeNAudioComponents(); WaveOut = new WaveOutEvent(); ProcessWaveStream(); Reader = new WaveFileReader(WaveStream); MixedWave = new WaveChannel32(Reader, VolumeF, PanF); WaveDurationMs = (int)MixedWave.TotalTime.TotalMilliseconds + 5; // add some buffer WaveOut.DeviceNumber = AudioDevices.GetWaveOutDeviceNumber(); WaveOut.Init(MixedWave); // limit play duration in case wave length is reported incorrectly or a long sound is loaded PlayDurationMs = (WaveDurationMs <MaxPlayDuration_ms && WaveDurationMs> WaveMonitorLoopLength_ms) ? WaveDurationMs : MaxPlayDuration_ms; WaveMonitorLoopCount = Convert.ToInt32(Math.Ceiling(PlayDurationMs / (float)WaveMonitorLoopLength_ms)); Error = false; } catch (Exception e) { Error = true; Config.WriteLog("Unable to initialize audio for " + (Wave?.DisplayName ?? "") + Environment.NewLine + e.Message); } WaveInitializationInProgress = false; }
/// <summary> /// Prepares wave file for playing. Needs to be called if wavefile or audio device is changed. /// </summary> void InitializeWave() { try { DisposeNAudioComponents(); WaveOut = new WaveOutEvent(); Reader = new WaveFileReader(_Wave + WaveFileExtension); MixedWave = new WaveChannel32(Reader, VolumeF, PanF); WaveDurationMs = (int)MixedWave.TotalTime.TotalMilliseconds + 100; // add some buffer WaveOut.DeviceNumber = AudioDevices.GetWaveOutDeviceNumber(); WaveOut.Init(MixedWave); Error = false; ErrorMessage = null; } catch (Exception e) { Error = true; ErrorMessage = e.Message; } }
/// <summary> /// Prepares wave file for playing. Needs to be called if wavefile or audio device is changed. /// </summary> void InitializeWave() { try { DisposeNAudioComponents(); WaveOut = new WaveOutEvent(); ProcessWaveStream(); Reader = new WaveFileReader(WaveStream); MixedWave = new WaveChannel32(Reader, VolumeF, PanF); WaveDurationMs = (int)MixedWave.TotalTime.TotalMilliseconds + 5; // add some buffer WaveOut.DeviceNumber = AudioDevices.GetWaveOutDeviceNumber(); WaveOut.Init(MixedWave); Error = false; } catch (Exception e) { Error = true; Config.WriteLog("Unable to initialize audio for " + (Wave?.DisplayName ?? "") + Environment.NewLine + e.Message); } }