From ab8a7846ddbfbfa5b61d8512020cd42136115e65 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 20 Jan 2021 11:13:55 -0800 Subject: [PATCH] allow static sound to be trimmed --- src/Audio/StaticSound.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Audio/StaticSound.cs b/src/Audio/StaticSound.cs index 1807e77..b716c62 100644 --- a/src/Audio/StaticSound.cs +++ b/src/Audio/StaticSound.cs @@ -39,6 +39,7 @@ namespace MoonWorks.Audio device, buffer, 0, + (uint) buffer.Length, (ushort) info.channels, info.sample_rate ); @@ -47,7 +48,8 @@ namespace MoonWorks.Audio public StaticSound( AudioDevice device, float[] buffer, - uint bufferOffset, + uint bufferOffset, /* in floats */ + uint bufferLength, /* in floats */ ushort channels, uint samplesPerSecond ) : base(device) { @@ -63,14 +65,13 @@ namespace MoonWorks.Audio nAvgBytesPerSec = blockAlign * samplesPerSecond }; - var bufferLengthInBytes = sizeof(float) * buffer.Length; - + var bufferLengthInBytes = (int) (bufferLength * sizeof(float)); Handle = new FAudio.FAudioBuffer(); Handle.Flags = FAudio.FAUDIO_END_OF_STREAM; Handle.pContext = IntPtr.Zero; Handle.AudioBytes = (uint) bufferLengthInBytes; Handle.pAudioData = Marshal.AllocHGlobal(bufferLengthInBytes); - Marshal.Copy(buffer, (int) bufferOffset, Handle.pAudioData, buffer.Length); + Marshal.Copy(buffer, (int) bufferOffset, Handle.pAudioData, (int) bufferLength); Handle.PlayBegin = 0; Handle.PlayLength = 0;