Repository navigation
Expand file tree
/
Copy pathdcr.js
More file actions
52 lines (49 loc) · 1.77 KB
/
Copy pathdcr.js
File metadata and controls
52 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { renderPairItem } from "../ui.js";
import { playItem } from "../audio.js";
export const dcr = {
id: "dcr",
label: "DCR — Degradation Category Rating",
description:
"Rate how degraded a processed sample sounds relative to its clean reference, on a 5-point impairment scale.",
defaultScale: [
{ value: 1, label: "Very annoying" },
{ value: 2, label: "Annoying" },
{ value: 3, label: "Slightly annoying" },
{ value: 4, label: "Perceptible, not annoying" },
{ value: 5, label: "Imperceptible" },
],
// items: [{ id, reference: {type, ...}, test: {type, ...} }]
// options: { itemLabel, allowSkip, onRate(itemId, rating) }
async runItems(items, config, { itemLabel = "Item", allowSkip = false, onRate }) {
const scale = config.scale ?? dcr.defaultScale;
for (let index = 0; index < items.length; index++) {
const item = items[index];
const action = await new Promise((resolve) => {
renderPairItem(
{
index,
total: items.length,
scale,
itemLabel,
heading: "Listen and rate the degradation",
description:
"A is the original, unprocessed reference. B is the processed version. Rate how degraded B sounds compared to A.",
playLabel: "Play A and B",
},
{
onPlay: async () => {
await playItem(item.reference, config.clickDelayMs);
await playItem(item.test, config.pairPauseMs ?? 500);
},
onRate: (rating) => {
onRate(item.id, rating);
resolve("continue");
},
onSkip: allowSkip ? () => resolve("skip") : undefined,
}
);
});
if (action === "skip") return;
}
},
};