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.
This commit is contained in:
player-03
2023-10-19 22:57:43 -04:00
committed by GitHub
parent 51273fb258
commit 1a3a9bd5c5

View File

@@ -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