From f2b38767e66248362832d6d394eab36b7c5d094d Mon Sep 17 00:00:00 2001 From: Dave Yost Date: Sat, 18 May 2024 22:30:49 -0700 Subject: [PATCH] Update Stream.cs to support Pa_GetStreamTime copied exactly from the Bassoon repo --- PortAudioSharp/Stream.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/PortAudioSharp/Stream.cs b/PortAudioSharp/Stream.cs index f5fa052..0c7c816 100644 --- a/PortAudioSharp/Stream.cs +++ b/PortAudioSharp/Stream.cs @@ -67,6 +67,9 @@ IntPtr userData // Originally `void *` [return: MarshalAs(UnmanagedType.I4)] public static extern ErrorCode Pa_IsStreamActive(IntPtr stream); // `PaStream *` + [DllImport(PortAudioDLL)] + public static extern double Pa_GetStreamTime(IntPtr stream); // `PaStream *` + [DllImport(PortAudioDLL)] public static extern double Pa_GetStreamCpuLoad(IntPtr stream); // `PaStream *` } @@ -388,6 +391,28 @@ public bool IsActive } } + /// + /// Returns the current time in seconds for a stream according to the same clock + /// used to generate callback PaStreamCallbackTimeInfo timestamps. The time values + /// are monotonically increasing and have unspecified origin. + /// + /// Pa_GetStreamTime returns valid time values for the entire life of the stream, + /// from when the stream is opened until it is closed. Starting and stopping the + /// stream does not affect the passage of time returned by Pa_GetStreamTime. + /// + /// This time may be used for synchronizing other events to the audio stream, + /// for example synchronizing audio to MIDI. + /// + /// @return + /// The stream's current time in seconds, or 0 if an error occurred. + /// + /// @see PaTime, PaStreamCallback, PaStreamCallbackTimeInfo + /// + public double Time + { + get => Native.Pa_GetStreamTime(streamPtr); + } + /// /// Retrieve CPU usage information for the specified stream. /// The "CPU Load" is a fraction of total CPU time consumed by a callback stream's