@100mslive/hms-noise-suppression
Advanced tools
Comparing version
@@ -16,3 +16,3 @@ import { HMSAudioPlugin, HMSAudioPluginType } from '@100mslive/hms-video'; | ||
stop(): void; | ||
setNoiseSuppression(value: boolean): void; | ||
setEnabled(value: boolean): void; | ||
removeNoise(buffer: any, module: any): void; | ||
@@ -19,0 +19,0 @@ processAudioTrack(audioContext: AudioContext, sourceNode: MediaStreamAudioSourceNode): Promise<AudioNode>; |
{ | ||
"version": "0.1.4", | ||
"version": "0.1.5-1", | ||
"license": "MIT", | ||
@@ -42,11 +42,12 @@ "main": "dist/index.js", | ||
"path": "dist/hms-audionoise-suppression.cjs.production.min.js", | ||
"limit": "10 KB" | ||
"limit": "100 KB" | ||
}, | ||
{ | ||
"path": "dist/hms-audionoise-suppression.esm.js", | ||
"limit": "10 KB" | ||
"limit": "100 KB" | ||
} | ||
], | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^5.0.3", | ||
"@100mslive/hms-video": "0.0.176", | ||
"@size-limit/preset-small-lib": "^4.5.5", | ||
"husky": "^7.0.1", | ||
@@ -56,5 +57,7 @@ "size-limit": "^5.0.3", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.3.5", | ||
"@100mslive/hms-video": "0.0.176" | ||
"typescript": "^4.3.5" | ||
}, | ||
"resolutions": { | ||
"tsdx/**/node-notifier": "10.0.0" | ||
} | ||
} |
// @ts-ignore | ||
import { NoiseModule } from './models/Noise'; | ||
import { Module } from './models/index'; | ||
//import { NoiseModule } from './models/Noise'; | ||
import { HMSAudioPlugin, HMSAudioPluginType } from '@100mslive/hms-video'; | ||
@@ -34,24 +36,21 @@ | ||
if (!this.module) { | ||
this.module = { | ||
noExitRuntime: true, | ||
noInitialRun: true, | ||
preInit: [], | ||
preRun: [], | ||
postRun: [ | ||
function() { | ||
console.log(`Loaded Javascript Module OK`); | ||
}, | ||
], | ||
memoryInitializerPrefixURL: 'bin/', | ||
arguments: ['input.ivf', 'output.raw'], | ||
}; | ||
this.module = { | ||
noExitRuntime: true, | ||
noInitialRun: true, | ||
preInit: [], | ||
preRun: [], | ||
postRun: [ | ||
function() { | ||
console.log(`Loaded Javascript Module OK`); | ||
}, | ||
], | ||
memoryInitializerPrefixURL: 'bin/', | ||
arguments: ['input.ivf', 'output.raw'], | ||
}; | ||
NoiseModule(this.module); | ||
this.module.st = this.module._rnnoise_create(); | ||
this.module.ptr = this.module._malloc(480 * 4); | ||
this.log(TAG, 'background noise suppression module is initialized'); | ||
//set default random noise to false | ||
this.addRandomNoise(false); | ||
Module(this.module); | ||
this.module.st = this.module._rnnoise_create(); | ||
this.module.ptr = this.module._malloc(480 * 4); | ||
//set default random noise to false | ||
this.addRandomNoise(false); | ||
} | ||
@@ -77,12 +76,9 @@ } | ||
stop(): void { | ||
this.setNoiseSuppression(false); | ||
if(this.processingNode){ | ||
this.setEnabled(false); | ||
if (this.processingNode) { | ||
this.processingNode.disconnect(); | ||
} | ||
//TODO: see if we need to disconnect audio nodes also | ||
} | ||
setNoiseSuppression(value: boolean) { | ||
setEnabled(value: boolean) { | ||
this.suppressNoise = value; | ||
@@ -102,14 +98,14 @@ } | ||
processAudioTrack(audioContext: AudioContext, sourceNode: MediaStreamAudioSourceNode): Promise<AudioNode> { | ||
processAudioTrack( | ||
audioContext: AudioContext, | ||
sourceNode: MediaStreamAudioSourceNode | ||
): Promise<AudioNode> { | ||
if (!audioContext) { | ||
throw new Error('Audio context is not created'); | ||
} | ||
if (!sourceNode) { | ||
throw new Error('source node is not defined'); | ||
} | ||
if (this.module) { | ||
if (!this.nodesCreated) { | ||
this.log(TAG, 'nodes created'); | ||
this.createNodes(audioContext); | ||
@@ -119,3 +115,2 @@ this.nodesCreated = true; | ||
if (!this.nodesConnected) { | ||
this.log(TAG, 'nodes connected'); | ||
this.connectAudioNodes(audioContext, sourceNode); | ||
@@ -128,3 +123,2 @@ this.nodesConnected = true; | ||
} | ||
let frameBuffer: any = []; | ||
@@ -134,5 +128,3 @@ let inputBuffer: any = []; | ||
this.log(TAG, this.suppressNoise); | ||
this.processingNode.onaudioprocess = (e: any) => { | ||
@@ -143,7 +135,5 @@ let input = e.inputBuffer.getChannelData(0); | ||
// Drain input buffer. | ||
for (let i = 0; i < bufferSize; i++) { | ||
inputBuffer.push(input[i]); | ||
} | ||
while (inputBuffer.length >= 480) { | ||
@@ -153,7 +143,5 @@ for (let i = 0; i < 480; i++) { | ||
} | ||
if (this.suppressNoise) { | ||
this.removeNoise(frameBuffer, this.module); | ||
} | ||
for (let i = 0; i < 480; i++) { | ||
@@ -160,0 +148,0 @@ outputBuffer.push(frameBuffer[i]); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3
-50%2137121
-69.76%2966
-84.08%24
100%