-
-
Notifications
You must be signed in to change notification settings - Fork 289
fix sound length rounding to seconds #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
in chart editor songs would end early because guess what.... the sound length was rounded for whatever reason meaning like a 0.9 second song wouldnt even be chartable lmfao but hopefully its fixed now ..... feel free to test with long ass songs cus that was the whole purpose of changing the sound length stuff in the first place .... i dont have any long ass songs to test .....
Make sure this works on haxe 4.2.5 and haxe 4.3.6 |
source/openfl/media/Sound.hx
Outdated
// return Std.int(samples / __buffer.sampleRate * 1000); | ||
var samples = (Int64.make(0, __buffer.data.length) * Int64.ofInt(8)) / Int64.ofInt(__buffer.channels * __buffer.bitsPerSample); | ||
var value = samples / Int64.ofInt(__buffer.sampleRate) * Int64.ofInt(1000); | ||
var div = Int64.divMod(samples * 1000, Int64.ofInt(__buffer.sampleRate)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not samples * Int64.ofInt(1000)
Wouldnt there be a risk of overflow otherwise
or 4.3.7 because that came out not long ago |
var samples = (Int64.make(0, __buffer.data.length) * Int64.ofInt(8)) / Int64.ofInt(__buffer.channels * __buffer.bitsPerSample); | ||
var value = samples / Int64.ofInt(__buffer.sampleRate) * Int64.ofInt(1000); | ||
var div = Int64.divMod(samples * 1000, Int64.ofInt(__buffer.sampleRate)); | ||
var value = (div.quotient + (div.modulus / __buffer.sampleRate)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure that the value returned from this matches correctly, between normal openfl and your pr.
And show the results,
Because i am feeling a bit suspicious of the (div.modulus / sampleRate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've actually tested this and it does match correctly, i was doing a trace like
trace('og openfl: $ogval');
trace('my calc: $myval');
tested on a 20.974s audio file, i managed to get both results to show the same number (20974)
reason it was rounding to 20000 was because (i64 / int)
only returns the quotient of the division:
/**
Returns the quotient of `a` divided by `b`.
**/
@:op(A / B) public static inline function div(a:Int64, b:Int64):Int64
return divMod(a, b).quotient;
haxe.Int64, line 320
which of course would be 20, the modulus corresponds to the decimal of the wanted number (.974)
and since were multiplying the "whole parts" of the division by 1000...... well..... thats what was causing the bug lol
so i had to implement the modulus myself because an average division on Int64 only uses like the "floored" value of the wanted result ;-;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet I'll send this in for internal review!
you are not part of the team lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will respectfully need you to shut it
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in chart editor songs would end early because guess what.... the sound length was rounded for whatever reason meaning like a 0.9 second song wouldnt even be chartable lmfao
but hopefully its fixed now ..... feel free to test with long ass songs cus that was the whole purpose of changing the sound length stuff in the first place .... i dont have any long ass songs to test .....