mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
High bitrate/samplerate is now correctly clipped (#1318)
* High bitrate/samplerate is now correctly clipped This makes the ``kbps`` and ``kHz`` displays in the main window correctly emulate what Winamp does with high bitrates/samplerates. * Moved globals to be local to their designated functions Division is no longer performed in each if condition Default to displaying "0" for the kbps and khz fields (doesn't seem to trigger, though) * Use padStart and slice to more properly format the data Added comment by Justin Frankel on the meaning of H and C * Display "0" while gathering bitrate and khz * Remove logging of kbps in console Co-authored-by: Jordan Eldredge <jordan@jordaneldredge.com> * Assign ``finalKhz`` properly * Make CI hopefully happy --------- Co-authored-by: Jordan Eldredge <jordan@jordaneldredge.com>
This commit is contained in:
parent
8efe121f3c
commit
a56cbc54c5
2 changed files with 33 additions and 4 deletions
|
|
@ -6,6 +6,35 @@ export interface TracksState {
|
|||
[id: string]: PlaylistTrack;
|
||||
}
|
||||
|
||||
function massageKhz(khz: number) {
|
||||
let finalKhz: String;
|
||||
const khzNum: number = Math.round(khz / 1000);
|
||||
|
||||
// there is no real need to run a condition for below 100khz
|
||||
// when the other conditions (hopefully) take over
|
||||
// ...also to make CI happy
|
||||
finalKhz = String(khzNum);
|
||||
if (khzNum <= 10) finalKhz = String(khzNum).slice(0, 1).padStart(2, " ");
|
||||
if (khzNum >= 100) finalKhz = String(khzNum).slice(1, 3);
|
||||
return finalKhz;
|
||||
}
|
||||
|
||||
function massageKbps(kbps: number) {
|
||||
let finalKbps: String;
|
||||
const bitrateNum: number = Math.round(kbps / 1000);
|
||||
|
||||
finalKbps = String(bitrateNum); // present as is
|
||||
if (bitrateNum <= 100) finalKbps = String(bitrateNum).padStart(3, " ");
|
||||
if (bitrateNum <= 10) finalKbps = String(bitrateNum).padStart(3, " ");
|
||||
// from Justin Frankel directly:
|
||||
// IIRC H was for "hundred" and "C" was thousand,
|
||||
// though why it was for thousand I have no idea lol, maybe it was a mistake...
|
||||
if (bitrateNum >= 1000) finalKbps = String(bitrateNum).slice(0, 2) + "H";
|
||||
if (bitrateNum >= 10000)
|
||||
finalKbps = String(bitrateNum).slice(0, 1).padStart(2, " ") + "C";
|
||||
return finalKbps;
|
||||
}
|
||||
|
||||
const defaultPlaylistState: TracksState = {};
|
||||
|
||||
const tracks = (
|
||||
|
|
@ -80,8 +109,8 @@ const tracks = (
|
|||
artist,
|
||||
album,
|
||||
albumArtUrl,
|
||||
kbps: bitrate != null ? String(Math.round(bitrate / 1000)) : kbps,
|
||||
khz: sampleRate != null ? String(Math.round(sampleRate / 1000)) : khz,
|
||||
kbps: bitrate != null ? massageKbps(bitrate) : kbps,
|
||||
khz: sampleRate != null ? massageKhz(sampleRate) : khz,
|
||||
channels: numberOfChannels != null ? numberOfChannels : channels,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -686,14 +686,14 @@ export const getMarqueeText = (state: AppState): string => {
|
|||
export const getKbps = createSelector(
|
||||
getCurrentTrack,
|
||||
(track: PlaylistTrack | null): string | null => {
|
||||
return track != null ? track.kbps || null : null;
|
||||
return track != null ? track.kbps || "0".padStart(3, " ") : null;
|
||||
}
|
||||
);
|
||||
|
||||
export const getKhz = createSelector(
|
||||
getCurrentTrack,
|
||||
(track: PlaylistTrack | null): string | null => {
|
||||
return track != null ? track.khz || null : null;
|
||||
return track != null ? track.khz || "0".padStart(2, " ") : null;
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue