Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 174 forks source link

HL/C: sound length is not set correctly when loading wav files #1363

Closed MoritzBrueckner closed 2 years ago

MoritzBrueckner commented 2 years ago

Describe the bug When loading a .wav audio file (Khamake quality set to 1.0), the Sound object's length will not be set correctly on HL on Windows. The reason for this is the known hl.Ref issue we've had before with the sample rate (https://github.com/Kode/Kha/pull/1361), but that alone is unfortunately not enough here because something is wrong with the resulting float value.

The sound in my case has a length of ~62.95s and the wav reader seems to parse the file correctly as you see in the following screenshot:

2021-09-16 19_03_52-Window _Screenshot from VS 2019 that shows sound->length is correct in hl_kore_sound_init_wav()._

However it is somehow passed to Haxe as 5.51085676554428e-315, at least that's the result when printing the value in Haxe. So there must be a conversion error somewhere, but I currently have no idea where... My current hypothesis is that the value is converted from float to double and that's where the issue comes from.

This is the changed code in korehl/Sound.hx in initWav():

final sampleRateRef: hl.Ref<Int> = sampleRate;
final lengthRef: hl.Ref<Float> = length;
var data = kore_sound_init_wav(StringHelper.convert(filename), dataSize.getData(), sampleRateRef, lengthRef);
sampleRate = sampleRateRef.get();
length = lengthRef.get();

Execution Environment: