Skip to main content

Notice

Please be aware that much of the software linked to or mentioned on this forum is niche and therefore infrequently downloaded. Lots of anti-virus scanners and so-called malware detectors like to flag infrequently downloaded software as bad until it is either downloaded enough times, or its developer actually bothers with getting each individual release allow listed by every single AV vendor. You can do many people a great favor when encountering such a "problem" example by submitting them to your AV vendor for examination. For almost everything on this forum, it is a false positive.
Topic: Advice On Making HH:MM:SS:FF UI Column (Read 341 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Advice On Making HH:MM:SS:FF UI Column

Hi all,

I have a situation where I would like to display the time format in hours:minutes:seconds:frames based on the 75fps Redbook timecode. I didn't see anything in Foobar2000 that would allow me to do that so last night I started tossing some things together for a custom UI column. I'm stuck on an issue (though I just woke up and haven't tackled it); but in addition to that I'm sure there are ways I'm doing this about as inefficiently as possible. I'm not much of a programer.

In my example the files I'm dealing with are DSD64 (2822400hz sample rate) files. I have plans for modifying the script to be sample-rate independent at a later time...but I figured I'd start with one goal before modifying. Here is the code I have now:

Code: [Select]
$left(%length_ex%,$sub($len(%length_ex%),4)):$num($div($sub(%length_samples%,$mul(%length_seconds_fp%,2822400)),37632),2)

So I start by figuring out the length of the %length_ex% string and display everything except the last 4 places; being the decimal point and everything after. This is because I do not need seconds rounded up and I want the time to be able to handle more than 9 minutes 59 seconds.

Then comes all the math I had to figure out last night. If I did this right...it should be the equivalent of this equation:

Code: [Select]
(samples-(length*2822400))
----------------------------
         37632

I take the floating-point version of the seconds and multiply it by the DSD sample rate; since Foobar's math is all integer it drops the decimal places exactly as I want. So that gives me the number of samples based on the minutes and seconds; then subtract that from the reported length to give me the number of samples left over.

Divide that by 37632 to get the number of frames. (I calculated 37632 samples per DSD frame.)

With the above code...This mostly works. I have a file that has a reported length of 5:46.720; and the code above spits out 5:46:54. Great right? In this case, yes. When I do all the math by hand, the final calculation is 2032128/37632 and it comes out to 54. But...this can be a problem. How about a file with a length of 4:00.170 (677 855 808 samples)?

240 * 2822400 = 677,376,000
677,855,808 - 677,376,000 = 479,808
479,808 / 32632 = 12.75

There's my problem. You can't have a fraction of a frame...so this needs to be rounded up.

Now...how the hell do I do this in Foobar2k? I know exactly how to figure out if I have a partial frame to deal with:

479808 mod 37632 = 28224

What I'm stuck with is to actually how to make this work as an if/then/else statement. Here's something I came up with last night that didn't work:

Code: [Select]
$puts(rem,$sub(%length_samples%,$mul(%length_seconds_fp%,2822400)))$left(%length_ex%,$sub($len(%length_ex%),4)):$num($if($mod($get(rem),37632),$add($div($sub(%length_samples%,$get(rem),37632),1),$div($sub(%length_samples%$get(rem),37632),2)

My idea was to first calculate the remaining samples and write them to a variable; then run modulus on there and if any reminder occurs...then just add 1 to the final result.

I'm pretty sure I'm doing if statements wrong. I'm pretty sure I'm doing everything wrong. Any advice would be appreciated.

SMSL SU-8 -> Little Bear P5 -> Sansui SE-8 - Denon PMA-770 -> Ohm Model L | High-Res Lover | DSD Enthusiast | Mad SACD-Scientist

Re: Advice On Making HH:MM:SS:FF UI Column

Reply #1
Now that I sat down and looked at it again...I see exactly what I needed to do.

Code: [Select]
$puts(rem,$sub(%length_samples%,$mul(%length_seconds_fp%,2822400)))$left(%length_ex%,$sub($len(%length_ex%),4)):$ifgreater($mod($get(rem),37632),0,$num($add($div($get(rem),37632),1),2),$num($div($get(rem),37632),2))

Okay, now to make it sample rage agnostic.

Code: [Select]
$puts(frm,$div(%samplerate%,75))$puts(rem,$sub(%length_samples%,$mul(%length_seconds_fp%,%samplerate%)))$left(%length_ex%,$sub($len(%length_ex%),4)):$ifgreater($mod($get(rem),$get(frm)),0,$num($add($div($get(rem),$get(frm)),1),2),$num($div($get(rem),$get(frm)),2))

SMSL SU-8 -> Little Bear P5 -> Sansui SE-8 - Denon PMA-770 -> Ohm Model L | High-Res Lover | DSD Enthusiast | Mad SACD-Scientist

Re: Advice On Making HH:MM:SS:FF UI Column

Reply #2
My assumption that I should round-up when I have samples that don't fit in a full frame does not agree with what my audio workstations have been telling me. So rip out the ifgreater check and drop the variables since we don't calculate that stuff more than once now.

Code: [Select]
$left(%length_ex%,$sub($len(%length_ex%),4)):$num($div($sub(%length_samples%,$mul(%length_seconds_fp%,%samplerate%)),$div(%samplerate%,75)),2))
SMSL SU-8 -> Little Bear P5 -> Sansui SE-8 - Denon PMA-770 -> Ohm Model L | High-Res Lover | DSD Enthusiast | Mad SACD-Scientist

 
SimplePortal 1.0.0 RC1 © 2008-2021