allow static sound to be trimmed

main
cosmonaut 2021-01-20 11:13:55 -08:00
parent 481c17945a
commit ab8a7846dd
1 changed files with 5 additions and 4 deletions

View File

@ -39,6 +39,7 @@ namespace MoonWorks.Audio
device, device,
buffer, buffer,
0, 0,
(uint) buffer.Length,
(ushort) info.channels, (ushort) info.channels,
info.sample_rate info.sample_rate
); );
@ -47,7 +48,8 @@ namespace MoonWorks.Audio
public StaticSound( public StaticSound(
AudioDevice device, AudioDevice device,
float[] buffer, float[] buffer,
uint bufferOffset, uint bufferOffset, /* in floats */
uint bufferLength, /* in floats */
ushort channels, ushort channels,
uint samplesPerSecond uint samplesPerSecond
) : base(device) { ) : base(device) {
@ -63,14 +65,13 @@ namespace MoonWorks.Audio
nAvgBytesPerSec = blockAlign * samplesPerSecond nAvgBytesPerSec = blockAlign * samplesPerSecond
}; };
var bufferLengthInBytes = sizeof(float) * buffer.Length; var bufferLengthInBytes = (int) (bufferLength * sizeof(float));
Handle = new FAudio.FAudioBuffer(); Handle = new FAudio.FAudioBuffer();
Handle.Flags = FAudio.FAUDIO_END_OF_STREAM; Handle.Flags = FAudio.FAUDIO_END_OF_STREAM;
Handle.pContext = IntPtr.Zero; Handle.pContext = IntPtr.Zero;
Handle.AudioBytes = (uint) bufferLengthInBytes; Handle.AudioBytes = (uint) bufferLengthInBytes;
Handle.pAudioData = Marshal.AllocHGlobal(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.PlayBegin = 0;
Handle.PlayLength = 0; Handle.PlayLength = 0;