Merge pull request #325 from lukeIam/PACloaseStreamHandling
PortAudio close-stream-handling
This commit is contained in:
1 file changed
+27
-9
@@ -74,12 +74,23 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
lock (_Mutex)
|
lock (_Mutex)
|
||||||
{
|
{
|
||||||
|
if (_Disposed)
|
||||||
|
return;
|
||||||
Debug.Assert(_RefCount > 0);
|
Debug.Assert(_RefCount > 0);
|
||||||
_RefCount--;
|
_RefCount--;
|
||||||
if (_RefCount == 0)
|
if (_RefCount == 0)
|
||||||
PortAudio.Pa_Terminate();
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PortAudio.Pa_Terminate();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CLog.LogError(errorText: $"Error disposing PortAudio: {ex.Message}", e: ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_Disposed = true;
|
||||||
}
|
}
|
||||||
_Disposed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -100,11 +111,11 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags,
|
double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags,
|
||||||
PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData)
|
PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData)
|
||||||
{
|
{
|
||||||
if (_Disposed)
|
|
||||||
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
|
||||||
|
|
||||||
lock (_Mutex)
|
lock (_Mutex)
|
||||||
{
|
{
|
||||||
|
if (_Disposed)
|
||||||
|
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
||||||
|
|
||||||
PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback,
|
PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback,
|
||||||
userData);
|
userData);
|
||||||
if (res == PortAudio.PaError.paNoError)
|
if (res == PortAudio.PaError.paNoError)
|
||||||
@@ -157,12 +168,19 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
|
|
||||||
public void CloseStream(IntPtr stream)
|
public void CloseStream(IntPtr stream)
|
||||||
{
|
{
|
||||||
if (_Disposed)
|
|
||||||
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
|
||||||
|
|
||||||
lock (_Mutex)
|
lock (_Mutex)
|
||||||
{
|
{
|
||||||
PortAudio.Pa_CloseStream(stream);
|
if (_Disposed)
|
||||||
|
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PortAudio.Pa_CloseStream(stream);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CLog.LogError(errorText:$"Error closing stream: {ex.Message}", e:ex);
|
||||||
|
}
|
||||||
_Streams.Remove(stream);
|
_Streams.Remove(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user