Skip to content

Commit a56cbc5

Browse files
0x5066captbaritone
andauthored
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>
1 parent 8efe121 commit a56cbc5

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

packages/webamp/js/reducers/tracks.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ export interface TracksState {
66
[id: string]: PlaylistTrack;
77
}
88

9+
function massageKhz(khz: number) {
10+
let finalKhz: String;
11+
const khzNum: number = Math.round(khz / 1000);
12+
13+
// there is no real need to run a condition for below 100khz
14+
// when the other conditions (hopefully) take over
15+
// ...also to make CI happy
16+
finalKhz = String(khzNum);
17+
if (khzNum <= 10) finalKhz = String(khzNum).slice(0, 1).padStart(2, " ");
18+
if (khzNum >= 100) finalKhz = String(khzNum).slice(1, 3);
19+
return finalKhz;
20+
}
21+
22+
function massageKbps(kbps: number) {
23+
let finalKbps: String;
24+
const bitrateNum: number = Math.round(kbps / 1000);
25+
26+
finalKbps = String(bitrateNum); // present as is
27+
if (bitrateNum <= 100) finalKbps = String(bitrateNum).padStart(3, " ");
28+
if (bitrateNum <= 10) finalKbps = String(bitrateNum).padStart(3, " ");
29+
// from Justin Frankel directly:
30+
// IIRC H was for "hundred" and "C" was thousand,
31+
// though why it was for thousand I have no idea lol, maybe it was a mistake...
32+
if (bitrateNum >= 1000) finalKbps = String(bitrateNum).slice(0, 2) + "H";
33+
if (bitrateNum >= 10000)
34+
finalKbps = String(bitrateNum).slice(0, 1).padStart(2, " ") + "C";
35+
return finalKbps;
36+
}
37+
938
const defaultPlaylistState: TracksState = {};
1039

1140
const tracks = (
@@ -80,8 +109,8 @@ const tracks = (
80109
artist,
81110
album,
82111
albumArtUrl,
83-
kbps: bitrate != null ? String(Math.round(bitrate / 1000)) : kbps,
84-
khz: sampleRate != null ? String(Math.round(sampleRate / 1000)) : khz,
112+
kbps: bitrate != null ? massageKbps(bitrate) : kbps,
113+
khz: sampleRate != null ? massageKhz(sampleRate) : khz,
85114
channels: numberOfChannels != null ? numberOfChannels : channels,
86115
},
87116
};

packages/webamp/js/selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,14 @@ export const getMarqueeText = (state: AppState): string => {
686686
export const getKbps = createSelector(
687687
getCurrentTrack,
688688
(track: PlaylistTrack | null): string | null => {
689-
return track != null ? track.kbps || null : null;
689+
return track != null ? track.kbps || "0".padStart(3, " ") : null;
690690
}
691691
);
692692

693693
export const getKhz = createSelector(
694694
getCurrentTrack,
695695
(track: PlaylistTrack | null): string | null => {
696-
return track != null ? track.khz || null : null;
696+
return track != null ? track.khz || "0".padStart(2, " ") : null;
697697
}
698698
);
699699

0 commit comments

Comments
 (0)