Skip to content

Commit 6601060

Browse files
committed
added MFCC data to SEPIA vad worker + display in test;
1 parent f888ad3 commit 6601060

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/modules/sepia-vad-worker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ function process(data) {
328328
//Process if we have enough frames
329329
var vadResults = [];
330330
var loudnessResults = [];
331+
var mfcc = [];
331332
while (_processRingBuffer.framesAvailable >= _vadBufferSize) {
332333
//pull samples
333334
_processRingBuffer.pull(_vadBuffer);
@@ -343,6 +344,8 @@ function process(data) {
343344
_maxLoudness = Math.max(_maxLoudness, loudness);
344345
_movingAvgLoudness = getWeightedMovingAverage(_movingAvgLoudness, loudness, _movingAvgLoudnessWeight);
345346

347+
mfcc.push(features.mfcc);
348+
346349
//activity check
347350
var voiceActivity = (loudness/_movingAvgLoudness) > (1 + vadMode/10)? 1 : 0;
348351
vadResults.push(voiceActivity);
@@ -367,6 +370,7 @@ function process(data) {
367370
voiceActivity: vadResults,
368371
voiceEnergy: voiceEnergy,
369372
voiceLoudness: loudnessResults,
373+
mfcc: mfcc,
370374
movingAvgLoudness: _movingAvgLoudness,
371375
maxLoudness: _maxLoudness
372376
});
@@ -387,8 +391,6 @@ function start(options) {
387391
function stop(options) {
388392
//TODO: anything to do?
389393
//NOTE: timing of this signal is not very well defined
390-
_movingAvgLoudness = undefined;
391-
_maxLoudness = 0;
392394
}
393395
function reset(options) {
394396
//TODO: clean up worker and prep. for restart
@@ -399,6 +401,8 @@ function release(options){
399401
_processRingBuffer = null;
400402
_vadBuffer = null;
401403
_previousVadBuffer = null;
404+
_movingAvgLoudness = undefined;
405+
_maxLoudness = 0;
402406
}
403407

404408
//--- helpers ---

test-commons.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ function usePlot(index, ele){
6868
if (container) container.style.display = p.use? "" : "none";
6969
}
7070
}
71+
function useHeatmap(index, ele){
72+
useHeatmaps[index] = ele.checked;
73+
if (heatmaps[index]) heatmaps[index].resetMax();
74+
}
75+
var useHeatmaps = {};
76+
var heatmaps = {};
7177

7278
function addChartContainerToPage(){
7379
var ele = document.createElement("div");

test.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ <h1>SEPIA Web Audio Processor</h1>
128128
<label>Plot 2:</label><input type="checkbox" id="usePlot2" checked onchange="usePlot(2, this);">
129129
<label>Plot 3:</label><input type="checkbox" id="usePlot3" onchange="usePlot(3, this);">
130130
<label>Plot 4:</label><input type="checkbox" id="usePlot4" checked onchange="usePlot(4, this);">
131+
<label>Heatmap 1:</label><input type="checkbox" id="useHeatmap1" onchange="useHeatmap(1, this);">
131132
</div>
132133
<div id="chart1" class="chart"></div>
133134
<div id="chart2" class="chart"></div>
134135
<div id="chart3" class="chart" style="display: none;"></div>
135136
<div id="chart4" class="chart"></div>
137+
<div id="heatmap1" class="chart"></div>
136138
</div>
137139
<script type='text/javascript' src="test-commons.js"></script>
138140
<script type='text/javascript'>
@@ -622,7 +624,25 @@ <h1>SEPIA Web Audio Processor</h1>
622624
waveEncoderSetGate('close');
623625
}
624626
}
627+
if (useHeatmaps[1] && data.mfcc != undefined){
628+
if (!heatmap1){
629+
let colorIndex = 4;
630+
heatmap1 = new uPlot.lazy.Heatmap(document.getElementById("heatmap1"), {
631+
dataPixelWidth: 4,
632+
dataPixelHeight: 4,
633+
colorIndex: colorIndex,
634+
maxDataPoints: 150
635+
});
636+
heatmaps[1] = heatmap1;
637+
}
638+
data.mfcc.forEach(function(d, i){
639+
heatmap1.addDataArray(d);
640+
});
641+
heatmap1.draw();
642+
}
625643
}
644+
var heatmap1;
645+
626646
var vadAutoActivate = true;
627647
var vadAutoActivateSequenceWasTrigger = false;
628648
var vadMinRecordTimeAfterActivate = 3000;

0 commit comments

Comments
 (0)