ran pretty on the front
This commit is contained in:
parent
7743bda3eb
commit
4160235b92
54 changed files with 808 additions and 694 deletions
|
@ -1,4 +1,4 @@
|
|||
import type {IAnalyserNode, IAudioContext, IMediaStreamAudioSourceNode} from 'standardized-audio-context';
|
||||
import type { IAnalyserNode, IAudioContext, IMediaStreamAudioSourceNode } from "standardized-audio-context";
|
||||
|
||||
/**
|
||||
* Class to measure the sound volume of a media stream
|
||||
|
@ -7,10 +7,10 @@ export class SoundMeter {
|
|||
private instant: number;
|
||||
private clip: number;
|
||||
//private script: ScriptProcessorNode;
|
||||
private analyser: IAnalyserNode<IAudioContext>|undefined;
|
||||
private dataArray: Uint8Array|undefined;
|
||||
private context: IAudioContext|undefined;
|
||||
private source: IMediaStreamAudioSourceNode<IAudioContext>|undefined;
|
||||
private analyser: IAnalyserNode<IAudioContext> | undefined;
|
||||
private dataArray: Uint8Array | undefined;
|
||||
private context: IAudioContext | undefined;
|
||||
private source: IMediaStreamAudioSourceNode<IAudioContext> | undefined;
|
||||
|
||||
constructor() {
|
||||
this.instant = 0.0;
|
||||
|
@ -27,8 +27,7 @@ export class SoundMeter {
|
|||
this.dataArray = new Uint8Array(bufferLength);
|
||||
}
|
||||
|
||||
public connectToSource(stream: MediaStream, context: IAudioContext): void
|
||||
{
|
||||
public connectToSource(stream: MediaStream, context: IAudioContext): void {
|
||||
if (this.source !== undefined) {
|
||||
this.stop();
|
||||
}
|
||||
|
@ -42,8 +41,6 @@ export class SoundMeter {
|
|||
//analyser.connect(distortion);
|
||||
//distortion.connect(this.context.destination);
|
||||
//this.analyser.connect(this.context.destination);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public getVolume(): number {
|
||||
|
@ -52,16 +49,15 @@ export class SoundMeter {
|
|||
}
|
||||
this.analyser.getByteFrequencyData(this.dataArray);
|
||||
|
||||
|
||||
const input = this.dataArray;
|
||||
let i;
|
||||
let sum = 0.0;
|
||||
//let clipcount = 0;
|
||||
for (i = 0; i < input.length; ++i) {
|
||||
sum += input[i] * input[i];
|
||||
// if (Math.abs(input[i]) > 0.99) {
|
||||
// clipcount += 1;
|
||||
// }
|
||||
// if (Math.abs(input[i]) > 0.99) {
|
||||
// clipcount += 1;
|
||||
// }
|
||||
}
|
||||
this.instant = Math.sqrt(sum / input.length);
|
||||
//this.slow = 0.95 * that.slow + 0.05 * that.instant;
|
||||
|
@ -84,6 +80,4 @@ export class SoundMeter {
|
|||
this.dataArray = undefined;
|
||||
this.source = undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue