|
| 1 | +const highConflictIds = new Set([ |
| 2 | + 'double-spatial-risk', |
| 3 | + 'native-spatial-stack-blocked', |
| 4 | + 'double-eq-risk', |
| 5 | + 'stacked-noise-suppression', |
| 6 | + 'missing-stream-limiter', |
| 7 | + 'stream-clipping-risk', |
| 8 | + 'bass-masking-footsteps', |
| 9 | + 'latency-budget-fail' |
| 10 | +]); |
| 11 | + |
| 12 | +export function detectBottleneck(detectData = {}) { |
| 13 | + const findings = []; |
| 14 | + const conflicts = Array.isArray(detectData.conflicts) ? detectData.conflicts : []; |
| 15 | + const metrics = detectData.metrics || {}; |
| 16 | + |
| 17 | + if (detectData?.sonar && detectData?.discord) { |
| 18 | + findings.push({ |
| 19 | + id: 'sonar-discord-conflict', |
| 20 | + severity: 'high', |
| 21 | + title: 'Sonar + Discord likely conflicting', |
| 22 | + msg: 'Sonar + Discord likely conflicting', |
| 23 | + fix: 'Pick one processing path for voice while testing, then confirm Discord input/output.' |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + if (Number(detectData?.micClip) > 0.6) { |
| 28 | + findings.push({ |
| 29 | + id: 'mic-clipping-risk', |
| 30 | + severity: 'high', |
| 31 | + title: 'High mic clipping risk', |
| 32 | + msg: 'High mic clipping risk - lower gain', |
| 33 | + fix: 'Lower mic gain before trusting EQ, Sound Match, or Discord feedback.' |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + if (detectData?.iEm && !detectData?.eqActive) { |
| 38 | + findings.push({ |
| 39 | + id: 'iem-eq-needed', |
| 40 | + severity: 'medium', |
| 41 | + title: 'IEMs usually need EQ', |
| 42 | + msg: 'IEMs usually need EQ', |
| 43 | + fix: 'Start from a safe IEM profile and verify comfort before boosting cue bands.' |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + conflicts.forEach((conflict) => { |
| 48 | + findings.push({ |
| 49 | + id: conflict.id || 'conflict', |
| 50 | + severity: conflict.severity || (highConflictIds.has(conflict.id) ? 'high' : 'medium'), |
| 51 | + title: conflict.title || conflict.message || conflict.id || 'Audio conflict', |
| 52 | + fix: conflict.fix || 'Resolve this before applying a profile.' |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + if (Number(metrics.cpuLoadPercent) >= 75) { |
| 57 | + findings.push({ |
| 58 | + id: 'cpu-load-high', |
| 59 | + severity: 'medium', |
| 60 | + title: 'CPU load is high for live monitoring', |
| 61 | + fix: 'Use Game Mode or close extra analyzers while playing.' |
| 62 | + }); |
| 63 | + } |
| 64 | + |
| 65 | + if (Number(metrics.audioLatencyMs) > 30) { |
| 66 | + findings.push({ |
| 67 | + id: 'latency-budget-fail', |
| 68 | + severity: 'high', |
| 69 | + title: 'Latency budget is too high', |
| 70 | + fix: 'Use one spatial layer, one EQ path, and a lower-latency output route.' |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + if (Number(metrics.droppedFrames) > 0 || Number(metrics.monitorDrops) > 0) { |
| 75 | + findings.push({ |
| 76 | + id: 'monitor-drops', |
| 77 | + severity: 'medium', |
| 78 | + title: 'Monitoring loop dropped updates', |
| 79 | + fix: 'Switch to Game Mode or reduce analyzer size.' |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + const sorted = findings.sort((a, b) => severityRank(b.severity) - severityRank(a.severity)); |
| 84 | + const primary = sorted[0] || { |
| 85 | + id: 'none', |
| 86 | + severity: 'low', |
| 87 | + title: 'No bottleneck detected', |
| 88 | + fix: 'Keep the current profile and run one controlled match test.' |
| 89 | + }; |
| 90 | + |
| 91 | + return { |
| 92 | + schema: 'cueforge.bottleneck-diagnosis.v1', |
| 93 | + status: primary.severity === 'high' ? 'blocked' : sorted.length ? 'watch' : 'clear', |
| 94 | + primary, |
| 95 | + primaryBottleneck: { |
| 96 | + severity: primary.severity, |
| 97 | + msg: primary.msg || primary.title, |
| 98 | + fix: primary.fix |
| 99 | + }, |
| 100 | + issues: sorted.map((item) => ({ |
| 101 | + severity: item.severity, |
| 102 | + msg: item.msg || item.title, |
| 103 | + id: item.id, |
| 104 | + fix: item.fix |
| 105 | + })), |
| 106 | + findings: sorted, |
| 107 | + metrics: { |
| 108 | + cpuLoadPercent: Number(metrics.cpuLoadPercent) || 0, |
| 109 | + audioLatencyMs: Number(metrics.audioLatencyMs) || 0, |
| 110 | + droppedFrames: Number(metrics.droppedFrames || metrics.monitorDrops) || 0 |
| 111 | + } |
| 112 | + }; |
| 113 | +} |
| 114 | + |
| 115 | +function severityRank(severity) { |
| 116 | + return { high: 3, medium: 2, low: 1 }[severity] || 0; |
| 117 | +} |
0 commit comments