public void SOXResamplerConstructorTest() { AudioPCMConfig inputPCM = new AudioPCMConfig(32, 1, 44100); AudioPCMConfig outputPCM = new AudioPCMConfig(32, 1, 48000); SOXResamplerConfig cfg; cfg.Quality = SOXResamplerQuality.Very; cfg.Phase = 50; cfg.AllowAliasing = false; cfg.Bandwidth = 0; SOXResampler resampler = new SOXResampler(inputPCM, outputPCM, cfg); AudioBuffer src = new AudioBuffer(inputPCM, 400 * inputPCM.SampleRate / 1000); AudioBuffer dst = new AudioBuffer(outputPCM, src.Size * 3); int offs = 0; double delta = 0; for (int i = 0; i < 100; i++) { src.Prepare(-1); for (int j = 0; j < src.Size; j++) { src.Float[j, 0] = (float)Math.Sin((i * src.Size + j) * Math.PI / 44100); } src.Length = src.Size; resampler.Flow(src, dst); for (int j = 0; j < dst.Length; j++) { delta += dst.Float[j, 0] - Math.Sin((offs + j) * Math.PI / 48000); } offs += dst.Length; } Assert.IsTrue(Math.Abs(delta) < 0.00001, "Error too large"); }
public void Init(frmCUEPlayer parent) { MdiParent = parent; _device = WasapiOut.GetDefaultAudioEndpoint(); _device.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); mediaSliderVolume.Value = (int)(_device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); //mediaSliderVolume.Maximum = (int)(_device.AudioEndpointVolume.VolumeRange); Show(); int delay = 100; try { _player = new WasapiOut(_device, NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, delay, new AudioPCMConfig(32, 2, 44100)); } catch { _player = null; } if (_player == null) { try { _player = new WasapiOut(_device, NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, delay, new AudioPCMConfig(32, 2, 48000)); SOXResamplerConfig cfg; cfg.Quality = SOXResamplerQuality.Very; cfg.Phase = 50; cfg.AllowAliasing = false; cfg.Bandwidth = 0; _resampler = new SOXResampler(parent.Mixer.PCM, _player.Settings.PCM, cfg); resampled = new AudioBuffer(_player.Settings.PCM, parent.Mixer.BufferSize * 2 * parent.Mixer.PCM.SampleRate / _player.Settings.PCM.SampleRate); } catch (Exception ex) { _player = null; Trace.WriteLine(ex.Message); } } parent.Mixer.AudioRead += new EventHandler <AudioReadEventArgs>(Mixer_AudioRead); if (_player != null) { _player.Play(); } }