From 1a3a9bd5c54bfd52cd9a690296c243ccd044f940 Mon Sep 17 00:00:00 2001 From: player-03 Date: Thu, 19 Oct 2023 22:57:43 -0400 Subject: [PATCH] Avoid integer overflow for long sounds. Multiplying `dataLength * 8` produces a high number, which in the case of very long audio files can exceed the integer limit. Multiplying by 8.0 coerces to float, allowing much higher values. An alternate solution is to divide first and multiply by 8 second, thus keeping the number from getting too large at any point. However, the purpose of the 8 is to convert `dataLength` from bytes to bits, so it's clearer if those two are close together. --- src/lime/_internal/backend/native/NativeAudioSource.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lime/_internal/backend/native/NativeAudioSource.hx b/src/lime/_internal/backend/native/NativeAudioSource.hx index 37c04fb79..ab85e0e00 100644 --- a/src/lime/_internal/backend/native/NativeAudioSource.hx +++ b/src/lime/_internal/backend/native/NativeAudioSource.hx @@ -136,7 +136,7 @@ class NativeAudioSource } } - samples = Std.int((dataLength * 8) / (parent.buffer.channels * parent.buffer.bitsPerSample)); + samples = Std.int((dataLength * 8.0) / (parent.buffer.channels * parent.buffer.bitsPerSample)); } public function play():Void