/// <summary>Releases unmanaged and - optionally - managed resources.</summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { m_Exit = true; if (m_StreamHandle != IntPtr.Zero) { PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_CloseStream(m_StreamHandle); if (l_ErrorCode != PAErrorCode.NoError) { Trace.WriteLine("Error Pa_CloseStream " + PA.GetErrorText(l_ErrorCode)); } m_StreamHandle = IntPtr.Zero; } m_CallbackDelegate = null; m_StreamData = null; }
/// <summary>Initializes a new instance of the <see cref="PAOut"/> class.</summary> /// <param name="dev">The device to use.</param> /// <param name="configuration">The configuration to use.</param> /// <exception cref="NotSupportedException"> /// </exception> /// <exception cref="Exception"></exception> internal PAOut(IAudioDevice dev, IAudioConfiguration configuration) : base(dev, configuration) { var l_OutputParameters = new PAStreamParameters(); switch (configuration.ChannelSetup) { case AudioChannelSetup.Mono: case AudioChannelSetup.Stereo: l_OutputParameters.ChannelCount = configuration.Channels; break; default: throw new NotSupportedException(string.Format("Audio channel setup {0} not supported!", configuration.ChannelSetup)); } switch (configuration.Format) { case AudioSampleFormat.Float: l_OutputParameters.SampleFormat = PASampleFormat.Float32; break; case AudioSampleFormat.Int8: l_OutputParameters.SampleFormat = PASampleFormat.Int8; break; case AudioSampleFormat.Int16: l_OutputParameters.SampleFormat = PASampleFormat.Int16; break; case AudioSampleFormat.Int24: l_OutputParameters.SampleFormat = PASampleFormat.Int24; break; case AudioSampleFormat.Int32: l_OutputParameters.SampleFormat = PASampleFormat.Int32; break; default: throw new NotSupportedException(string.Format("Audio format {0} not supported!", configuration.Format)); } l_OutputParameters.Device = ((PADevice)dev).DeviceIndex; SamplesPerBuffer = Math.Max(1, configuration.SamplingRate / PA.BuffersPerSecond); BufferSize = configuration.BytesPerTick * SamplesPerBuffer; m_CallbackDelegate = new PA.StreamCallbackDelegate(Callback); PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_OpenStream(out m_StreamHandle, IntPtr.Zero, ref l_OutputParameters, configuration.SamplingRate, (uint)SamplesPerBuffer, PAStreamFlags.ClipOff, m_CallbackDelegate, IntPtr.Zero); if (l_ErrorCode != PAErrorCode.NoError) { throw new Exception(PA.GetErrorText(l_ErrorCode)); } }