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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user