mirror of
https://github.com/unclshura/ABStemPlayer.git
synced 2026-08-07 00:43:38 +00:00
Compare commits
No commits in common. "5142bb61f21ff982f45bb9aba5dfd0795e864fb6" and "82167921706087b29979407483538669417217a2" have entirely different histories.
5142bb61f2
...
8216792170
@ -1,8 +0,0 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ABStemPlayer": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "C:\\Users\\uncls\\Music\\test_input.mp3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,8 +56,6 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
private TimeSpan? _loopA;
|
||||
private TimeSpan? _loopB;
|
||||
|
||||
private static bool _commandLineProcessed = false;
|
||||
|
||||
// -----------------------------
|
||||
// Constructor
|
||||
// -----------------------------
|
||||
@ -96,24 +94,7 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
UpdateLoop();
|
||||
});
|
||||
|
||||
if ( !_commandLineProcessed)
|
||||
{
|
||||
_commandLineProcessed = true;
|
||||
ProcessCommandLineArgs();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessCommandLineArgs()
|
||||
{
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
var filePath = args[1];
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
Task.Run( () => LoadFile(filePath!));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnPlay()
|
||||
@ -126,9 +107,11 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
Stems = _engine.CurrentSession.StemSet.Stems.Select(GetMixerSettings).ToList()
|
||||
};
|
||||
|
||||
await _engine.UpdateMixerAsync(mixer);
|
||||
await _engine.UpdatePlaybackSpeedAsync(new PlaybackSpeedSettings { Speed = PlaybackSpeed });
|
||||
|
||||
_engine.CurrentSession.Mixer = mixer;
|
||||
_engine.CurrentSession.Speed = new PlaybackSpeedSettings
|
||||
{
|
||||
Speed = PlaybackSpeed
|
||||
};
|
||||
await _engine.PlayAsync();
|
||||
}
|
||||
|
||||
@ -150,7 +133,7 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
|
||||
partial void OnPlaybackSpeedChanged(float value)
|
||||
{
|
||||
Task.Run( async () => await _engine.UpdatePlaybackSpeedAsync(new PlaybackSpeedSettings { Speed = PlaybackSpeed }));
|
||||
_engine.CurrentSession?.Speed.Speed = value;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
@ -183,12 +166,6 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
|
||||
var file = files[0];
|
||||
|
||||
await LoadFile(file.Path.LocalPath);
|
||||
|
||||
}
|
||||
|
||||
private async Task LoadFile(string file)
|
||||
{
|
||||
await _engine.StopAsync();
|
||||
|
||||
var session = await SplitStems(file);
|
||||
@ -203,25 +180,24 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
Bands.Clear();
|
||||
foreach ( var item in session.StemSet.Stems)
|
||||
{
|
||||
var model = new WaveformBandViewModel(item);
|
||||
Bands.Add(model);
|
||||
Bands.Add(new WaveformBandViewModel(item));
|
||||
}
|
||||
|
||||
await _engine.LoadSessionAsync(session, new PlaybackProgressReporter(this));
|
||||
}
|
||||
|
||||
private class PlaybackProgressReporter : IProgressReporter<double>
|
||||
private class PlaybackProgressReporter : IProgressReporter<TimeSpan>
|
||||
{
|
||||
private readonly PlaybackViewModel _vm;
|
||||
public PlaybackProgressReporter(PlaybackViewModel vm)
|
||||
{
|
||||
_vm = vm;
|
||||
}
|
||||
public Task ReportProgress(double progress, CancellationToken ct)
|
||||
public Task ReportProgress(TimeSpan progress, CancellationToken ct)
|
||||
{
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
_vm.CurrentTime = TimeSpan.FromMilliseconds(progress * _vm.TotalTime.TotalMilliseconds);
|
||||
_vm.CurrentTime = progress;
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -322,7 +298,7 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
// Stem splitting
|
||||
// -----------------------------
|
||||
|
||||
private async Task<PlaybackSession?> SplitStems(string file)
|
||||
private async Task<PlaybackSession?> SplitStems(IStorageFile file)
|
||||
{
|
||||
// Enter conversion mode
|
||||
IsConverting = true;
|
||||
@ -331,7 +307,7 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
_conversionCts = new CancellationTokenSource();
|
||||
var ct = _conversionCts.Token;
|
||||
|
||||
var outDir = Path.Combine(Path.GetDirectoryName(file)!, "ABStemPlayer");
|
||||
var outDir = Path.Combine(Path.GetDirectoryName(file.Path.LocalPath)!, "ABStemPlayer");
|
||||
|
||||
StemSet? stemSet = null;
|
||||
|
||||
@ -345,7 +321,7 @@ public sealed partial class PlaybackViewModel : ObservableObject
|
||||
return await _separator.SeparateAsync(
|
||||
new StemSeparationRequest
|
||||
{
|
||||
SourceFilePath = file,
|
||||
SourceFilePath = file.Path.LocalPath,
|
||||
OutputDirectory = outDir
|
||||
},
|
||||
new VmProgressReporter(this),
|
||||
|
||||
@ -15,7 +15,5 @@ public sealed class RelayCommand : ICommand
|
||||
|
||||
public bool CanExecute(object? parameter) => _canExecute?.Invoke(parameter) ?? true;
|
||||
public void Execute(object? parameter) => _execute(parameter);
|
||||
#pragma warning disable CS0067
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
#pragma warning restore CS0067
|
||||
}
|
||||
|
||||
@ -16,17 +16,13 @@ public class BlockingRingBuffer
|
||||
_ringRead = 0;
|
||||
}
|
||||
|
||||
public void Write(ReadOnlySpan<byte> src, int srcLen, CancellationToken ct)
|
||||
public void WriteToOutput(ReadOnlySpan<byte> src, int srcLen, CancellationToken ct)
|
||||
{
|
||||
int written = 0;
|
||||
|
||||
while (written < srcLen)
|
||||
{
|
||||
if ( ct.IsCancellationRequested )
|
||||
{
|
||||
Debug.WriteLine("BlockingRingBuffer: Write: operation cancelled.");
|
||||
return;
|
||||
}
|
||||
ct.ThrowIfCancellationRequested();
|
||||
|
||||
int remaining = srcLen - written;
|
||||
|
||||
@ -37,11 +33,12 @@ public class BlockingRingBuffer
|
||||
? _ringWrite - _ringRead
|
||||
: _ring.Length - _ringRead + _ringWrite;
|
||||
|
||||
free = _ring.Length - used - 1;
|
||||
free = _ring.Length - used - 1; // leave 1 byte to distinguish full/empty
|
||||
}
|
||||
|
||||
if (free <= 0)
|
||||
{
|
||||
// No room → block until space becomes available
|
||||
Thread.Sleep(1);
|
||||
continue;
|
||||
}
|
||||
@ -52,6 +49,7 @@ public class BlockingRingBuffer
|
||||
{
|
||||
int first = Math.Min(toWrite, _ring.Length - _ringWrite);
|
||||
|
||||
// Write first segment
|
||||
src.Slice(written, first)
|
||||
.CopyTo(new Span<byte>(_ring, _ringWrite, first));
|
||||
|
||||
@ -60,6 +58,7 @@ public class BlockingRingBuffer
|
||||
int leftover = toWrite - first;
|
||||
if (leftover > 0)
|
||||
{
|
||||
// Wrap-around segment
|
||||
src.Slice(written + first, leftover)
|
||||
.CopyTo(new Span<byte>(_ring, _ringWrite, leftover));
|
||||
|
||||
@ -71,56 +70,28 @@ public class BlockingRingBuffer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> WaitForRoomToWrite(CancellationToken token)
|
||||
public int WaitForOutput(CancellationToken token)
|
||||
{
|
||||
while (true)
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
Debug.WriteLine("BlockingRingBuffer: WaitForRoomToWrite: operation cancelled.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lock (_ringLock)
|
||||
{
|
||||
var used = (_ringWrite >= _ringRead)
|
||||
var available = (_ringWrite >= _ringRead)
|
||||
? _ringWrite - _ringRead
|
||||
: _ring.Length - _ringRead + _ringWrite;
|
||||
|
||||
var free = _ring.Length - used - 1;
|
||||
|
||||
if (free > 0)
|
||||
return free;
|
||||
if (available > 0)
|
||||
return available;
|
||||
}
|
||||
|
||||
await Task.Delay(2).ConfigureAwait(false);
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
}
|
||||
public async Task<int> WaitForDataToRead(CancellationToken token)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
Debug.WriteLine("BlockingRingBuffer: WaitForDataToRead: operation cancelled.");
|
||||
|
||||
Debug.WriteLine("BlockingRingBuffer: Timeout waiting for output");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lock (_ringLock)
|
||||
{
|
||||
var used = (_ringWrite >= _ringRead)
|
||||
? _ringWrite - _ringRead
|
||||
: _ring.Length - _ringRead + _ringWrite;
|
||||
|
||||
if (used > 0)
|
||||
return used;
|
||||
}
|
||||
|
||||
await Task.Delay(2).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public int Read(Span<byte> dest, int maxBytes)
|
||||
public int DrainRing(Span<byte> dest, int maxBytes)
|
||||
{
|
||||
lock (_ringLock)
|
||||
{
|
||||
@ -149,7 +120,7 @@ public class BlockingRingBuffer
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
public void ResetRing()
|
||||
{
|
||||
lock (_ringLock)
|
||||
{
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AudioCore.Impl;
|
||||
|
||||
@ -7,13 +6,12 @@ public sealed class FfmpegAudioReader : IAudioReader, IDisposable
|
||||
{
|
||||
private readonly string _path;
|
||||
|
||||
// Lazy process wrapper
|
||||
private Lazy<FfmpegProcess> _process;
|
||||
|
||||
// Remember last seek position
|
||||
private long _pendingSeekSample = 0;
|
||||
|
||||
// NEW: internal position tracking (in floats)
|
||||
private long _pos = 0;
|
||||
|
||||
public int SampleRate { get; }
|
||||
public int Channels { get; }
|
||||
public long TotalSamples { get; }
|
||||
@ -33,55 +31,41 @@ public sealed class FfmpegAudioReader : IAudioReader, IDisposable
|
||||
_process = CreateLazyProcess();
|
||||
}
|
||||
|
||||
private Lazy<FfmpegProcess> CreateLazyProcess() =>
|
||||
new Lazy<FfmpegProcess>(() =>
|
||||
private Lazy<FfmpegProcess> CreateLazyProcess() => new Lazy<FfmpegProcess>(() =>
|
||||
{
|
||||
var startSeconds = (double)_pendingSeekSample / SampleRate;
|
||||
|
||||
var cmd =
|
||||
"-hide_banner -loglevel error " +
|
||||
"-nostdin " +
|
||||
$"-i \"{_path}\" " + // input first
|
||||
$"-ss {startSeconds.ToString(CultureInfo.InvariantCulture)} " + // output seek
|
||||
$"-ss {startSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture)} " +
|
||||
$"-i \"{_path}\" " +
|
||||
$"-f f32le -ac {Channels} -ar {SampleRate} pipe:1";
|
||||
|
||||
|
||||
var p = new FfmpegProcess(
|
||||
name: $"pipe:{_path}",
|
||||
commandLine: cmd,
|
||||
redirectOutput: true,
|
||||
redirectInput: false);
|
||||
redirectInput: true);
|
||||
|
||||
p.StartProcess();
|
||||
return p;
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Async float reader using new FfmpegProcess.ReadAsync
|
||||
/// </summary>
|
||||
public async Task<int> ReadAsync(Memory<float> buffer, CancellationToken token)
|
||||
public int Read(float[] buffer, int offset, int count)
|
||||
{
|
||||
var proc = _process.Value;
|
||||
var proc = _process.Value; // starts process if not started
|
||||
if (proc.Stdout is null)
|
||||
return 0;
|
||||
|
||||
int readFloats = await proc.ReadAsync(buffer, token).ConfigureAwait(false);
|
||||
|
||||
// NEW: update internal position
|
||||
_pos += readFloats;
|
||||
|
||||
return readFloats;
|
||||
return proc.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
public void Seek(long sampleIndex)
|
||||
{
|
||||
_pendingSeekSample = sampleIndex;
|
||||
|
||||
// NEW: update internal position (floats)
|
||||
_pos = sampleIndex * Channels;
|
||||
|
||||
DisposeProcessOnly();
|
||||
_process = CreateLazyProcess();
|
||||
_process = CreateLazyProcess(); // new lazy instance
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AudioCore.Impl;
|
||||
|
||||
@ -10,12 +9,10 @@ public sealed class FfmpegProcess : IDisposable
|
||||
public Stream? Stdout { get; private set; }
|
||||
public Stream? Stdin { get; private set; }
|
||||
|
||||
private readonly string _name;
|
||||
private readonly string _commandLine;
|
||||
private readonly bool _redirectOutput;
|
||||
private readonly bool _redirectInput;
|
||||
|
||||
private Task? _stderrTask;
|
||||
private string _name;
|
||||
private string _commandLine;
|
||||
private bool _redirectOutput;
|
||||
private bool _redirectInput;
|
||||
|
||||
public FfmpegProcess(string name, string commandLine, bool redirectOutput = true, bool redirectInput = true)
|
||||
{
|
||||
@ -49,72 +46,44 @@ public sealed class FfmpegProcess : IDisposable
|
||||
if (_redirectOutput)
|
||||
Stdout = Proc.StandardOutput.BaseStream;
|
||||
|
||||
_stderrTask = Task.Run(() => DrainStderrAsync(Proc));
|
||||
// Start draining stderr immediately
|
||||
_ = Task.Run(() => DrainStderr(Proc));
|
||||
}
|
||||
|
||||
private async Task DrainStderrAsync(Process proc)
|
||||
private void DrainStderr(Process proc)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var reader = proc.StandardError;
|
||||
while (true)
|
||||
{
|
||||
var line = await reader.ReadLineAsync().ConfigureAwait(false);
|
||||
if (line == null)
|
||||
break;
|
||||
var reader = proc.StandardError;
|
||||
|
||||
// ffmpeg writes short lines, so ReadLine is fine
|
||||
// If you want zero allocations, use ReadAsync into a rented buffer.
|
||||
string? line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
Debug.WriteLine($"{_name}: {line}");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore exceptions during stderr drain, as the process may have exited
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> ReadAsync(Memory<float> buffer, CancellationToken token)
|
||||
public int Read(float[] buffer, int offset, int count)
|
||||
{
|
||||
if (Stdout is null)
|
||||
return 0;
|
||||
var bytesNeeded = count * sizeof(float);
|
||||
var tmp = new byte[bytesNeeded];
|
||||
|
||||
int maxBytes = buffer.Length * sizeof(float);
|
||||
byte[] tmp = ArrayPool<byte>.Shared.Rent(maxBytes);
|
||||
|
||||
try
|
||||
{
|
||||
int readBytes = await Stdout.ReadAsync(tmp.AsMemory(0, maxBytes), token)
|
||||
.ConfigureAwait(false);
|
||||
var readBytes = Stdout!.Read(tmp, 0, bytesNeeded);
|
||||
if (readBytes <= 0)
|
||||
return 0;
|
||||
|
||||
int floatsRead = readBytes / sizeof(float);
|
||||
var floatMem = buffer.Slice(0, floatsRead);
|
||||
Buffer.BlockCopy(tmp, 0, buffer, offset * sizeof(float), readBytes);
|
||||
|
||||
// Copy raw bytes into the caller's float buffer
|
||||
var floatSpan = floatMem.Span;
|
||||
var byteSpan = MemoryMarshal.AsBytes(floatSpan);
|
||||
tmp.AsSpan(0, readBytes).CopyTo(byteSpan);
|
||||
|
||||
return floatsRead;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(tmp);
|
||||
}
|
||||
return readBytes / sizeof(float);
|
||||
}
|
||||
|
||||
public async Task WriteAsync(ReadOnlyMemory<byte> bytes, CancellationToken token)
|
||||
{
|
||||
if (Stdin is null)
|
||||
throw new InvalidOperationException("StdIn is not redirected");
|
||||
await Stdin.WriteAsync(bytes, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task FlushAsync(CancellationToken token)
|
||||
{
|
||||
if (Stdin is null)
|
||||
throw new InvalidOperationException("StdIn is not redirected");
|
||||
return Stdin.FlushAsync(token);
|
||||
}
|
||||
|
||||
private void DisposeProcessOnly()
|
||||
{
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AudioCore.Impl;
|
||||
|
||||
public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisposable
|
||||
public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IDisposable
|
||||
{
|
||||
private readonly AudioBufferPool _pool;
|
||||
private readonly int _sampleRate;
|
||||
@ -16,9 +17,8 @@ public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisp
|
||||
private BlockingRingBuffer _ring;
|
||||
private float _speed = 1.0f;
|
||||
|
||||
private Task? _readerTask;
|
||||
private CancellationTokenSource? _cts;
|
||||
private CancellationToken _token;
|
||||
private Thread? _readerThread;
|
||||
private bool _readerRunning;
|
||||
|
||||
public RubberBandTimeStretchEngine(AudioBufferPool pool, int sampleRate = 44100, int channels = 2)
|
||||
{
|
||||
@ -27,29 +27,35 @@ public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisp
|
||||
_channels = channels;
|
||||
|
||||
var bytesPerSecond = sampleRate * channels * sizeof(float);
|
||||
_ring = new BlockingRingBuffer( bytesPerSecond * 2);
|
||||
_ring = new BlockingRingBuffer(1 * bytesPerSecond);
|
||||
}
|
||||
|
||||
public async Task Configure(PlaybackSpeedSettings settings, CancellationToken token)
|
||||
public void Configure(PlaybackSpeedSettings settings)
|
||||
{
|
||||
if (Math.Abs(settings.Speed - _speed) < 0.0001f)
|
||||
return;
|
||||
|
||||
_speed = settings.Speed;
|
||||
|
||||
if ( _cts != null && _ff != null )
|
||||
await DisposeProcess().ConfigureAwait(false);
|
||||
|
||||
_ring.Reset();
|
||||
_token = token;
|
||||
if (Math.Abs(_speed - 1.0f) < 0.01f)
|
||||
{
|
||||
DisposeProcess();
|
||||
_ring.ResetRing();
|
||||
}
|
||||
else
|
||||
{
|
||||
RestartProcess();
|
||||
}
|
||||
}
|
||||
|
||||
public Task IsReadyToAccept(CancellationToken token) => _ring.WaitForRoomToWrite(token);
|
||||
|
||||
public Task Submit(MixedAudioBlock input, CancellationToken token)
|
||||
public Task Submit(MixedAudioBlock input)
|
||||
{
|
||||
// No-stretch path: enqueue block and signal semaphore
|
||||
if (Math.Abs(_speed - 1.0f) < 0.01f)
|
||||
{
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
var b = MemoryMarshal.AsBytes(input.Buffer.Span);
|
||||
_ring.Write(b, b.Length, token);
|
||||
_ring.WriteToOutput(b, b.Length, cts.Token);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -66,26 +72,28 @@ public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisp
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<TimeStretchedAudioBlock> Receive(CancellationToken token)
|
||||
public async Task<TimeStretchedAudioBlock> Receive()
|
||||
{
|
||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
|
||||
int available = 0;
|
||||
while (!token.IsCancellationRequested)
|
||||
while (!cts.IsCancellationRequested)
|
||||
{
|
||||
available = await _ring.WaitForDataToRead(token).ConfigureAwait(false);
|
||||
available = _ring.WaitForOutput(cts.Token);
|
||||
if (available > 0)
|
||||
break;
|
||||
|
||||
await Task.Delay(2).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
if (cts.IsCancellationRequested)
|
||||
return default;
|
||||
|
||||
var maxFloats = available / sizeof(float);
|
||||
var outBuf = _pool.Rent(maxFloats);
|
||||
var outBytes = MemoryMarshal.AsBytes(outBuf.Span);
|
||||
|
||||
var readBytes = _ring.Read(outBytes, outBytes.Length);
|
||||
var readBytes = _ring.DrainRing(outBytes, outBytes.Length);
|
||||
if (readBytes <= 0)
|
||||
{
|
||||
outBuf.Dispose();
|
||||
@ -119,48 +127,50 @@ public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisp
|
||||
_stdin = _ff.Stdin!;
|
||||
_stdout = _ff.Stdout!;
|
||||
|
||||
Debug.Assert(_cts == null);
|
||||
|
||||
_cts = CancellationTokenSource.CreateLinkedTokenSource(_token);
|
||||
_readerTask = Task.Run(ReaderLoop);
|
||||
_readerRunning = true;
|
||||
_readerThread = new Thread(ReaderLoop) { IsBackground = true };
|
||||
_readerThread.Start();
|
||||
}
|
||||
|
||||
private async Task ReaderLoop()
|
||||
private void RestartProcess()
|
||||
{
|
||||
Debug.Assert(_cts != null);
|
||||
DisposeProcess();
|
||||
_ring.ResetRing();
|
||||
StartProcess();
|
||||
}
|
||||
|
||||
private void ReaderLoop()
|
||||
{
|
||||
var buf = new byte[4096];
|
||||
|
||||
try
|
||||
{
|
||||
while (!_cts.Token.IsCancellationRequested)
|
||||
while (_readerRunning)
|
||||
{
|
||||
var read = await _stdout!.ReadAsync(buf, 0, buf.Length, _cts.Token).ConfigureAwait(false);
|
||||
var read = _stdout!.Read(buf, 0, buf.Length);
|
||||
if (read <= 0)
|
||||
break;
|
||||
|
||||
_ring.Write(buf, read, _cts.Token);
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
_ring.WriteToOutput(buf, read, cts.Token);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
|
||||
private async Task DisposeProcess()
|
||||
private void DisposeProcess()
|
||||
{
|
||||
_readerRunning = false;
|
||||
|
||||
try { _stdout?.Close(); } catch { }
|
||||
try { _stdin?.Close(); } catch { }
|
||||
try { _ff?.Dispose(); } catch { }
|
||||
|
||||
if (_readerTask != null)
|
||||
if (_readerThread != null)
|
||||
{
|
||||
Debug.Assert(_cts != null);
|
||||
|
||||
_cts.Cancel();
|
||||
try { await _readerTask.ConfigureAwait(false); } catch { }
|
||||
_readerTask = null;
|
||||
_cts.Dispose();
|
||||
_cts = null;
|
||||
try { _readerThread.Join(500); } catch { }
|
||||
_readerThread = null;
|
||||
}
|
||||
|
||||
_ff = null;
|
||||
@ -168,8 +178,8 @@ public sealed class RubberBandTimeStretchEngine : ITimeStretchEngine, IAsyncDisp
|
||||
_stdout = null;
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
public void Dispose()
|
||||
{
|
||||
await DisposeProcess().ConfigureAwait(false);
|
||||
DisposeProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using AudioCore.Impl;
|
||||
namespace AudioCore.Impl;
|
||||
|
||||
public sealed class StemDecoder : IStemDecoder
|
||||
{
|
||||
@ -25,29 +25,28 @@ public sealed class StemDecoder : IStemDecoder
|
||||
Stem.Duration = TimeSpan.FromSeconds((double)reader.TotalSamples / reader.SampleRate);
|
||||
}
|
||||
|
||||
public async Task<AudioBlock?> DecodeNextBlockAsync(CancellationToken token)
|
||||
public bool TryDecodeNextBlock(out AudioBlock block)
|
||||
{
|
||||
int channels = _reader.Channels;
|
||||
int floatsNeeded = _blockSize * channels;
|
||||
var channels = _reader.Channels;
|
||||
var floatsNeeded = _blockSize * channels;
|
||||
|
||||
var buf = _pool.Rent(floatsNeeded);
|
||||
|
||||
// Async read into Memory<float>
|
||||
int readFloats = await _reader.ReadAsync(buf.Samples.AsMemory(0, floatsNeeded), token)
|
||||
.ConfigureAwait(false);
|
||||
var readFloats = _reader.Read(buf.Samples, 0, floatsNeeded);
|
||||
|
||||
if (readFloats <= 0)
|
||||
{
|
||||
buf.Dispose();
|
||||
return null;
|
||||
block = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
buf.Length = readFloats;
|
||||
|
||||
long pos = _currentSample;
|
||||
var pos = _currentSample;
|
||||
_currentSample += readFloats / channels;
|
||||
|
||||
return new AudioBlock(buf, _reader.SampleRate, channels, pos);
|
||||
block = new AudioBlock(buf, _reader.SampleRate, channels, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Seek(long samplePosition)
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using NAudio.Wave;
|
||||
|
||||
namespace AudioCore.Impl;
|
||||
namespace AudioCore.Impl;
|
||||
|
||||
public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
{
|
||||
@ -39,19 +35,18 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
|
||||
private LoopRegion _loopRegion = new();
|
||||
|
||||
private long _decodedFramePosition;
|
||||
private long _currentFramePosition;
|
||||
private long _loopStartFrames;
|
||||
private long _loopEndFrames;
|
||||
|
||||
private long _outputFramesWritten;
|
||||
private float _currentSpeed = 1.0f;
|
||||
|
||||
private bool IsPlaying => _outputDevice.State == PlaybackState.Playing;
|
||||
private IProgressReporter<double>? _progressReporter;
|
||||
private bool _isPlaying;
|
||||
private IProgressReporter<TimeSpan>? _progressReporter;
|
||||
|
||||
private PipelineState? _pipeline;
|
||||
private long _pendingSeekFrames;
|
||||
|
||||
private readonly List<AudioBlock> _stemBlocks = new(8);
|
||||
|
||||
public StemPlaybackEngine(
|
||||
IStemDecoderFactory stemDecoderFactory,
|
||||
IAudioOutputDevice outputDevice,
|
||||
@ -73,18 +68,16 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadSessionAsync(PlaybackSession session, IProgressReporter<double> progress)
|
||||
public async Task LoadSessionAsync(PlaybackSession session, IProgressReporter<TimeSpan> progress)
|
||||
{
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
|
||||
await _timeStretchEngine.Configure(session.Speed, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
lock (_stateLock)
|
||||
{
|
||||
_session = session;
|
||||
_progressReporter = progress;
|
||||
|
||||
_currentSpeed = session.Speed.Speed;
|
||||
_timeStretchEngine.Configure(session.Speed);
|
||||
|
||||
_loopRegion = session.Loop;
|
||||
if (_loopRegion.IsEnabled)
|
||||
@ -99,8 +92,7 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
}
|
||||
|
||||
_pendingSeekFrames = 0;
|
||||
_decodedFramePosition = 0;
|
||||
_outputFramesWritten = 0;
|
||||
_currentFramePosition = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,14 +100,9 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
{
|
||||
lock (_stateLock)
|
||||
{
|
||||
if (IsPlaying || _session is null)
|
||||
if (_isPlaying || _session is null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (_pipeline is not null)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
_pipeline = new PipelineState
|
||||
{
|
||||
Decoders = _session.StemSet.Stems
|
||||
@ -130,10 +117,12 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
d.Seek(_pendingSeekFrames);
|
||||
}
|
||||
|
||||
_decodedFramePosition = _pendingSeekFrames;
|
||||
_outputFramesWritten = (long)(_decodedFramePosition / Math.Max(_currentSpeed, 0.0001f));
|
||||
_currentFramePosition = _pendingSeekFrames;
|
||||
|
||||
_pipeline.RenderTask = Task.Run(() => RenderLoopAsync(_pipeline, _pipeline.Cts.Token));
|
||||
_pipeline.RenderTask = Task.Run(() =>
|
||||
RenderLoopAsync(_pipeline, _pipeline.Cts!.Token));
|
||||
|
||||
_isPlaying = true;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@ -143,14 +132,17 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
{
|
||||
lock (_stateLock)
|
||||
{
|
||||
if (!IsPlaying)
|
||||
if (!_isPlaying)
|
||||
return Task.CompletedTask;
|
||||
|
||||
_outputDevice.Pause();
|
||||
_isPlaying = false;
|
||||
|
||||
if (_pipeline is not null && _pipeline.OutputStarted)
|
||||
{
|
||||
_outputDevice.Stop();
|
||||
_pipeline.OutputStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -161,12 +153,12 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
|
||||
lock (_stateLock)
|
||||
{
|
||||
if (!IsPlaying && _pipeline is null)
|
||||
if (!_isPlaying && _pipeline is null)
|
||||
return;
|
||||
|
||||
_decodedFramePosition = 0;
|
||||
_isPlaying = false;
|
||||
_currentFramePosition = 0;
|
||||
_pendingSeekFrames = 0;
|
||||
_outputFramesWritten = 0;
|
||||
|
||||
pipelineToDispose = _pipeline;
|
||||
_pipeline = null;
|
||||
@ -202,37 +194,8 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
foreach (var d in _pipeline.Decoders)
|
||||
d.Seek(frameIndex);
|
||||
|
||||
_decodedFramePosition = frameIndex;
|
||||
_outputFramesWritten = (long)(_decodedFramePosition / Math.Max(_currentSpeed, 0.0001f));
|
||||
_currentFramePosition = frameIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
_decodedFramePosition = frameIndex;
|
||||
_outputFramesWritten = (long)(_decodedFramePosition / Math.Max(_currentSpeed, 0.0001f));
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task UpdatePlaybackSpeedAsync(PlaybackSpeedSettings settings)
|
||||
{
|
||||
lock (_stateLock)
|
||||
{
|
||||
_currentSpeed = settings.Speed;
|
||||
_outputFramesWritten = (long)(_decodedFramePosition / Math.Max(_currentSpeed, 0.0001f));
|
||||
}
|
||||
|
||||
Debug.Assert(_pipeline?.Cts != null);
|
||||
await _timeStretchEngine.Configure(settings, _pipeline!.Cts!.Token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task UpdateMixerAsync(MixerSettings settings)
|
||||
{
|
||||
lock (_stateLock)
|
||||
{
|
||||
if (_session is not null)
|
||||
_session.Mixer = settings;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@ -270,24 +233,14 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private bool _decodeCompleted;
|
||||
|
||||
private async Task RenderLoopAsync(PipelineState pipeline, CancellationToken token)
|
||||
private async Task RenderLoopAsync(PipelineState pipeline, CancellationToken ct)
|
||||
{
|
||||
if (!pipeline.OutputStarted)
|
||||
{
|
||||
_outputDevice.Start();
|
||||
pipeline.OutputStarted = true;
|
||||
}
|
||||
var decodeTask = DecodeLoopAsync(pipeline, ct);
|
||||
var stretchTask = StretchLoopAsync(pipeline, ct);
|
||||
|
||||
_decodeCompleted = false;
|
||||
|
||||
var decodeTask = DecodeLoopAsync(pipeline, token);
|
||||
var stretchTask = StretchLoopAsync(pipeline, token);
|
||||
|
||||
// Wait for BOTH to finish naturally
|
||||
await Task.WhenAll(decodeTask, stretchTask).ConfigureAwait(false);
|
||||
await Task.WhenAny(decodeTask, stretchTask);
|
||||
|
||||
// When either loop ends, stop output
|
||||
if (pipeline.OutputStarted)
|
||||
{
|
||||
_outputDevice.Stop();
|
||||
@ -295,161 +248,118 @@ public sealed class StemPlaybackEngine : IStemPlaybackEngine, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task DecodeLoopAsync(PipelineState pipeline, CancellationToken token)
|
||||
private async Task DecodeLoopAsync(PipelineState pipeline, CancellationToken ct)
|
||||
{
|
||||
await Task.Yield();
|
||||
var stemBlocks = new List<AudioBlock>(6);
|
||||
|
||||
try
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
bool playing;
|
||||
MixerSettings? mixerSnapshot;
|
||||
IStemDecoder[] decodersSnapshot;
|
||||
long loopStart, loopEnd;
|
||||
bool loopEnabled;
|
||||
IProgressReporter<TimeSpan>? progressReporter;
|
||||
|
||||
lock (_stateLock)
|
||||
{
|
||||
playing = IsPlaying;
|
||||
playing = _isPlaying;
|
||||
mixerSnapshot = Mixer;
|
||||
decodersSnapshot = pipeline.Decoders;
|
||||
loopStart = _loopStartFrames;
|
||||
loopEnd = _loopEndFrames;
|
||||
loopEnabled = _loopRegion.IsEnabled;
|
||||
progressReporter = _progressReporter;
|
||||
}
|
||||
|
||||
if (!playing || mixerSnapshot is null || decodersSnapshot.Length == 0)
|
||||
{
|
||||
await Task.Delay(5, token).ConfigureAwait(false);
|
||||
await Task.Delay(5, ct);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!await ReadStemsAsync(stemBlocks, decodersSnapshot, token).ConfigureAwait(false))
|
||||
_stemBlocks.Clear();
|
||||
bool eof = false;
|
||||
|
||||
foreach (var decoder in decodersSnapshot)
|
||||
{
|
||||
DisposeStems(stemBlocks);
|
||||
if (!decoder.TryDecodeNextBlock(out var block))
|
||||
{
|
||||
eof = true;
|
||||
foreach (var b in _stemBlocks) b.Dispose();
|
||||
_stemBlocks.Clear();
|
||||
break;
|
||||
}
|
||||
|
||||
var mixed = _audioMixer.Mix(stemBlocks, mixerSnapshot);
|
||||
_stemBlocks.Add(block);
|
||||
}
|
||||
|
||||
DisposeStems(stemBlocks);
|
||||
if (eof)
|
||||
{
|
||||
lock (_stateLock)
|
||||
_isPlaying = false;
|
||||
break;
|
||||
}
|
||||
|
||||
await _timeStretchEngine.IsReadyToAccept(token).ConfigureAwait(false);
|
||||
await _timeStretchEngine.Submit(mixed, token).ConfigureAwait(false);
|
||||
var mixed = _audioMixer.Mix(_stemBlocks, mixerSnapshot);
|
||||
|
||||
foreach (var b in _stemBlocks)
|
||||
b.Dispose();
|
||||
_stemBlocks.Clear();
|
||||
|
||||
await _timeStretchEngine.Submit(mixed);
|
||||
|
||||
var progress = TimeSpan.FromSeconds(
|
||||
(double)_currentFramePosition / _outputDevice.SampleRate);
|
||||
|
||||
if (progressReporter != null)
|
||||
await progressReporter.ReportProgress(progress);
|
||||
|
||||
var nextPosition = mixed.SamplePosition + mixed.Frames;
|
||||
|
||||
if (loopEnabled && loopEnd > loopStart && nextPosition >= loopEnd)
|
||||
{
|
||||
lock (_stateLock)
|
||||
_decodedFramePosition = loopEnd;
|
||||
{
|
||||
_currentFramePosition = loopEnd;
|
||||
_isPlaying = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
lock (_stateLock)
|
||||
_decodedFramePosition = nextPosition;
|
||||
_currentFramePosition = nextPosition;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
_decodeCompleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void DisposeStems(List<AudioBlock> stemBlocks)
|
||||
private async Task StretchLoopAsync(PipelineState pipeline, CancellationToken ct)
|
||||
{
|
||||
foreach (var b in stemBlocks)
|
||||
b.Dispose();
|
||||
stemBlocks.Clear();
|
||||
}
|
||||
|
||||
private static async Task<bool> ReadStemsAsync(
|
||||
List<AudioBlock> stemBlocks,
|
||||
IStemDecoder[] decodersSnapshot,
|
||||
CancellationToken ct)
|
||||
{
|
||||
DisposeStems(stemBlocks);
|
||||
|
||||
foreach (var decoder in decodersSnapshot)
|
||||
{
|
||||
var block = await decoder.DecodeNextBlockAsync(ct).ConfigureAwait(false);
|
||||
if (block is null)
|
||||
{
|
||||
DisposeStems(stemBlocks);
|
||||
return false;
|
||||
}
|
||||
|
||||
stemBlocks.Add(block.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task StretchLoopAsync(PipelineState pipeline, CancellationToken token)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
try
|
||||
{
|
||||
var gotFirstBlock = false;
|
||||
while (!token.IsCancellationRequested)
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
var stretched = await _timeStretchEngine.Receive(token).ConfigureAwait(false);
|
||||
var stretched = await _timeStretchEngine.Receive();
|
||||
|
||||
if (stretched.Buffer == null)
|
||||
{
|
||||
if (_decodeCompleted && gotFirstBlock)
|
||||
break; // fully drained
|
||||
|
||||
await Task.Delay(1, token).ConfigureAwait(false);
|
||||
await Task.Delay(1, ct);
|
||||
continue;
|
||||
}
|
||||
|
||||
await _outputDevice.IsReadyToAccept(token).ConfigureAwait(false);
|
||||
if (!pipeline.OutputStarted)
|
||||
{
|
||||
_outputDevice.Start();
|
||||
pipeline.OutputStarted = true;
|
||||
}
|
||||
|
||||
_outputDevice.Write(stretched.Buffer.Span);
|
||||
gotFirstBlock = true;
|
||||
|
||||
lock (_stateLock)
|
||||
{
|
||||
_outputFramesWritten += stretched.Frames;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
long sourceFrames;
|
||||
lock (_stateLock)
|
||||
{
|
||||
sourceFrames = (long)(_outputFramesWritten * _currentSpeed);
|
||||
}
|
||||
|
||||
double progress;
|
||||
lock (_stateLock)
|
||||
{
|
||||
var total = _session?.StemSet.TotalFrames ?? 1L;
|
||||
progress = (double)sourceFrames / Math.Max(total, 1L);
|
||||
}
|
||||
|
||||
if (_progressReporter != null)
|
||||
await _progressReporter.ReportProgress(progress).ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
try { stretched.Dispose(); } catch { }
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"StemPlaybackEngine: Error in PlaybackLoopAsync: {ex.Message}");
|
||||
try { pipeline.Cts?.Cancel(); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private long TimeToFrames(TimeSpan time)
|
||||
{
|
||||
|
||||
@ -36,12 +36,11 @@ public sealed class StemWaveformService : IStemWaveformService
|
||||
var count = 0;
|
||||
|
||||
// Decode only one block per segment
|
||||
var block = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
if (block != null)
|
||||
if (decoder.TryDecodeNextBlock(out var block))
|
||||
{
|
||||
try
|
||||
{
|
||||
var span = block.Value.Span;
|
||||
var span = block.Span;
|
||||
var channels = decoder.Stem.Channels;
|
||||
|
||||
for (var s = 0; s < span.Length; s++)
|
||||
@ -54,7 +53,7 @@ public sealed class StemWaveformService : IStemWaveformService
|
||||
}
|
||||
finally
|
||||
{
|
||||
block.Value.Dispose();
|
||||
block.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -71,8 +71,6 @@ public sealed class WasapiOutputDevice : IAudioOutputDevice, IDisposable
|
||||
|
||||
public void Start() => _out.Play();
|
||||
public void Stop() => _out.Stop();
|
||||
public void Pause() => _out.Pause();
|
||||
public PlaybackState State => _out.PlaybackState;
|
||||
|
||||
public void Write(ReadOnlySpan<float> samples)
|
||||
{
|
||||
@ -103,50 +101,17 @@ public sealed class WasapiOutputDevice : IAudioOutputDevice, IDisposable
|
||||
|
||||
}
|
||||
|
||||
private Lock _lock = new();
|
||||
|
||||
public async Task IsReadyToAccept(CancellationToken token)
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
int free = _buffer.BufferLength - _buffer.BufferedBytes;
|
||||
if (free > 0)
|
||||
return;
|
||||
|
||||
await Task.Delay(2, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Send(byte[] bytes)
|
||||
{
|
||||
if (_out.PlaybackState != PlaybackState.Playing)
|
||||
return;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
|
||||
int offset = 0;
|
||||
|
||||
while (offset < bytes.Length)
|
||||
{
|
||||
if (_out.PlaybackState != PlaybackState.Playing)
|
||||
return;
|
||||
|
||||
int free = _buffer.BufferLength - _buffer.BufferedBytes;
|
||||
if (free <= 0)
|
||||
// Wait until buffer has enough free space
|
||||
while (_buffer.BufferedBytes + bytes.Length > _buffer.BufferLength)
|
||||
{
|
||||
// Sleep a tiny amount to let WASAPI consume data
|
||||
Thread.Sleep(2);
|
||||
continue;
|
||||
}
|
||||
|
||||
int toWrite = Math.Min(free, bytes.Length - offset);
|
||||
|
||||
_buffer.AddSamples(bytes, offset, toWrite);
|
||||
offset += toWrite;
|
||||
_buffer.AddSamples(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
using NAudio.Wave;
|
||||
|
||||
namespace AudioCore.Interfaces;
|
||||
|
||||
public interface IAudioOutputDevice
|
||||
@ -7,12 +5,8 @@ public interface IAudioOutputDevice
|
||||
int SampleRate { get; }
|
||||
int Channels { get; }
|
||||
|
||||
Task IsReadyToAccept(CancellationToken token);
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
void Pause();
|
||||
PlaybackState State { get; }
|
||||
|
||||
// Push interleaved float32 PCM
|
||||
void Write(ReadOnlySpan<float> samples);
|
||||
|
||||
@ -8,7 +8,7 @@ public interface IAudioReader : IDisposable
|
||||
|
||||
// Read PCM float samples into the provided buffer.
|
||||
// Returns number of samples actually read.
|
||||
Task<int> ReadAsync(Memory<float> buffer, CancellationToken token);
|
||||
int Read(float[] buffer, int offset, int count);
|
||||
|
||||
// Seek to absolute sample index.
|
||||
void Seek(long sampleIndex);
|
||||
|
||||
@ -4,7 +4,7 @@ public interface IStemDecoder : IDisposable
|
||||
{
|
||||
StemTrack Stem { get; }
|
||||
|
||||
Task<AudioBlock?> DecodeNextBlockAsync(CancellationToken token);
|
||||
bool TryDecodeNextBlock(out AudioBlock block);
|
||||
|
||||
void Seek(long samplePosition);
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ public interface IStemPlaybackEngine
|
||||
{
|
||||
PlaybackSession? CurrentSession { get; }
|
||||
|
||||
Task LoadSessionAsync(PlaybackSession session, IProgressReporter<double> progressReporter);
|
||||
Task LoadSessionAsync(PlaybackSession session, IProgressReporter<TimeSpan> progressReporter);
|
||||
|
||||
// Transport
|
||||
Task PlayAsync();
|
||||
@ -12,10 +12,6 @@ public interface IStemPlaybackEngine
|
||||
Task StopAsync();
|
||||
Task SeekAsync(TimeSpan position);
|
||||
|
||||
// Dynamic controls
|
||||
Task UpdatePlaybackSpeedAsync(PlaybackSpeedSettings settings);
|
||||
Task UpdateMixerAsync(MixerSettings settings);
|
||||
|
||||
// Loop
|
||||
void SetLoop(TimeSpan start, TimeSpan end);
|
||||
void ClearLoop();
|
||||
|
||||
@ -8,10 +8,9 @@ public sealed class PlaybackSpeedSettings
|
||||
|
||||
public interface ITimeStretchEngine
|
||||
{
|
||||
Task Configure(PlaybackSpeedSettings settings, CancellationToken token);
|
||||
void Configure(PlaybackSpeedSettings settings);
|
||||
|
||||
// Streaming block processing
|
||||
Task IsReadyToAccept(CancellationToken token);
|
||||
Task Submit(MixedAudioBlock input, CancellationToken token);
|
||||
Task<TimeStretchedAudioBlock> Receive(CancellationToken token);
|
||||
Task Submit(MixedAudioBlock input);
|
||||
Task<TimeStretchedAudioBlock> Receive();
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ namespace AudioCore.Models;
|
||||
public sealed class PlaybackSession
|
||||
{
|
||||
public StemSet StemSet { get; init; } = default!;
|
||||
public long TotalFrames => StemSet?.TotalFrames ?? 0;
|
||||
public MixerSettings Mixer { get; set; } = new() { Stems = [] };
|
||||
public LoopRegion Loop { get; set; } = new();
|
||||
public PlaybackSpeedSettings Speed { get; set; } = new();
|
||||
|
||||
@ -4,6 +4,4 @@ public sealed class StemSet
|
||||
{
|
||||
public string OriginalFilePath { get; init; } = string.Empty;
|
||||
public IReadOnlyList<StemTrack> Stems { get; init; } = Array.Empty<StemTrack>();
|
||||
|
||||
public long TotalFrames => Stems.Max(s => s.TotalFrames);
|
||||
}
|
||||
|
||||
@ -9,6 +9,4 @@ public sealed class StemTrack
|
||||
public int SampleRate { get; set; }
|
||||
public int Channels { get; set; }
|
||||
public float[] Waveform { get; set; } = [];
|
||||
|
||||
public long TotalFrames => (long)(Duration.TotalMilliseconds * SampleRate / 1000.0);
|
||||
}
|
||||
|
||||
@ -15,10 +15,10 @@ public sealed class BlockingRingBuffer_Tests
|
||||
for (int i = 0; i < src.Length; i++)
|
||||
src[i] = (byte)i;
|
||||
|
||||
ring.Write(src, src.Length, ct);
|
||||
ring.WriteToOutput(src, src.Length, ct);
|
||||
|
||||
Span<byte> dest = stackalloc byte[100];
|
||||
int read = ring.Read(dest, dest.Length);
|
||||
int read = ring.DrainRing(dest, dest.Length);
|
||||
|
||||
Assert.AreEqual(100, read);
|
||||
for (int i = 0; i < 100; i++)
|
||||
@ -36,11 +36,11 @@ public sealed class BlockingRingBuffer_Tests
|
||||
for (int i = 0; i < first.Length; i++)
|
||||
first[i] = (byte)(i + 1);
|
||||
|
||||
ring.Write(first, first.Length, ct);
|
||||
ring.WriteToOutput(first, first.Length, ct);
|
||||
|
||||
// Drain a bit to force wrap
|
||||
Span<byte> tmp = stackalloc byte[10];
|
||||
int drained = ring.Read(tmp, tmp.Length);
|
||||
int drained = ring.DrainRing(tmp, tmp.Length);
|
||||
Assert.AreEqual(10, drained);
|
||||
|
||||
// Now write again, forcing wrap-around
|
||||
@ -48,11 +48,11 @@ public sealed class BlockingRingBuffer_Tests
|
||||
for (int i = 0; i < second.Length; i++)
|
||||
second[i] = (byte)(100 + i);
|
||||
|
||||
ring.Write(second, second.Length, ct);
|
||||
ring.WriteToOutput(second, second.Length, ct);
|
||||
|
||||
// Drain everything
|
||||
Span<byte> dest = stackalloc byte[25];
|
||||
int read = ring.Read(dest, dest.Length);
|
||||
int read = ring.DrainRing(dest, dest.Length);
|
||||
|
||||
Assert.AreEqual(25, read);
|
||||
|
||||
@ -71,7 +71,7 @@ public sealed class BlockingRingBuffer_Tests
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
byte[] src = new byte[63]; // fills ring completely (63 bytes free)
|
||||
ring.Write(src, src.Length, CancellationToken.None);
|
||||
ring.WriteToOutput(src, src.Length, CancellationToken.None);
|
||||
|
||||
bool writeCompleted = false;
|
||||
|
||||
@ -80,7 +80,7 @@ public sealed class BlockingRingBuffer_Tests
|
||||
try
|
||||
{
|
||||
// This should block until space is freed
|
||||
ring.Write(new byte[10], 10, cts.Token);
|
||||
ring.WriteToOutput(new byte[10], 10, cts.Token);
|
||||
writeCompleted = true;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@ -96,7 +96,7 @@ public sealed class BlockingRingBuffer_Tests
|
||||
|
||||
// Drain some space
|
||||
Span<byte> drain = stackalloc byte[20];
|
||||
int drained = ring.Read(drain, drain.Length);
|
||||
int drained = ring.DrainRing(drain, drain.Length);
|
||||
Assert.IsGreaterThan(0, drained);
|
||||
|
||||
// Writer should now complete
|
||||
@ -104,49 +104,49 @@ public sealed class BlockingRingBuffer_Tests
|
||||
Assert.IsTrue(writeCompleted, "Writer should unblock after draining");
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
//public void Write_Cancels_WhenFull()
|
||||
//{
|
||||
// var ring = new BlockingRingBuffer(32);
|
||||
// var cts = new CancellationTokenSource();
|
||||
[TestMethod]
|
||||
public void Write_Cancels_WhenFull()
|
||||
{
|
||||
var ring = new BlockingRingBuffer(32);
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
// // Fill ring
|
||||
// ring.WriteToOutput(new byte[31], 31, CancellationToken.None);
|
||||
// Fill ring
|
||||
ring.WriteToOutput(new byte[31], 31, CancellationToken.None);
|
||||
|
||||
// bool canceled = false;
|
||||
bool canceled = false;
|
||||
|
||||
// var writerThread = new Thread(() =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// ring.WriteToOutput(new byte[10], 10, cts.Token);
|
||||
// }
|
||||
// catch (OperationCanceledException)
|
||||
// {
|
||||
// canceled = true;
|
||||
// }
|
||||
// });
|
||||
var writerThread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ring.WriteToOutput(new byte[10], 10, cts.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
canceled = true;
|
||||
}
|
||||
});
|
||||
|
||||
// writerThread.Start();
|
||||
writerThread.Start();
|
||||
|
||||
// Thread.Sleep(50);
|
||||
// cts.Cancel();
|
||||
Thread.Sleep(50);
|
||||
cts.Cancel();
|
||||
|
||||
// writerThread.Join();
|
||||
writerThread.Join();
|
||||
|
||||
// Assert.IsTrue(canceled, "Writer should throw OperationCanceledException");
|
||||
//}
|
||||
Assert.IsTrue(canceled, "Writer should throw OperationCanceledException");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task WaitForOutput_ReturnsAvailable()
|
||||
public void WaitForOutput_ReturnsAvailable()
|
||||
{
|
||||
var ring = new BlockingRingBuffer(128);
|
||||
var ct = CancellationToken.None;
|
||||
|
||||
byte[] src = new byte[50];
|
||||
ring.Write(src, src.Length, ct);
|
||||
ring.WriteToOutput(src, src.Length, ct);
|
||||
|
||||
int available = await ring.WaitForDataToRead(ct);
|
||||
int available = ring.WaitForOutput(ct);
|
||||
|
||||
Assert.AreEqual(50, available);
|
||||
}
|
||||
@ -157,12 +157,12 @@ public sealed class BlockingRingBuffer_Tests
|
||||
var ring = new BlockingRingBuffer(128);
|
||||
var ct = CancellationToken.None;
|
||||
|
||||
ring.Write(new byte[60], 60, ct);
|
||||
ring.WriteToOutput(new byte[60], 60, ct);
|
||||
|
||||
ring.Reset();
|
||||
ring.ResetRing();
|
||||
|
||||
Span<byte> dest = stackalloc byte[128];
|
||||
int read = ring.Read(dest, dest.Length);
|
||||
int read = ring.DrainRing(dest, dest.Length);
|
||||
|
||||
Assert.AreEqual(0, read);
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Buffers;
|
||||
using AudioCore.Interfaces;
|
||||
using AudioCore.Interfaces;
|
||||
|
||||
namespace AudioCore_Tests;
|
||||
|
||||
@ -21,29 +20,19 @@ public sealed class FakeAudioReader : IAudioReader
|
||||
_pos = 0;
|
||||
}
|
||||
|
||||
public Task<int> ReadAsync(Memory<float> buffer, CancellationToken token)
|
||||
public int Read(float[] buffer, int offset, int count)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException(nameof(FakeAudioReader));
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
return Task.FromCanceled<int>(token);
|
||||
|
||||
// How many floats remain?
|
||||
long remaining = _data.Length - _pos;
|
||||
var remaining = _data.Length - _pos;
|
||||
if (remaining <= 0)
|
||||
return Task.FromResult(0);
|
||||
return 0;
|
||||
|
||||
// How many floats can we copy?
|
||||
int toCopy = (int)Math.Min(buffer.Length, remaining);
|
||||
|
||||
// Copy from backing array into caller's buffer
|
||||
_data.AsMemory((int)_pos, toCopy).CopyTo(buffer);
|
||||
|
||||
// Advance position
|
||||
_pos += toCopy;
|
||||
|
||||
return Task.FromResult(toCopy);
|
||||
var toRead = (int)Math.Min(count, remaining);
|
||||
Array.Copy(_data, _pos, buffer, offset, toRead);
|
||||
_pos += toRead;
|
||||
return toRead;
|
||||
}
|
||||
|
||||
public void Seek(long samplePosition)
|
||||
|
||||
@ -28,34 +28,37 @@ public sealed class FfmpegAudioReader_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Reader_Reads_Some_Samples()
|
||||
public void Reader_Reads_Some_Samples()
|
||||
{
|
||||
using var reader = new FfmpegAudioReader(_inputPath);
|
||||
|
||||
var buf = new float[44100];
|
||||
var read = await reader.ReadAsync(buf.AsMemory(), CancellationToken.None);
|
||||
var buf = new float[44100]; // 0.5 sec stereo = 22050 frames
|
||||
var read = reader.Read(buf, 0, buf.Length);
|
||||
|
||||
Assert.IsGreaterThan(0, read, "Reader returned no samples");
|
||||
Assert.IsLessThanOrEqualTo(buf.Length, read);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Reader_Seek_Works()
|
||||
public void Reader_Seek_Works()
|
||||
{
|
||||
using var reader = new FfmpegAudioReader(_inputPath);
|
||||
|
||||
var buf1 = new float[44100];
|
||||
var buf2 = new float[44100];
|
||||
|
||||
var r1 = await reader.ReadAsync(buf1.AsMemory(), CancellationToken.None);
|
||||
// Read from start
|
||||
var r1 = reader.Read(buf1, 0, buf1.Length);
|
||||
Assert.IsGreaterThan(0, r1);
|
||||
|
||||
reader.Seek(reader.SampleRate*5);
|
||||
// Seek to 1 second
|
||||
reader.Seek(reader.SampleRate);
|
||||
|
||||
var r2 = await reader.ReadAsync(buf2.AsMemory(), CancellationToken.None);
|
||||
var r2 = reader.Read(buf2, 0, buf2.Length);
|
||||
Assert.IsGreaterThan(0, r2);
|
||||
|
||||
bool identical = true;
|
||||
// Buffers should differ
|
||||
var identical = true;
|
||||
for (var i = 0; i < Math.Min(r1, r2); i++)
|
||||
{
|
||||
if (buf1[i] != buf2[i])
|
||||
@ -69,22 +72,23 @@ public sealed class FfmpegAudioReader_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Reader_Reset_Works()
|
||||
public void Reader_Reset_Works()
|
||||
{
|
||||
using var reader = new FfmpegAudioReader(_inputPath);
|
||||
|
||||
var buf1 = new float[44100];
|
||||
var buf2 = new float[44100];
|
||||
|
||||
var r1 = await reader.ReadAsync(buf1.AsMemory(), CancellationToken.None);
|
||||
var r1 = reader.Read(buf1, 0, buf1.Length);
|
||||
Assert.IsGreaterThan(0, r1);
|
||||
|
||||
reader.Reset();
|
||||
|
||||
var r2 = await reader.ReadAsync(buf2.AsMemory(), CancellationToken.None);
|
||||
var r2 = reader.Read(buf2, 0, buf2.Length);
|
||||
Assert.IsGreaterThan(0, r2);
|
||||
|
||||
bool identical = true;
|
||||
// After reset, buffers should match again
|
||||
var identical = true;
|
||||
for (var i = 0; i < Math.Min(r1, r2); i++)
|
||||
{
|
||||
if (buf1[i] != buf2[i])
|
||||
@ -105,13 +109,15 @@ public sealed class FfmpegAudioReader_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Reader_Can_Read_Flac_File()
|
||||
public void Reader_Can_Read_Flac_File()
|
||||
{
|
||||
// Arrange
|
||||
var baseDir = AppContext.BaseDirectory;
|
||||
var flacPath = Path.Combine(baseDir, "Data", "test_input_converted.flac");
|
||||
|
||||
try
|
||||
{
|
||||
// Convert MP3 → FLAC using FFmpeg
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = "ffmpeg",
|
||||
@ -125,33 +131,39 @@ public sealed class FfmpegAudioReader_Tests
|
||||
|
||||
using (var p = Process.Start(psi) ?? throw new InvalidOperationException("Failed to start FFmpeg process"))
|
||||
{
|
||||
// Start draining stderr immediately
|
||||
_ = Task.Run(() => DrainStderr(p));
|
||||
p.WaitForExit();
|
||||
|
||||
p!.WaitForExit();
|
||||
Assert.AreEqual(0, p.ExitCode, "FFmpeg failed to convert MP3 to FLAC");
|
||||
}
|
||||
|
||||
Assert.IsTrue(File.Exists(flacPath), "FLAC file was not created");
|
||||
|
||||
// Act
|
||||
using var reader = new FfmpegAudioReader(flacPath);
|
||||
|
||||
// Assert basic properties
|
||||
Assert.AreEqual(44100, reader.SampleRate);
|
||||
Assert.AreEqual(2, reader.Channels);
|
||||
Assert.IsGreaterThan(0, reader.TotalSamples);
|
||||
|
||||
// Read some samples
|
||||
var buf = new float[44100];
|
||||
var read = await reader.ReadAsync(buf.AsMemory(), CancellationToken.None);
|
||||
var read = reader.Read(buf, 0, buf.Length);
|
||||
|
||||
Assert.IsGreaterThan(0, read);
|
||||
Assert.IsGreaterThan(0, read, "FLAC reader returned no samples");
|
||||
Assert.IsLessThanOrEqualTo(buf.Length, read);
|
||||
|
||||
reader.Seek(reader.SampleRate);
|
||||
|
||||
// Seek test
|
||||
reader.Seek(reader.SampleRate); // 1 second
|
||||
var buf2 = new float[44100];
|
||||
var read2 = await reader.ReadAsync(buf2.AsMemory(), CancellationToken.None);
|
||||
var read2 = reader.Read(buf2, 0, buf2.Length);
|
||||
|
||||
Assert.IsGreaterThan(0, read2);
|
||||
|
||||
bool identical = true;
|
||||
// Buffers should differ after seek
|
||||
var identical = true;
|
||||
for (var i = 0; i < Math.Min(read, read2); i++)
|
||||
{
|
||||
if (buf[i] != buf2[i])
|
||||
@ -163,14 +175,15 @@ public sealed class FfmpegAudioReader_Tests
|
||||
|
||||
Assert.IsFalse(identical, "Seek did not change decoded FLAC samples");
|
||||
|
||||
// Reset test
|
||||
reader.Reset();
|
||||
|
||||
var buf3 = new float[44100];
|
||||
var read3 = await reader.ReadAsync(buf3.AsMemory(), CancellationToken.None);
|
||||
var read3 = reader.Read(buf3, 0, buf3.Length);
|
||||
|
||||
Assert.IsGreaterThan(0, read3);
|
||||
|
||||
bool matchAfterReset = true;
|
||||
// After reset, buf3 should match buf
|
||||
var matchAfterReset = true;
|
||||
for (var i = 0; i < Math.Min(read, read3); i++)
|
||||
{
|
||||
if (buf[i] != buf3[i])
|
||||
@ -184,12 +197,13 @@ public sealed class FfmpegAudioReader_Tests
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Cleanup even if test fails
|
||||
try
|
||||
{
|
||||
if (File.Exists(flacPath))
|
||||
File.Delete(flacPath);
|
||||
}
|
||||
catch { }
|
||||
catch { /* swallow */ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,6 +212,9 @@ public sealed class FfmpegAudioReader_Tests
|
||||
try
|
||||
{
|
||||
var reader = proc.StandardError;
|
||||
|
||||
// ffmpeg writes short lines, so ReadLine is fine
|
||||
// If you want zero allocations, use ReadAsync into a rented buffer.
|
||||
string? line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
@ -209,4 +226,5 @@ public sealed class FfmpegAudioReader_Tests
|
||||
Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public sealed class Pipeline_Integration_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FullPipeline_Decoder_Mixer_Encoder_Works()
|
||||
public void FullPipeline_Decoder_Mixer_Encoder_Works()
|
||||
{
|
||||
var pool = new AudioBufferPool();
|
||||
var readerFactory = new FfmpegAudioReaderFactory();
|
||||
@ -79,7 +79,7 @@ public sealed class Pipeline_Integration_Tests
|
||||
|
||||
using var ff = Process.Start(psi);
|
||||
var stdin = ff!.StandardInput.BaseStream;
|
||||
|
||||
// Start draining stderr immediately
|
||||
_ = Task.Run(() => DrainStderr(ff));
|
||||
|
||||
var running = true;
|
||||
@ -90,8 +90,7 @@ public sealed class Pipeline_Integration_Tests
|
||||
|
||||
foreach (var d in decoders)
|
||||
{
|
||||
var block = await d.DecodeNextBlockAsync(CancellationToken.None);
|
||||
if (block is null)
|
||||
if (!d.TryDecodeNextBlock(out var block))
|
||||
{
|
||||
foreach (var b in blocks)
|
||||
b.Dispose();
|
||||
@ -100,7 +99,7 @@ public sealed class Pipeline_Integration_Tests
|
||||
break;
|
||||
}
|
||||
|
||||
blocks.Add(block.Value);
|
||||
blocks.Add(block);
|
||||
}
|
||||
|
||||
if (!running)
|
||||
@ -108,12 +107,9 @@ public sealed class Pipeline_Integration_Tests
|
||||
|
||||
var mixed = mixer.Mix(blocks, settings);
|
||||
|
||||
// Convert float → bytes
|
||||
ReadOnlySpan<float> span = mixed.Buffer.Span;
|
||||
ReadOnlyMemory<byte> bytes = MemoryMarshal.AsBytes(span).ToArray();
|
||||
|
||||
await stdin.WriteAsync(bytes, CancellationToken.None);
|
||||
await stdin.FlushAsync(CancellationToken.None);
|
||||
var span = mixed.Buffer.Span;
|
||||
var bytes = MemoryMarshal.AsBytes(span);
|
||||
stdin.Write(bytes);
|
||||
|
||||
mixed.Dispose();
|
||||
foreach (var b in blocks)
|
||||
@ -130,7 +126,7 @@ public sealed class Pipeline_Integration_Tests
|
||||
|
||||
using var verify = new FfmpegAudioReader(outFlac);
|
||||
var buf = new float[4096];
|
||||
var read = await verify.ReadAsync(buf.AsMemory(), CancellationToken.None);
|
||||
var read = verify.Read(buf, 0, buf.Length);
|
||||
|
||||
Assert.IsGreaterThan(0, read, "FLAC output is not decodable");
|
||||
}
|
||||
@ -140,6 +136,9 @@ public sealed class Pipeline_Integration_Tests
|
||||
try
|
||||
{
|
||||
var reader = proc.StandardError;
|
||||
|
||||
// ffmpeg writes short lines, so ReadLine is fine
|
||||
// If you want zero allocations, use ReadAsync into a rented buffer.
|
||||
string? line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
|
||||
@ -7,21 +7,18 @@ namespace AudioCore_Tests;
|
||||
public sealed class StemDecoder_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task DecodeNextBlockAsync_ReturnsBlock()
|
||||
public void TryDecodeNextBlock_ReturnsBlock()
|
||||
{
|
||||
var pool = new AudioBufferPool();
|
||||
var samples = Enumerable.Range(0, 48000).Select(i => (float)i).ToArray();
|
||||
var samples = Enumerable.Range(0, 48000).Select(i => (float)i).ToArray(); // 1 sec stereo
|
||||
var reader = new FakeAudioReader(samples, 48000, 2);
|
||||
var stem = new StemTrack{ Name = "test", FilePath = "file.wav" };
|
||||
|
||||
var decoder = new StemDecoder(reader, pool, stem, blockSize: 1024);
|
||||
|
||||
var nullableBlock = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
|
||||
Assert.IsNotNull(nullableBlock);
|
||||
|
||||
var block = nullableBlock.Value;
|
||||
var ok = decoder.TryDecodeNextBlock(out var block);
|
||||
|
||||
Assert.IsTrue(ok);
|
||||
Assert.AreEqual(1024, block.Frames);
|
||||
Assert.AreEqual(0, block.Position);
|
||||
Assert.AreEqual(48000, block.SampleRate);
|
||||
@ -31,7 +28,7 @@ public sealed class StemDecoder_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DecodeNextBlockAsync_AdvancesPosition()
|
||||
public void TryDecodeNextBlock_AdvancesPosition()
|
||||
{
|
||||
var pool = new AudioBufferPool();
|
||||
var samples = Enumerable.Range(0, 48000).Select(i => (float)i).ToArray();
|
||||
@ -40,21 +37,18 @@ public sealed class StemDecoder_Tests
|
||||
|
||||
var decoder = new StemDecoder(reader, pool, stem, blockSize: 1000);
|
||||
|
||||
var b1 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
var b2 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
decoder.TryDecodeNextBlock(out var b1);
|
||||
decoder.TryDecodeNextBlock(out var b2);
|
||||
|
||||
Assert.IsNotNull(b1);
|
||||
Assert.IsNotNull(b2);
|
||||
Assert.AreEqual(0, b1.Position);
|
||||
Assert.AreEqual(1000, b2.Position);
|
||||
|
||||
Assert.AreEqual(0, b1!.Value.Position);
|
||||
Assert.AreEqual(1000, b2!.Value.Position);
|
||||
|
||||
b1.Value.Dispose();
|
||||
b2.Value.Dispose();
|
||||
b1.Dispose();
|
||||
b2.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Seek_MovesReaderAndDecoderPosition()
|
||||
public void Seek_MovesReaderAndDecoderPosition()
|
||||
{
|
||||
var pool = new AudioBufferPool();
|
||||
var samples = Enumerable.Range(0, 48000).Select(i => (float)i).ToArray();
|
||||
@ -63,19 +57,18 @@ public sealed class StemDecoder_Tests
|
||||
|
||||
var decoder = new StemDecoder(reader, pool, stem, blockSize: 500);
|
||||
|
||||
decoder.Seek(2000);
|
||||
decoder.Seek(2000); // sample position
|
||||
|
||||
var block = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
decoder.TryDecodeNextBlock(out var block);
|
||||
|
||||
Assert.IsNotNull(block);
|
||||
Assert.AreEqual(2000, block!.Value.Position);
|
||||
Assert.AreEqual(500, block.Value.Frames);
|
||||
Assert.AreEqual(2000, block.Position);
|
||||
Assert.AreEqual(500, block.Frames);
|
||||
|
||||
block.Value.Dispose();
|
||||
block.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Reset_ReturnsToStart()
|
||||
public void Reset_ReturnsToStart()
|
||||
{
|
||||
var pool = new AudioBufferPool();
|
||||
var samples = Enumerable.Range(0, 48000).Select(i => (float)i).ToArray();
|
||||
@ -84,39 +77,45 @@ public sealed class StemDecoder_Tests
|
||||
|
||||
var decoder = new StemDecoder(reader, pool, stem, blockSize: 500);
|
||||
|
||||
var b1 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
decoder.TryDecodeNextBlock(out var b1);
|
||||
decoder.Reset();
|
||||
var b2 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
decoder.TryDecodeNextBlock(out var b2);
|
||||
|
||||
Assert.IsNotNull(b2);
|
||||
Assert.AreEqual(0, b2!.Value.Position);
|
||||
Assert.AreEqual(0, b2.Position);
|
||||
|
||||
b1!.Value.Dispose();
|
||||
b2!.Value.Dispose();
|
||||
b1.Dispose();
|
||||
b2.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DecodeNextBlockAsync_ReturnsNullAtEnd()
|
||||
public void TryDecodeNextBlock_ReturnsFalseAtEnd()
|
||||
{
|
||||
var pool = new AudioBufferPool();
|
||||
var samples = new float[2000];
|
||||
var samples = new float[2000]; // small buffer
|
||||
var reader = new FakeAudioReader(samples, 48000, 2);
|
||||
var stem = new StemTrack { Name = "test", FilePath = "file.wav" };
|
||||
|
||||
var decoder = new StemDecoder(reader, pool, stem, blockSize: 1024);
|
||||
|
||||
var b1 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
Assert.IsNotNull(b1);
|
||||
b1!.Value.Dispose();
|
||||
// First block: should succeed
|
||||
Assert.IsTrue(decoder.TryDecodeNextBlock(out var b1));
|
||||
Assert.IsNotNull(b1.Buffer);
|
||||
b1.Dispose();
|
||||
|
||||
var b2 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
if (b2 != null)
|
||||
b2!.Value.Dispose();
|
||||
// Second block: may succeed or partially succeed
|
||||
decoder.TryDecodeNextBlock(out var b2);
|
||||
if (b2.Buffer != null)
|
||||
b2.Dispose();
|
||||
|
||||
var b3 = await decoder.DecodeNextBlockAsync(CancellationToken.None);
|
||||
Assert.IsNull(b3, "Decoder should return null at end of stream");
|
||||
// Third block: MUST fail
|
||||
var ok = decoder.TryDecodeNextBlock(out var b3);
|
||||
|
||||
Assert.IsFalse(ok, "Decoder should return false at end of stream");
|
||||
|
||||
// IMPORTANT: do NOT touch b3.Buffer — it is null
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void Dispose_DisposesReader()
|
||||
{
|
||||
@ -131,8 +130,8 @@ public sealed class StemDecoder_Tests
|
||||
|
||||
try
|
||||
{
|
||||
// FakeAudioReader throws ObjectDisposedException when used after Dispose
|
||||
var _ = reader.ReadAsync(new float[10].AsMemory(), CancellationToken.None).Result;
|
||||
// This must throw
|
||||
reader.Read(new float[10], 0, 10);
|
||||
Assert.Fail("Expected ObjectDisposedException");
|
||||
}
|
||||
catch(AssertFailedException )
|
||||
@ -144,4 +143,6 @@ public sealed class StemDecoder_Tests
|
||||
Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using AudioCore.Impl;
|
||||
using AudioCore.Interfaces;
|
||||
using AudioCore.Interfaces;
|
||||
using AudioCore.Models;
|
||||
using NAudio.Wave;
|
||||
using AudioCore.Impl;
|
||||
|
||||
namespace AudioCore_Tests;
|
||||
|
||||
@ -39,16 +38,16 @@ public sealed class StemPlaybackEngine_Tests
|
||||
}
|
||||
}
|
||||
|
||||
public Task<AudioBlock?> DecodeNextBlockAsync(CancellationToken token)
|
||||
public bool TryDecodeNextBlock(out AudioBlock block)
|
||||
{
|
||||
AudioBlock? block;
|
||||
if (_blocks.Count == 0)
|
||||
{
|
||||
return Task.FromResult<AudioBlock?>(null);
|
||||
block = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
block = _blocks.Dequeue();
|
||||
return Task.FromResult<AudioBlock?>(block);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Seek(long samplePosition)
|
||||
@ -106,19 +105,18 @@ public sealed class StemPlaybackEngine_Tests
|
||||
{
|
||||
private MixedAudioBlock _lastInput;
|
||||
|
||||
public Task Configure(PlaybackSpeedSettings settings, CancellationToken token)
|
||||
public void Configure(PlaybackSpeedSettings settings)
|
||||
{
|
||||
// no-op for tests
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Submit(MixedAudioBlock input, CancellationToken token)
|
||||
public Task Submit(MixedAudioBlock input)
|
||||
{
|
||||
_lastInput = input;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<TimeStretchedAudioBlock> Receive(CancellationToken token)
|
||||
public Task<TimeStretchedAudioBlock> Receive()
|
||||
{
|
||||
if (_lastInput.Buffer == null)
|
||||
return Task.FromResult(default(TimeStretchedAudioBlock));
|
||||
@ -132,8 +130,6 @@ public sealed class StemPlaybackEngine_Tests
|
||||
_lastInput = default;
|
||||
return Task.FromResult(block);
|
||||
}
|
||||
|
||||
Task ITimeStretchEngine.IsReadyToAccept(CancellationToken token) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
private sealed class MockOutput : IAudioOutputDevice
|
||||
@ -145,8 +141,6 @@ public sealed class StemPlaybackEngine_Tests
|
||||
public int LastWriteSamples { get; private set; }
|
||||
public bool Started { get; private set; }
|
||||
|
||||
public Task IsReadyToAccept(CancellationToken token) => Task.CompletedTask;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Started = true;
|
||||
@ -156,8 +150,6 @@ public sealed class StemPlaybackEngine_Tests
|
||||
{
|
||||
Started = false;
|
||||
}
|
||||
public void Pause() => Started = false;
|
||||
public PlaybackState State => Started ? PlaybackState.Playing : PlaybackState.Stopped;
|
||||
|
||||
public void Write(ReadOnlySpan<float> samples)
|
||||
{
|
||||
@ -211,9 +203,9 @@ public sealed class StemPlaybackEngine_Tests
|
||||
};
|
||||
}
|
||||
|
||||
private class DummyProgressReporter : IProgressReporter<double>
|
||||
private class DummyProgressReporter : IProgressReporter<TimeSpan>
|
||||
{
|
||||
public Task ReportProgress(double value, CancellationToken ct)
|
||||
public Task ReportProgress(TimeSpan value, CancellationToken ct)
|
||||
=> Task.CompletedTask;
|
||||
}
|
||||
|
||||
@ -338,7 +330,7 @@ public sealed class StemPlaybackEngine_Tests
|
||||
await engine.LoadSessionAsync(session, new DummyProgressReporter());
|
||||
await engine.PlayAsync();
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||
await Task.Delay(50);
|
||||
|
||||
await engine.StopAsync();
|
||||
|
||||
|
||||
@ -48,16 +48,16 @@ public sealed class StemWaveformService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
public Task<AudioBlock?> DecodeNextBlockAsync(CancellationToken ct)
|
||||
public bool TryDecodeNextBlock(out AudioBlock block)
|
||||
{
|
||||
if (ct.IsCancellationRequested)
|
||||
return Task.FromCanceled<AudioBlock?>(ct);
|
||||
|
||||
if (_blocks.Count == 0)
|
||||
return Task.FromResult<AudioBlock?>(null);
|
||||
{
|
||||
block = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var block = _blocks.Dequeue();
|
||||
return Task.FromResult<AudioBlock?>(block);
|
||||
block = _blocks.Dequeue();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Seek(long samplePosition)
|
||||
@ -75,7 +75,6 @@ public sealed class StemWaveformService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string GetTestInputPath()
|
||||
{
|
||||
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
@ -30,12 +30,12 @@ public sealed class TimeStretchEngine_Tests
|
||||
[TestMethod]
|
||||
public async Task Process_Returns_Output_For_Speed_1()
|
||||
{
|
||||
await using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
|
||||
var input = MakeBlock(5000);
|
||||
|
||||
await engine.Submit(input, CancellationToken.None);
|
||||
var output = await engine.Receive(CancellationToken.None);
|
||||
await engine.Submit(input);
|
||||
var output = await engine.Receive();
|
||||
|
||||
Assert.IsGreaterThan(0, output.Frames);
|
||||
Assert.AreEqual(2, output.Channels);
|
||||
@ -55,204 +55,101 @@ public sealed class TimeStretchEngine_Tests
|
||||
[TestMethod]
|
||||
public async Task Process_Respects_Speed_Increase()
|
||||
{
|
||||
await using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
using var input = MakeBlock(44100);
|
||||
using var cts = new CancellationTokenSource();
|
||||
using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
var input = MakeBlock(1000);
|
||||
|
||||
for (var i = 0; i < 25; i++)
|
||||
await engine.Submit(input);
|
||||
|
||||
// -----------------------------
|
||||
// Phase 1: speed = 1.0
|
||||
// -----------------------------
|
||||
var normalFrames = 0;
|
||||
|
||||
const int NumberOfIterations = 5;
|
||||
|
||||
var submitTask1 = Task.Run(async () =>
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
for (var i = 0; i < NumberOfIterations; i++)
|
||||
await engine.Submit(input, ts.Token);
|
||||
});
|
||||
|
||||
var receiveTask1 = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(2));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
using var data = await engine.Receive(ts.Token);
|
||||
using var data = await engine.Receive();
|
||||
normalFrames += data.Frames;
|
||||
if (data.Buffer == null)
|
||||
break;
|
||||
|
||||
normalFrames += data.Frames;
|
||||
}
|
||||
});
|
||||
|
||||
await Task.WhenAll(submitTask1, receiveTask1);
|
||||
|
||||
Debug.WriteLine($"Normal frames: {normalFrames}");
|
||||
engine.Configure(new PlaybackSpeedSettings { Speed = 1.5f });
|
||||
|
||||
// -----------------------------
|
||||
// Phase 2: speed = 1.5
|
||||
// -----------------------------
|
||||
await engine.Configure(new PlaybackSpeedSettings { Speed = 1.5f }, cts.Token);
|
||||
|
||||
for (var i = 0; i < 25; i++)
|
||||
await engine.Submit(input);
|
||||
|
||||
var fasterFrames = 0;
|
||||
|
||||
var submitTask2 = Task.Run(async () =>
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
for (var i = 0; i < NumberOfIterations; i++)
|
||||
await engine.Submit(input, ts.Token);
|
||||
});
|
||||
|
||||
var receiveTask2 = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(2));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
using var data = await engine.Receive(ts.Token);
|
||||
using var data = await engine.Receive();
|
||||
fasterFrames += data.Frames;
|
||||
if (data.Buffer == null)
|
||||
break;
|
||||
|
||||
fasterFrames += data.Frames;
|
||||
}
|
||||
});
|
||||
|
||||
await Task.WhenAll(submitTask2, receiveTask2);
|
||||
|
||||
Debug.WriteLine($"Faster frames: {fasterFrames}");
|
||||
|
||||
// -----------------------------
|
||||
// Assertion
|
||||
// -----------------------------
|
||||
Assert.IsLessThan(fasterFrames, normalFrames);
|
||||
|
||||
cts.Cancel();
|
||||
}
|
||||
|
||||
Assert.IsLessThanOrEqualTo(normalFrames, fasterFrames);
|
||||
|
||||
input.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Process_Respects_Speed_Decrease()
|
||||
{
|
||||
await using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
using var input = MakeBlock(44100);
|
||||
using var cts = new CancellationTokenSource();
|
||||
using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
var input = MakeBlock(1000);
|
||||
|
||||
for (var i = 0; i < 25; i++)
|
||||
await engine.Submit(input);
|
||||
|
||||
// -----------------------------
|
||||
// Phase 1: speed = 1.0
|
||||
// -----------------------------
|
||||
var normalFrames = 0;
|
||||
|
||||
const int NumberOfIterations = 5;
|
||||
|
||||
var submitTask1 = Task.Run(async () =>
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
for (var i = 0; i < NumberOfIterations; i++)
|
||||
await engine.Submit(input, ts.Token);
|
||||
});
|
||||
|
||||
var receiveTask1 = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(2));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
using var data = await engine.Receive(ts.Token);
|
||||
using var data = await engine.Receive();
|
||||
normalFrames += data.Frames;
|
||||
if (data.Buffer == null)
|
||||
break;
|
||||
|
||||
normalFrames += data.Frames;
|
||||
}
|
||||
});
|
||||
|
||||
await Task.WhenAll(submitTask1, receiveTask1);
|
||||
engine.Configure(new PlaybackSpeedSettings { Speed = 0.5f });
|
||||
|
||||
Debug.WriteLine($"Normal frames: {normalFrames}");
|
||||
|
||||
// -----------------------------
|
||||
// Phase 2: speed = 0.5
|
||||
// -----------------------------
|
||||
await engine.Configure(new PlaybackSpeedSettings { Speed = 0.5f }, cts.Token);
|
||||
for (var i = 0; i < 25; i++)
|
||||
await engine.Submit(input);
|
||||
|
||||
var slowerFrames = 0;
|
||||
|
||||
var submitTask2 = Task.Run(async () =>
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
for (var i = 0; i < NumberOfIterations; i++)
|
||||
await engine.Submit(input, ts.Token);
|
||||
});
|
||||
|
||||
var receiveTask2 = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(2));
|
||||
using var ts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, timeout.Token);
|
||||
|
||||
using var data = await engine.Receive(ts.Token);
|
||||
using var data = await engine.Receive();
|
||||
slowerFrames += data.Frames;
|
||||
if (data.Buffer == null)
|
||||
break;
|
||||
|
||||
slowerFrames += data.Frames;
|
||||
}
|
||||
});
|
||||
|
||||
await Task.WhenAll(submitTask2, receiveTask2);
|
||||
Assert.IsGreaterThanOrEqualTo(normalFrames, slowerFrames);
|
||||
|
||||
Debug.WriteLine($"Slower frames: {slowerFrames}");
|
||||
|
||||
// -----------------------------
|
||||
// Assertion
|
||||
// -----------------------------
|
||||
Assert.IsLessThan(slowerFrames, normalFrames);
|
||||
|
||||
cts.Cancel();
|
||||
input.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Engine_Restarts_On_Speed_Change()
|
||||
{
|
||||
await using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
using var cts = new CancellationTokenSource();
|
||||
using var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
|
||||
await engine.Configure(new PlaybackSpeedSettings { Speed = 1f }, cts.Token);
|
||||
var input = MakeBlock(100);
|
||||
|
||||
var input = MakeBlock(44100);
|
||||
await engine.Submit(input);
|
||||
var before = await engine.Receive();
|
||||
|
||||
await engine.Submit(input, cts.Token);
|
||||
var before = await engine.Receive(cts.Token);
|
||||
engine.Configure(new PlaybackSpeedSettings { Speed = 0.75f });
|
||||
|
||||
await engine.Configure(new PlaybackSpeedSettings { Speed = 0.75f }, cts.Token);
|
||||
await engine.Submit(input);
|
||||
var after = await engine.Receive();
|
||||
|
||||
await engine.Submit(input, cts.Token);
|
||||
var after = await engine.Receive(cts.Token);
|
||||
|
||||
Assert.AreNotEqual(0, before.Frames);
|
||||
Assert.AreNotEqual(0, after.Frames);
|
||||
Assert.AreNotEqual(before.Frames, after.Frames);
|
||||
|
||||
cts.Cancel();
|
||||
Assert.AreEqual(0, after.Frames);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Dispose_Kills_FFmpeg()
|
||||
public void Dispose_Kills_FFmpeg()
|
||||
{
|
||||
var engine = new RubberBandTimeStretchEngine(_pool, 44100, 2);
|
||||
using var cts = new CancellationTokenSource();
|
||||
|
||||
var ffField = typeof(RubberBandTimeStretchEngine)
|
||||
.GetField("_ff", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
@ -260,7 +157,7 @@ public sealed class TimeStretchEngine_Tests
|
||||
var ff = (Process?)ffField!.GetValue(engine);
|
||||
var pid = ff?.Id ?? -1;
|
||||
|
||||
await engine.DisposeAsync();
|
||||
engine.Dispose();
|
||||
|
||||
var exists = Process.GetProcesses().Any(p =>
|
||||
{
|
||||
@ -269,6 +166,5 @@ public sealed class TimeStretchEngine_Tests
|
||||
});
|
||||
|
||||
Assert.IsFalse(exists);
|
||||
cts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@ public sealed class WasapiOutputDevice_Tests
|
||||
public void Write_Adds_Bytes_To_Buffer()
|
||||
{
|
||||
var fake = new FakeWasapiOut();
|
||||
fake.Play();
|
||||
var dev = new WasapiOutputDevice(new ByteBufferPool(), fake);
|
||||
|
||||
float[] samples = { 1f, -1f, 0.5f, -0.5f };
|
||||
|
||||
@ -3,19 +3,19 @@
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Avalonia" Version="12.1.0" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="12.1.0" />
|
||||
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.0" />
|
||||
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.0" />
|
||||
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3" />
|
||||
<PackageVersion Include="Avalonia" Version="12.0.3" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="12.0.3" />
|
||||
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.0.3" />
|
||||
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.0.3" />
|
||||
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.1"/>
|
||||
<PackageVersion Include="BunLabs.NAudio.Flac" Version="2.0.1" />
|
||||
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.2" />
|
||||
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
|
||||
<PackageVersion Include="Microsoft.ML.OnnxRuntime" Version="1.27.0" />
|
||||
<PackageVersion Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
|
||||
<PackageVersion Include="NAudio" Version="2.3.0" />
|
||||
<PackageVersion Include="NAudio.Flac" Version="1.0.5702.29018" />
|
||||
<PackageVersion Include="System.Text.Json" Version="10.0.5" />
|
||||
<PackageVersion Include="MSTest" Version="4.3.0" />
|
||||
<PackageVersion Include="MSTest" Version="4.0.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
x
Reference in New Issue
Block a user