Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Friendly formatting of frequency (Read 4934 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

Friendly formatting of frequency

Got annoyed by the simple display of sampling frequency in Hz, especially with DSD it's hard to read and messes up the layouts.
I thought there was a nice helper function but I couldn't find one and neither a one-liner shared somewhere so that's what I came up with.

Hope you find it helpful, if you snatch a bug or have suggestions for improvements let me know.

Default UI status bar:
Code: [Select]
%codec% | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps mp3 |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) %channels% | %playback_time%[ / %length%]

Default UI status bar:
Code: [Select]
%codec% | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps mp3 |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) %channels% | %playback_time%[ / %length%]

Columns UI, Playlist View, Columns, Codec (Custom)
Code: [Select]
[%codec% $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,)$ifgreater(%__bitspersample%,0, %__bitspersample% bit,)$if($strcmp(%__encoding%,lossy), %bitrate% kbps) %channels% ]

Columns UI, Status Pane
Code: [Select]
%artist% – %title%
$crlf()
%codec% | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps mp3 |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) %channels% | %playback_time%[ / %length%]


Re: Friendly formatting of frequency

Reply #1
I'd press a thumbs up or "Thank you" button if one existed. Thank you!

Re: Friendly formatting of frequency

Reply #2
@Squeller You're welcome!

Made some changes:
- There was a leftover "mp3" from somewhere in the bitrate
- Changed "stereo" to "Stereo" in status pane and status bar and to "2ch" in the playlist

Default UI status bar:
Code: [Select]
%codec% | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) $if($stricmp(%channels%,stereo),Stereo,%channels%) | %playback_time%[ / %length%]

Columns UI, Playlist View, Columns, Codec (Custom)
Code: [Select]
[%codec% $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,)$ifgreater(%__bitspersample%,0, %__bitspersample% bit,)$if($strcmp(%__encoding%,lossy), %bitrate% kbps) $if($stricmp(%channels%,stereo),2ch,%channels%) ]

Columns UI, Status Pane
Code: [Select]
%artist% – %title%
$crlf()
%codec% | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) $if($stricmp(%channels%,stereo),Stereo,%channels%) | %playback_time%[ / %length%]

Re: Friendly formatting of frequency

Reply #3
This is kind of a different question, but it fits with the topic. Is there an easy way to add commas to a sample rate value, turning 44100 into 44,100, 176400 into 176,400, 5564800 into 5,564,800, etc? It would make it easier to visually parse a value in the status bar, for instance. I need it to work for both %samplerate% and %output_samplerate% (Case's output info component).
Think millionaire, but with cannons.

Re: Friendly formatting of frequency

Reply #4
This is kind of a different question, but it fits with the topic. Is there an easy way to add commas to a sample rate value, turning 44100 into 44,100, 176400 into 176,400,
$div(number,1000) and $num($mod(number,1000),3) ?

5564800 into 5,564,800, etc?
That is a bit worse than another such routine on the $div(number,1000), because you don't want "0,044,100". An $ifgreater first. Or just stick to the final separator and let 2822 be 2822?

Re: Friendly formatting of frequency

Reply #5
@Porcus I may be a bit dumb. How do I use those to put commas into the number? I checked titleformat info on those and I don't understand how they work.
Think millionaire, but with cannons.

Re: Friendly formatting of frequency

Reply #6
I cannot really test that %output_samplerate% thing at the moment, but I suspect it will return 0 if you aren't playing? Anyway, without that, it would be the following that works for sample rates less than a million:

$div(%__samplerate%,1000)','$num($mod(%__samplerate%,1000),3)

This will output e.g. 2822,200 (with no comma before the "8"). If you want a separator for the millions too, then I think you must do something like the following:
$ifgreater(%__samplerate%,999999,$div(%__samplerate%,1000000)','$num($div($mod(%__samplerate%,1000000),1000),3),$div(%__samplerate%,1000))','$num($mod(%__samplerate%,1000),3)

assuming that you have nothing that is sampled at merely three-figure rates ;)

Re: Friendly formatting of frequency

Reply #7
I cannot really test that %output_samplerate% thing at the moment, but I suspect it will return 0 if you aren't playing? Anyway, without that, it would be the following that works for sample rates less than a million:

$div(%__samplerate%,1000)','$num($mod(%__samplerate%,1000),3)

This will output e.g. 2822,200 (with no comma before the "8"). If you want a separator for the millions too, then I think you must do something like the following:
$ifgreater(%__samplerate%,999999,$div(%__samplerate%,1000000)','$num($div($mod(%__samplerate%,1000000),1000),3),$div(%__samplerate%,1000))','$num($mod(%__samplerate%,1000),3)

assuming that you have nothing that is sampled at merely three-figure rates ;)
Output samplerate is empty when not playing or outinfo not installed.

$puts(txt,$if([%output_samplerate%],Output $div(%output_samplerate%,1000)/%output_bitdepth%/%output_channels%,- Not Playing -))
$if($get(txt),$if($get(n),$crlf())$get(txt)$puts(n,CR))

Re: Friendly formatting of frequency

Reply #8
This is kind of a different question, but it fits with the topic. Is there an easy way to add commas to a sample rate value, turning 44100 into 44,100, 176400 into 176,400, 5564800 into 5,564,800, etc? It would make it easier to visually parse a value in the status bar, for instance. I need it to work for both %samplerate% and %output_samplerate% (Case's output info component).

Would this work?

Code: [Select]

$ifgreater($len(%__samplerate%),6,$substr(%__samplerate%,1,$sub($len(%__samplerate%),6))',',)$ifgreater($len(%__samplerate%),4,$substr(%__samplerate%,$sub($len(%__samplerate%),5),$sub($len(%__samplerate%),3))',',)$substr(%__samplerate%,$sub($len(%__samplerate%),2),$len(%__samplerate%))


Re: Friendly formatting of frequency

Reply #9
I came at it from a different angle (text rather than maths) -

Code: [Select]
$right($insert($insert($num(%samplerate%,9),',',6),',',3),$add($len(%samplerate%),$iflonger(%samplerate%,6,2,1)))

$num samplerate to 9 digits, $insert two commas, $right cut the extra digits.

(I love there are always different ways to do things with title formatting)

Re: Friendly formatting of frequency

Reply #10
Thank you, everyone! I'll test the options.
Think millionaire, but with cannons.


Re: Friendly formatting of frequency

Reply #12
Added Codec conversion for WavPack DSD shown as "WavPack" to "DSD64" "DSD128" etc

It was not fair not to add 48 kHz support.

Default UI status bar:

Code: [Select]
$if($stricmp(%codec%,WavPack),$ifgreater(2,%__bitspersample%,DSD$div(%__samplerate%,$ifgreater(0,$mod(%__samplerate%,44100),48000,44100)),%codec%),%codec%) | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) $if($stricmp(%channels%,stereo),Stereo,%channels%) | %playback_time%[ / %length%]

Columns UI, Playlist View, Columns, Codec (Custom)

Code: [Select]
[$if($stricmp(%codec%,WavPack),$ifgreater(2,%__bitspersample%,DSD$div(%__samplerate%,$ifgreater(0,$mod(%__samplerate%,44100),48000,44100)),%codec%),%codec%) $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,)$ifgreater(%__bitspersample%,0, %__bitspersample% bit,)$if($strcmp(%__encoding%,lossy), %bitrate% kbps) $if($stricmp(%channels%,stereo),2ch,%channels%) ]

Columns UI, Status Pane

Code: [Select]
%artist% – %title%
$crlf()
$if($stricmp(%codec%,WavPack),$ifgreater(2,%__bitspersample%,DSD$div(%__samplerate%,$ifgreater(0,$mod(%__samplerate%,44100),48000,44100)),%codec%),%codec%) | $ifgreater(%__samplerate%,999999,[$div(%__samplerate%,1000000).[$substr($mod(%__samplerate%,1000000),0,1)]] MHz,$ifgreater(%__samplerate%,999,[$div(%__samplerate%,1000).[$substr($mod(%__samplerate%,1000),0,1)]] KHz,))$ifgreater(1000,%__samplerate%,%__samplerate Hz,) | $if($strcmp(%__encoding%,lossy),%bitrate% kbps |,$ifgreater(%__bitspersample%,0,%__bitspersample% bit |,)) $if($stricmp(%channels%,stereo),Stereo,%channels%) | %playback_time%[ / %length%]

 

Re: Friendly formatting of frequency

Reply #13
In the case of WavPack DSD, it's better to know it as "WavPack".
e.g
WavPack high lossless 2912 kbps DSD 1 bit/2822400 Hz
SHURE SRH1840, SENNHEISER HD660S2, SENNHEISER HD620S, SENNHEISER HD 490 Pro Plus, beyerdynamic DT 1990 PRO, HiFiMAN Edition XS, HIFIMAN ANANDA, Bowers & Wilkins P7, FiiO FT5, FiiO FT1 Pro, 水月雨 (MOONDROP) 空鳴 - VOID, SONY WH1000XM5 (made a Upgrade/Balanced Cable by myself)

Re: Friendly formatting of frequency

Reply #14

foobar2000 v2.24.1 : 32-bit | 64-bit
Default UI Statusbar Device: FiiO 7

DSD Playing


WavPack DSD Playing
SHURE SRH1840, SENNHEISER HD660S2, SENNHEISER HD620S, SENNHEISER HD 490 Pro Plus, beyerdynamic DT 1990 PRO, HiFiMAN Edition XS, HIFIMAN ANANDA, Bowers & Wilkins P7, FiiO FT5, FiiO FT1 Pro, 水月雨 (MOONDROP) 空鳴 - VOID, SONY WH1000XM5 (made a Upgrade/Balanced Cable by myself)

Re: Friendly formatting of frequency

Reply #15
In the case of WavPack DSD, it's better to know it as "WavPack".
e.g
WavPack high lossless 2912 kbps DSD 1 bit/2822400 Hz

May I ask why would be important for you to know the container?

For me it's just a distraction; I prefer to see the DSD rate directly, especially in the playlist view.


Re: Friendly formatting of frequency

Reply #16
> May I ask why would be important for you to know the container?

Oh no, it seems that was a bit of a translation glitch. Sorry.

However, I personally find it easier to understand and more impactful to write it as "WavPack DSD", so it's a matter of preference.
You can pass in silence.
I hope this is getting through.
SHURE SRH1840, SENNHEISER HD660S2, SENNHEISER HD620S, SENNHEISER HD 490 Pro Plus, beyerdynamic DT 1990 PRO, HiFiMAN Edition XS, HIFIMAN ANANDA, Bowers & Wilkins P7, FiiO FT5, FiiO FT1 Pro, 水月雨 (MOONDROP) 空鳴 - VOID, SONY WH1000XM5 (made a Upgrade/Balanced Cable by myself)