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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MQ Spectral Editor</title>
<style>
body {
font-family: monospace;
margin: 20px;
background: #1a1a1a;
color: #ddd;
}
.toolbar {
margin-bottom: 10px;
padding: 10px;
background: #2a2a2a;
border-radius: 4px;
}
button {
background: #3a3a3a;
color: #ddd;
border: 1px solid #555;
padding: 8px 16px;
margin-right: 8px;
cursor: pointer;
border-radius: 4px;
}
button:hover { background: #4a4a4a; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input[type="file"] { margin-right: 16px; }
.params {
display: inline-block;
margin-left: 20px;
}
label {
margin-right: 8px;
}
input[type="number"], select {
width: 80px;
background: #3a3a3a;
color: #ddd;
border: 1px solid #555;
padding: 4px;
border-radius: 3px;
}
#canvas {
border: 1px solid #555;
background: #000;
cursor: crosshair;
display: block;
margin-top: 10px;
}
#status {
margin-top: 10px;
padding: 8px;
background: #2a2a2a;
border-radius: 4px;
min-height: 20px;
}
.info {
color: #4af;
}
.warn {
color: #fa4;
}
.error {
color: #f44;
}
</style>
</head>
<body>
<h2>MQ Spectral Editor</h2>
<div class="toolbar">
<input type="file" id="wavFile" accept=".wav">
<button id="extractBtn" disabled>Extract Partials</button>
<div class="params">
<label>Hop:</label>
<input type="number" id="hopSize" value="256" min="64" max="1024" step="64">
<label>Threshold (dB):</label>
<input type="number" id="threshold" value="-60" min="-80" max="-20" step="5">
</div>
</div>
<canvas id="canvas" width="1400" height="600"></canvas>
<div id="tooltip" style="position: fixed; display: none; background: #2a2a2a; padding: 4px 8px; border: 1px solid #555; border-radius: 3px; pointer-events: none; font-size: 11px; z-index: 1000;"></div>
<div id="status">Load a WAV file to begin...</div>
<script src="fft.js"></script>
<script src="mq_extract.js"></script>
<script src="viewer.js"></script>
<script>
let audioBuffer = null;
let viewer = null;
const wavFile = document.getElementById('wavFile');
const extractBtn = document.getElementById('extractBtn');
const canvas = document.getElementById('canvas');
const status = document.getElementById('status');
const hopSize = document.getElementById('hopSize');
const threshold = document.getElementById('threshold');
const fftSize = 1024; // Fixed
// Load WAV file
wavFile.addEventListener('change', async (e) => {
const file = e.target.files[0];
if (!file) return;
setStatus('Loading WAV...', 'info');
try {
const arrayBuffer = await file.arrayBuffer();
const audioContext = new AudioContext();
audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
extractBtn.disabled = false;
setStatus(`Loaded: ${audioBuffer.duration.toFixed(2)}s, ${audioBuffer.sampleRate}Hz, ${audioBuffer.numberOfChannels}ch`, 'info');
// Create viewer
viewer = new SpectrogramViewer(canvas, audioBuffer);
} catch (err) {
setStatus('Error loading WAV: ' + err.message, 'error');
console.error(err);
}
});
// Extract partials
extractBtn.addEventListener('click', () => {
if (!audioBuffer) return;
setStatus('Extracting partials...', 'info');
extractBtn.disabled = true;
setTimeout(() => {
try {
const params = {
fftSize: fftSize,
hopSize: parseInt(hopSize.value),
threshold: parseFloat(threshold.value),
sampleRate: audioBuffer.sampleRate
};
const partials = extractPartials(audioBuffer, params);
setStatus(`Extracted ${partials.length} partials`, 'info');
// Update viewer
viewer.setPartials(partials);
} catch (err) {
setStatus('Extraction error: ' + err.message, 'error');
console.error(err);
}
extractBtn.disabled = false;
}, 50);
});
function setStatus(msg, type = '') {
status.innerHTML = msg;
status.className = type;
}
</script>
</body>
</html>
|