Skip to content

Commit

Permalink
gswaMixer: add a VU analyser for the selected chan
Browse files Browse the repository at this point in the history
  • Loading branch information
mr21 committed Jul 7, 2024
1 parent 3720ee3 commit 6835112
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions gswaMixer/gswaMixer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"use strict";

class gswaMixer {
static fftSizeVu = 1024;
static fftSize = 4096;
ctx = null;
connectedTo = null;
#vuAnalyserL = null;
#vuAnalyserR = null;
#vuAnalyserChan = null;
$vuDataL = new Float32Array( gswaMixer.fftSizeVu / 2 );
$vuDataR = new Float32Array( gswaMixer.fftSizeVu / 2 );
$audioDataL = new Uint8Array( gswaMixer.fftSize / 2 );
$audioDataR = new Uint8Array( gswaMixer.fftSize / 2 );
#chans = {};
Expand All @@ -24,6 +30,10 @@ class gswaMixer {
$setContext( ctx ) {
this.$disconnect();
this.ctx = ctx;
this.#vuAnalyserL = ctx.createAnalyser();
this.#vuAnalyserR = ctx.createAnalyser();
this.#vuAnalyserL.fftSize =
this.#vuAnalyserR.fftSize = gswaMixer.fftSize;
if ( "main" in this.#ctrlMixer.$data.channels ) {
this.#ctrlMixer.$recall();
} else {
Expand All @@ -38,6 +48,9 @@ class gswaMixer {
},
} );
}
this.#vuAnalyserChan = "main";
this.#chans.main.splitter.connect( this.#vuAnalyserL, 0 );
this.#chans.main.splitter.connect( this.#vuAnalyserR, 1 );
}
$change( obj ) {
this.#ctrlMixer.$change( obj );
Expand Down Expand Up @@ -72,6 +85,20 @@ class gswaMixer {
$getChanOutput( id ) {
return this.#chans[ id ]?.pan.getInput();
}
$fillAudioDataVu( chanId ) {
if ( chanId !== this.#vuAnalyserChan ) {
const nodesOld = this.#chans[ this.#vuAnalyserChan ];
const nodes = this.#chans[ chanId ];

nodesOld.splitter.disconnect( this.#vuAnalyserL, 0 );
nodesOld.splitter.disconnect( this.#vuAnalyserR, 1 );
nodes.splitter.connect( this.#vuAnalyserL, 0 );
nodes.splitter.connect( this.#vuAnalyserR, 1 );
this.#vuAnalyserChan = chanId;
}
this.#vuAnalyserL.getFloatTimeDomainData( this.$vuDataL );
this.#vuAnalyserR.getFloatTimeDomainData( this.$vuDataR );
}
$fillAudioData( chanId ) {
const nodes = this.#chans[ chanId ];

Expand Down

0 comments on commit 6835112

Please sign in to comment.