426 changes: 426 additions & 0 deletions LoudPizza.Wav/Reader/WavReader.cs

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions LoudPizza.Wav/WavAudioStream.cs
@@ -0,0 +1,39 @@
using LoudPizza.Sources;
using LoudPizza.Wav.Reader;

namespace LoudPizza.Wav;

public class WavAudioStream : IAudioStream {
private readonly WavReader _wavReader;

public WavAudioStream(Stream stream, bool keepOpen) {
this._wavReader = new WavReader(stream, keepOpen);
}

public uint Channels => (uint)this._wavReader.Channels;
public float SampleRate => this._wavReader.SampleRate;
public float RelativePlaybackSpeed => 1.0f;

public uint GetAudio(Span<float> buffer, uint samplesToRead, uint channelStride) {
return this._wavReader.ReadSamples(buffer, samplesToRead, channelStride);
}

public bool HasEnded() {
return this._wavReader.EndOfFile;
}

public bool CanSeek() {
return true;
}

public SoLoudStatus Seek(ulong samplePosition, Span<float> scratch, AudioSeekFlags flags, out ulong resultPosition) {
this._wavReader.SamplePosition = (int)samplePosition;
resultPosition = (ulong)this._wavReader.SamplePosition;

return SoLoudStatus.Ok;
}

public void Dispose() {
this._wavReader.Dispose();
}
}
6 changes: 6 additions & 0 deletions LoudPizza.sln
Expand Up @@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencie
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLayer", "NLayer\NLayer\NLayer.csproj", "{8ADA7751-FE21-424A-A774-AB99D1288869}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoudPizza.Wav", "LoudPizza.Wav\LoudPizza.Wav.csproj", "{AAF74227-D445-4FAD-BA74-F76180D1456D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -61,6 +63,10 @@ Global
{8ADA7751-FE21-424A-A774-AB99D1288869}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8ADA7751-FE21-424A-A774-AB99D1288869}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8ADA7751-FE21-424A-A774-AB99D1288869}.Release|Any CPU.Build.0 = Release|Any CPU
{AAF74227-D445-4FAD-BA74-F76180D1456D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAF74227-D445-4FAD-BA74-F76180D1456D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAF74227-D445-4FAD-BA74-F76180D1456D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAF74227-D445-4FAD-BA74-F76180D1456D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down