Skip to content

Commit

Permalink
Avoid integer overflow for long sounds.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
player-03 authored Oct 20, 2023
1 parent 51273fb commit 1a3a9bd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lime/_internal/backend/native/NativeAudioSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a3a9bd

Please sign in to comment.