Skip to content

Commit

Permalink
fix(station): Migrated OpenTK.OpenAL to OpenTK.Audio.OpenAL
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarDev committed Dec 19, 2023
1 parent ff8edc2 commit 81b18a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion station/Signal.Beacon.Voice/Signal.Beacon.Voice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="Google.Apis" Version="1.64.0" />
<PackageReference Include="Google.Cloud.Speech.V1" Version="3.5.0" />
<PackageReference Include="OpenTK.OpenAL" Version="5.0.0-pre.8" />
<PackageReference Include="OpenTK.Audio.OpenAL" Version="5.0.0-pre.9" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Porcupine" Version="3.0.1" />
Expand Down
16 changes: 10 additions & 6 deletions station/Signal.Beacon.Voice/VoiceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ private bool GetNextFrameByte(int frameLength, ref byte[] buffer)
throw new NullReferenceException("Capture device not initialized.");
if (frameLength <= 0) throw new ArgumentOutOfRangeException(nameof(frameLength));

if (ALC.GetAvailableSamples(this.captureDevice.Value) < frameLength)
var samples = ALC.GetInteger(this.captureDevice.Value, AlcGetInteger.CaptureSamples);
if (samples < frameLength)
return false;

if (buffer == null) throw new ArgumentNullException(nameof(buffer));
Expand All @@ -494,7 +495,8 @@ private bool GetNextFrame(int frameLength, ref short[] buffer)
throw new NullReferenceException("Capture device not initialized.");
if (frameLength <= 0) throw new ArgumentOutOfRangeException(nameof(frameLength));

if (ALC.GetAvailableSamples(this.captureDevice.Value) < frameLength)
var samples = ALC.GetInteger(this.captureDevice.Value, AlcGetInteger.CaptureSamples);
if (samples < frameLength)
return false;

if (buffer == null) throw new ArgumentNullException(nameof(buffer));
Expand Down Expand Up @@ -765,7 +767,7 @@ private async Task PlaySoundAsync(string name)
ALC.MakeContextCurrent(this.alContext.Value);
this.AlHasError();

AL.BindBufferToSource(this.alSource.Value, sound.Buffer);
AL.Source(this.alSource.Value, ALSourcei.Buffer, sound.Buffer);
this.AlHasError();

AL.SourcePlay(this.alSource.Value);
Expand All @@ -787,15 +789,17 @@ private Task WaitSourceToStop()
return Task.CompletedTask;
}

return Task.Run(() =>
return Task.Run<Task>(async () =>
{
ALSourceState state;
do
{
state = AL.GetSourceState(this.alSource.Value);
AL.GetSource(this.alSource.Value, ALGetSourcei.SourceState, out var rawState);
if (this.AlHasError()) break;

Thread.Yield();
state = (ALSourceState) rawState;

await Task.Delay(10);
} while (state == ALSourceState.Playing);
});
}
Expand Down

0 comments on commit 81b18a9

Please sign in to comment.