Skip to content

Commit

Permalink
Add WhiteNoiseReducer and Reset to use dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
crazoter committed Sep 22, 2019
1 parent 70a4198 commit 349fe7a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
3 changes: 2 additions & 1 deletion PanoptoPlus/dev/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Panopto Plus",
"version": "1.3.7",
"version": "1.3.8",
"description": "Improve your webcasting experience!",
"manifest_version": 2,
"permissions": ["tabs", "storage"],
Expand Down Expand Up @@ -49,6 +49,7 @@
"panopto/js/ui/silence-cue-manager.js",
"panopto/js/ui/speed-slider.js",
"panopto/js/ui/volume-booster.js",
"panopto/js/ui/white-noise-reducer.js",
"panopto/js/ui/sidebar.js",
"panopto/js/ui/settings-page.js",
"panopto/js/ui/transcript-display.js",
Expand Down
4 changes: 2 additions & 2 deletions PanoptoPlus/dev/panopto/js/core/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ let Settings = (() => {
{"name":"settings_subtitles","value":1},
{"name":"settings_machinetranscript","value":1},
{"name":"settings_silencetrimming","value":1},
{"name":"settings_silencethreshold","value":1.89},
{"name":"settings_staticnoisedetection","value":1}
{"name":"settings_silencethreshold","value":2.66},
{"name":"settings_staticnoisedetection","value":0}
];
data.push({name: "time", value: new Date().getTime()});
return data;
Expand Down
3 changes: 2 additions & 1 deletion PanoptoPlus/dev/panopto/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
tsTracker: new TSTracker(settings),
carouselManager: new CarouselManager(settings),
//loggerDisabler: new LoggerDisabler(settings),//disabled
delayDisabler: new DelayDisabler(settings)
delayDisabler: new DelayDisabler(settings),
whiteNoiseReducer: new WhiteNoiseReducer(settings),
};

//Initialize initial settings
Expand Down
21 changes: 21 additions & 0 deletions PanoptoPlus/dev/panopto/js/jsmpeg/vad-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ VADProcessor = (() => {
if (!referenceLineFeatures && options.useFixedNoiseSample !== 0) {
switch (options.useFixedNoiseSample) {
//in case we want to extend it to more options
/*
default: referenceLineFeatures = [
[
{lowerBound: 4.888785711454075, upperBound: 6.783195750496256},
{lowerBound: 2.1059212543708576, upperBound: 6.2027694188546185},
{lowerBound: 2.731769271190809, upperBound: 7.5631685867822185},
{lowerBound: 3.3279498376197383, upperBound: 12.767826545633696},
{lowerBound: 15.056480962156463, upperBound: 60.7670527762376},
],
[
{lowerBound: 4.888785711454075, upperBound: 6.783195750496256},
{lowerBound: 2.1059212543708576, upperBound: 6.2027694188546185},
{lowerBound: 2.731769271190809, upperBound: 7.5631685867822185},
{lowerBound: 3.3279498376197383, upperBound: 12.767826545633696},
{lowerBound: 15.056480962156463, upperBound: 60.7670527762376}
]
];
break;*/
//*/

default: referenceLineFeatures = [
[
{lowerBound: 5.222302787585955, upperBound: 8.18209849619599},
Expand All @@ -95,6 +115,7 @@ VADProcessor = (() => {
]
];
break;

}
}

Expand Down
73 changes: 73 additions & 0 deletions PanoptoPlus/dev/panopto/js/ui/white-noise-reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* WhiteNoiseReducer reduces white noise.
*/
let WhiteNoiseReducer = (() => {
let audioContexts = [];

class WhiteNoiseReducer {
/**
* Initializes White Noise Reducer upon videos loaded.
* @param {Object} settings settings object
*/
constructor(settings) {
VideosLoadedEvent.subscribe(() => {
this.setup();
});
}

/**
* Setup the audiocontexts, called by the constructor.
*/
setup() {
let doms = document.getElementsByTagName("video");
for (let i = 0; i < doms.length; i++)
audioContexts.push(this.prepareAudioContext(doms[i]));
}

/**
* Modifications to the noise https://stackoverflow.com/questions/16949768/how-can-i-reduce-the-noise-of-a-microphone-input-with-the-web-audio-api
* @param {DOM} mediaElem MediaElement (video) which will have its audio modified
* @returns Object containing the compressor and filter
*/
prepareAudioContext(mediaElem) {
var context = new(window.AudioContext || window.webkitAudioContext),
result = {
context: context,
source: context.createMediaElementSource(mediaElem),
compressor: context.createDynamicsCompressor(),
filter: context.createBiquadFilter(),
media: mediaElem
};
//Setup Compressor
result.compressor.threshold.value = -50;
result.compressor.knee.value = 40;
result.compressor.ratio.value = 12;
//https://github.com/GoogleChromeLabs/web-audio-samples/wiki/DynamicsCompressor.reduction
/*
if (typeof result.compressor.reduction === 'number'
|| typeof result.compressor.reduction === 'float') {
result.compressor.reduction = -20;
} else {
result.compressor.reduction.value = -20;
}*/
result.compressor.attack.value = 0;
result.compressor.release.value = 0.25;

//Setup Filter
//result.filter.Q.value = 8.30;
result.filter.Q.value = 1.80;
result.filter.frequency.value = 355;//355;
result.filter.gain.value = 25;
result.filter.type = 'bandpass';
result.filter.connect(result.compressor);

//Link the pieces together
result.source.connect(result.filter);
result.compressor.connect(context.destination);
//result.filter.connect(context.destination);

return result;
}
}
return WhiteNoiseReducer;
})();

0 comments on commit 349fe7a

Please sign in to comment.