Skip to content

Commit

Permalink
Fixed Resampler
Browse files Browse the repository at this point in the history
  • Loading branch information
MineCake147E committed Mar 15, 2020
1 parent dd2bef6 commit a9f33ec
Show file tree
Hide file tree
Showing 56 changed files with 14,473 additions and 1,496 deletions.
24 changes: 14 additions & 10 deletions MonoAudio.Android/AudioTrackOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Initialize(IWaveSource source)
{
AudioAttributes attributes;
AudioFormat format;
int latencyInFrames = (int)(source.Format.SampleRate * Latency.TotalSeconds);
int latencyInFrames = (int)(source.Format.SampleRate * Latency.TotalSeconds / 2.0);
bufferSizeInBytes = latencyInFrames * source.Format.GetFrameSize();
buffer = new byte[bufferSizeInBytes];
using (var attributesBuilder = new AudioAttributes.Builder())
Expand All @@ -108,7 +108,7 @@ public void Initialize(IWaveSource source)
_ = trackBuilder
.SetAudioAttributes(attributes)
.SetAudioFormat(format)
.SetBufferSizeInBytes(bufferSizeInBytes);
.SetBufferSizeInBytes(bufferSizeInBytes * 2);
track = trackBuilder.Build();
}
Source = source;
Expand Down Expand Up @@ -173,15 +173,19 @@ private void Process(CancellationToken token)
track.Play();
}
var span = buffer.AsSpan();
span = span.Slice(0, Source.Read(span));
try
ReadResult rr = Source.Read(span);
if (rr.HasData)
{
track.Write(buffer, 0, span.Length, WriteMode.Blocking);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
span = span.Slice(0, rr.Length);
try
{
track.Write(buffer, 0, span.Length, WriteMode.Blocking);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
}
}
token.ThrowIfCancellationRequested();
fillFlag.Wait();
Expand Down
79 changes: 79 additions & 0 deletions MonoAudio.Android/MonoAudio.Android.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions MonoAudio.Android/MonoAudio.IO.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -61,7 +61,10 @@
<None Include="Resources\AboutResources.txt" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
<PackageReference Include="System.Numerics.Vectors">
<Version>4.5.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\strings.xml" />
Expand Down
Loading

0 comments on commit a9f33ec

Please sign in to comment.