diff --git a/Vocaluxe/GlobalSuppressions.cs b/Vocaluxe/GlobalSuppressions.cs index da284174..8a667a11 100644 --- a/Vocaluxe/GlobalSuppressions.cs +++ b/Vocaluxe/GlobalSuppressions.cs @@ -38,9 +38,6 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Objekte verwerfen, bevor Bereich verloren geht", Scope = "member", Target = "Vocaluxe.Lib.Draw.CDirect3D.#CopyScreen()") ] [assembly: SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Scope = "type", Target = "Vocaluxe.Lib.Input.WiiMote.InputReport")] -[assembly: SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Scope = "type", Target = "PortAudioSharp.PortAudio+PaDeviceIndex")] -[assembly: SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Scope = "type", Target = "PortAudioSharp.PortAudio+PaSampleFormat")] -[assembly: SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Scope = "type", Target = "PortAudioSharp.PortAudio+PaStreamCallbackFlags")] [assembly: SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", Target = "Vocaluxe.Lib.Video.Gstreamer.CGstreamerVideoWrapper.#GetFrame(System.Int32,System.Single)")] @@ -49,19 +46,4 @@ using System.Diagnostics.CodeAnalysis; Target = "Vocaluxe.Lib.Input.CHIDAPI.#ReadTimeout(System.IntPtr,System.Byte[]&,System.Int32,System.Int32)")] [assembly: SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", - Target = "Vocaluxe.Lib.Input.CHIDAPI.#Read(System.IntPtr,System.Byte[]&,System.Int32)")] -[assembly: SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", Target = "PortAudioSharp.PortAudio.#Pa_GetVersionText()")] -[assembly: - SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", - Target = "PortAudioSharp.PortAudio.#Pa_GetErrorText(PortAudioSharp.PortAudio+PaError)")] -[assembly: - SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", - Target = "PortAudioSharp.PortAudio.#Pa_GetHostApiInfo(System.Int32)")] -[assembly: - SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", Target = "PortAudioSharp.PortAudio.#Pa_GetLastHostErrorInfo()")] -[assembly: - SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", - Target = "PortAudioSharp.PortAudio.#Pa_GetDeviceInfo(System.Int32)")] -[assembly: - SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", - Target = "PortAudioSharp.PortAudio.#Pa_GetStreamInfo(System.IntPtr)")] \ No newline at end of file + Target = "Vocaluxe.Lib.Input.CHIDAPI.#Read(System.IntPtr,System.Byte[]&,System.Int32)")] \ No newline at end of file diff --git a/Vocaluxe/Lib/Sound/CPortAudioCommon.cs b/Vocaluxe/Lib/Sound/CPortAudioCommon.cs index d3584860..a3233047 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioCommon.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioCommon.cs @@ -12,7 +12,7 @@ namespace Vocaluxe.Lib.Sound /// DO NEVER use following Pa_* functions other than the ones from this class: /// Initialize, Terminate, OpenStream, CloseStream /// - abstract class CPortAudioCommon + static class CPortAudioCommon { private static int _RefCount; private static readonly object _Mutex = new object(); @@ -22,13 +22,13 @@ namespace Vocaluxe.Lib.Sound /// MUST call CloseDriver when done /// /// True on success, falso if not initialized (log written) - protected static bool _InitDriver() + public static bool InitDriver() { lock (_Mutex) { if (_RefCount == 0) { - if (_CheckError("Initialize", PortAudio.Pa_Initialize())) + if (CheckError("Initialize", PortAudio.Pa_Initialize())) return false; } _RefCount++; @@ -40,7 +40,7 @@ namespace Vocaluxe.Lib.Sound /// Safe method to close PortAudio /// MUST be called _exactly_ once after successfull InitDriver call /// - protected static void _CloseDriver() + public static void CloseDriver() { lock (_Mutex) { @@ -51,9 +51,9 @@ namespace Vocaluxe.Lib.Sound } } - protected static PortAudio.PaError _OpenStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, ref PortAudio.PaStreamParameters? outputParameters, - double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, - PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) + public static PortAudio.PaError OpenStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, ref PortAudio.PaStreamParameters? outputParameters, + double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, + PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) { lock (_Mutex) { @@ -72,14 +72,14 @@ namespace Vocaluxe.Lib.Sound /// /// /// True on success - protected static bool _OpenInputStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, - double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, - PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) + public static bool OpenInputStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, + double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, + PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) { PortAudio.PaStreamParameters? outputParameters = null; return - !_CheckError("OpenInputStream", - _OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData)); + !CheckError("OpenInputStream", + OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData)); } /// @@ -93,17 +93,17 @@ namespace Vocaluxe.Lib.Sound /// /// /// True on success - protected static bool _OpenOutputStream(out IntPtr stream, ref PortAudio.PaStreamParameters? outputParameters, - double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, - PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) + public static bool OpenOutputStream(out IntPtr stream, ref PortAudio.PaStreamParameters? outputParameters, + double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, + PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) { PortAudio.PaStreamParameters? inputParameters = null; return - !_CheckError("OpenOutputStream", - _OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData)); + !CheckError("OpenOutputStream", + OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData)); } - protected static void _CloseStream(IntPtr stream) + public static void CloseStream(IntPtr stream) { lock (_Mutex) { @@ -118,7 +118,7 @@ namespace Vocaluxe.Lib.Sound /// Action identifier (E.g. openStream) /// Result returned by Pa_* call /// True on error - protected static bool _CheckError(String action, PortAudio.PaError errorCode) + public static bool CheckError(String action, PortAudio.PaError errorCode) { if (errorCode != PortAudio.PaError.paNoError) { @@ -140,7 +140,7 @@ namespace Vocaluxe.Lib.Sound /// Selects the most appropriate host api /// /// The most appropriate host api - protected static int _GetHostApi() + public static int GetHostApi() { //Caller has to hold a reference anyway so no locking needed if (_RefCount < 1) diff --git a/Vocaluxe/Lib/Sound/Playback/PortAudio/CPortAudioStream.cs b/Vocaluxe/Lib/Sound/Playback/PortAudio/CPortAudioStream.cs index 6d372560..62a2f9f4 100644 --- a/Vocaluxe/Lib/Sound/Playback/PortAudio/CPortAudioStream.cs +++ b/Vocaluxe/Lib/Sound/Playback/PortAudio/CPortAudioStream.cs @@ -8,7 +8,7 @@ using VocaluxeLib; namespace Vocaluxe.Lib.Sound.Playback.PortAudio { - class CPortAudioStream : CPortAudioCommon, IDisposable + class CPortAudioStream : IDisposable { private const long _Bufsize = 1000000L; private const long _Beginrefill = 800000L; @@ -187,12 +187,12 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio { Paused = false; _AfterFadeAction = EStreamAction.Nothing; - _CheckError("StartStream", PortAudioSharp.PortAudio.Pa_StartStream(_Stream)); + CPortAudioCommon.CheckError("StartStream", PortAudioSharp.PortAudio.Pa_StartStream(_Stream)); } public void Stop() { - _CheckError("StopStream (playback)", PortAudioSharp.PortAudio.Pa_StopStream(_Stream)); + CPortAudioCommon.CheckError("StopStream (playback)", PortAudioSharp.PortAudio.Pa_StopStream(_Stream)); Skip(0f); } @@ -213,11 +213,11 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio bool driverInitialized = false; try { - if (!_InitDriver()) + if (!CPortAudioCommon.InitDriver()) return false; driverInitialized = true; - int hostApi = _GetHostApi(); + int hostApi = CPortAudioCommon.GetHostApi(); _ApiInfo = PortAudioSharp.PortAudio.Pa_GetHostApiInfo(hostApi); _OutputDeviceInfo = PortAudioSharp.PortAudio.Pa_GetDeviceInfo(_ApiInfo.defaultOutputDevice); if (_OutputDeviceInfo.defaultLowOutputLatency < 0.1) @@ -228,7 +228,7 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio catch (Exception) { if (driverInitialized) - _CloseDriver(); + CPortAudioCommon.CloseDriver(); CLog.LogError("Error Init PortAudio Playback"); return false; } @@ -240,7 +240,7 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio SFormatInfo format = _Decoder.GetFormatInfo(); if (format.SamplesPerSecond == 0) { - _CloseDriver(); + CPortAudioCommon.CloseDriver(); _Decoder.Close(); _Decoder = null; CLog.LogError("Error Init PortAudio Playback (samples=0)"); @@ -262,7 +262,7 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio hostApiSpecificStreamInfo = IntPtr.Zero }; - if (!_OpenOutputStream( + if (!CPortAudioCommon.OpenOutputStream( out _Stream, ref outputParams, format.SamplesPerSecond, @@ -271,7 +271,7 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio _PaStreamCallback, IntPtr.Zero) || _Stream == IntPtr.Zero) { - _CloseDriver(); + CPortAudioCommon.CloseDriver(); _Decoder.Close(); _Decoder = null; return false; @@ -410,8 +410,8 @@ namespace Vocaluxe.Lib.Sound.Playback.PortAudio private void _DoFree() { - _CloseStream(_Stream); - _CloseDriver(); + CPortAudioCommon.CloseStream(_Stream); + CPortAudioCommon.CloseDriver(); _Decoder.Close(); _Closeproc(ID); diff --git a/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs b/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs index 914435f8..5515b8b9 100644 --- a/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs +++ b/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs @@ -24,7 +24,7 @@ using Vocaluxe.Base; namespace Vocaluxe.Lib.Sound.Record.PortAudio { - class CPortAudioRecord : CPortAudioCommon, IRecord + class CPortAudioRecord : IRecord { private bool _Initialized; private readonly List _Devices = new List(); @@ -52,11 +52,11 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio try { - if (!_InitDriver()) + if (!CPortAudioCommon.InitDriver()) return false; _Devices.Clear(); - int hostAPI = _GetHostApi(); + int hostAPI = CPortAudioCommon.GetHostApi(); int numDevices = PortAudioSharp.PortAudio.Pa_GetDeviceCount(); for (int i = 0; i < numDevices; i++) { @@ -128,7 +128,7 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio suggestedLatency = PortAudioSharp.PortAudio.Pa_GetDeviceInfo(_Devices[dev].ID).defaultLowInputLatency, hostApiSpecificStreamInfo = IntPtr.Zero }; - if (!_OpenInputStream( + if (!CPortAudioCommon.OpenInputStream( out _RecHandle[dev], ref inputParams, 44100, @@ -138,7 +138,7 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio new IntPtr(dev))) return false; - if (_CheckError("Start Stream (rec)", PortAudioSharp.PortAudio.Pa_StartStream(_RecHandle[dev]))) + if (CPortAudioCommon.CheckError("Start Stream (rec)", PortAudioSharp.PortAudio.Pa_StartStream(_RecHandle[dev]))) return false; } } @@ -168,8 +168,8 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio return; foreach (IntPtr handle in _RecHandle) - _CloseStream(handle); - _CloseDriver(); + CPortAudioCommon.CloseStream(handle); + CPortAudioCommon.CloseDriver(); _Initialized = false;