From 4c8d4d2ed974dba0472834afbc4c8ff4b2391c0a Mon Sep 17 00:00:00 2001 From: Alexander Shabarshov Date: Sat, 15 Aug 2026 08:52:29 +0100 Subject: [PATCH] Common interface for audio blocks --- AudioCore/AudioCore.csproj | 2 ++ AudioCore/Impl/RubberBandTimeStretchEngine.cs | 2 +- AudioCore/Models/AudioBlock.cs | 2 +- AudioCore/Models/IAudioBlock.cs | 14 ++++++++++++++ AudioCore/Models/MixedAudioBlock.cs | 16 +++++++++------- AudioCore/Models/TimeStretchedAudioBlock.cs | 6 ++++-- 6 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 AudioCore/Models/IAudioBlock.cs diff --git a/AudioCore/AudioCore.csproj b/AudioCore/AudioCore.csproj index fe50c6e..f0f4e82 100644 --- a/AudioCore/AudioCore.csproj +++ b/AudioCore/AudioCore.csproj @@ -33,6 +33,8 @@ 1.0.0 + 0 + 0000 $(Version).$(BuildNumber)+$(SourceRevisionId) $(Version) $(Version).$(BuildNumber) diff --git a/AudioCore/Impl/RubberBandTimeStretchEngine.cs b/AudioCore/Impl/RubberBandTimeStretchEngine.cs index 6af030e..e810b32 100644 --- a/AudioCore/Impl/RubberBandTimeStretchEngine.cs +++ b/AudioCore/Impl/RubberBandTimeStretchEngine.cs @@ -115,7 +115,7 @@ public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisp return Task.CompletedTask; try { - proc.Stdin.Flush(); + proc.Stdin?.Flush(); } catch (System.ObjectDisposedException) { diff --git a/AudioCore/Models/AudioBlock.cs b/AudioCore/Models/AudioBlock.cs index b69bfd5..3fe1bf8 100644 --- a/AudioCore/Models/AudioBlock.cs +++ b/AudioCore/Models/AudioBlock.cs @@ -2,7 +2,7 @@ using AudioCore.Impl; namespace AudioCore.Models; -public readonly struct AudioBlock : IDisposable +public readonly struct AudioBlock : IAudioBlock, IDisposable { public AudioBuffer Buffer { get; } public int SampleRate { get; } diff --git a/AudioCore/Models/IAudioBlock.cs b/AudioCore/Models/IAudioBlock.cs new file mode 100644 index 0000000..170bea9 --- /dev/null +++ b/AudioCore/Models/IAudioBlock.cs @@ -0,0 +1,14 @@ +using AudioCore.Impl; + +namespace AudioCore.Models; + +public interface IAudioBlock : IDisposable +{ + AudioBuffer Buffer { get; } + int SampleRate { get; } + int Channels { get; } + long Position { get; } + int Frames { get; } + int Length { get; } + Span Span { get; } +} diff --git a/AudioCore/Models/MixedAudioBlock.cs b/AudioCore/Models/MixedAudioBlock.cs index b4e11e3..fbb6786 100644 --- a/AudioCore/Models/MixedAudioBlock.cs +++ b/AudioCore/Models/MixedAudioBlock.cs @@ -2,21 +2,23 @@ using AudioCore.Impl; namespace AudioCore.Models; -public readonly struct MixedAudioBlock : IDisposable +public readonly struct MixedAudioBlock : IAudioBlock, IDisposable { public AudioBuffer Buffer { get; } public int Frames { get; } public int Channels { get; } public int SampleRate { get; } - public long Position { get; } + public long Position { get; } + public Span Span => Buffer.Span; + public int Length => Buffer.Length; public MixedAudioBlock(AudioBuffer buffer, int frames, int channels, int sampleRate, long samplePosition) { - Buffer = buffer; - Frames = frames; - Channels = channels; - SampleRate = sampleRate; - Position = samplePosition; + Buffer = buffer; + Frames = frames; + Channels = channels; + SampleRate = sampleRate; + Position = samplePosition; } public void Dispose() => Buffer.Dispose(); diff --git a/AudioCore/Models/TimeStretchedAudioBlock.cs b/AudioCore/Models/TimeStretchedAudioBlock.cs index 1dc82bc..24a2615 100644 --- a/AudioCore/Models/TimeStretchedAudioBlock.cs +++ b/AudioCore/Models/TimeStretchedAudioBlock.cs @@ -2,14 +2,16 @@ using AudioCore.Impl; namespace AudioCore.Models; -public readonly struct TimeStretchedAudioBlock : IDisposable +public readonly struct TimeStretchedAudioBlock : IAudioBlock, IDisposable { public AudioBuffer Buffer { get; } public int Frames { get; } public int Channels { get; } public int SampleRate { get; } - public long Position { get; } + public long Position { get; } + public Span Span => Buffer.Span; + public int Length => Buffer.Length; public TimeStretchedAudioBlock(AudioBuffer buffer, int frames, int channels, int sampleRate, long position) { Buffer = buffer;