Prevent integer overflow (fixes segfault in the soundengine)

Yeah yeah, not that nice looking casts but works