Skip to content

Commit

Permalink
gswaMixer: analyserType "hz|td"
Browse files Browse the repository at this point in the history
  • Loading branch information
mr21 committed Jul 13, 2024
1 parent 3315658 commit bab3a46
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions gswaMixer/gswaMixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class gswaMixer {
#vuAnalyserL = null;
#vuAnalyserR = null;
#vuAnalyserChan = null;
#analyserType = "hz";
$vuDataL = new Float32Array( gswaMixer.fftSizeVu / 2 );
$vuDataR = new Float32Array( gswaMixer.fftSizeVu / 2 );
$audioDataL = new Uint8Array( gswaMixer.fftSize / 2 );
$audioDataR = new Uint8Array( gswaMixer.fftSize / 2 );
$audioDataL = new Float32Array( gswaMixer.fftSize / 2 );
$audioDataR = new Float32Array( gswaMixer.fftSize / 2 );
#chans = {};
#ctrlMixer = new DAWCoreControllerMixer( {
$addChannel: this.#addChan.bind( this ),
Expand Down Expand Up @@ -99,38 +100,48 @@ class gswaMixer {
this.#vuAnalyserL.getFloatTimeDomainData( this.$vuDataL );
this.#vuAnalyserR.getFloatTimeDomainData( this.$vuDataR );
}
$changeAnalyser( type ) {
this.#analyserType = type;
}
$fillAudioData( chanId ) {
const nodes = this.#chans[ chanId ];

nodes.analyserL.getByteFrequencyData( this.$audioDataL );
nodes.analyserR.getByteFrequencyData( this.$audioDataR );
switch ( this.#analyserType ) {
case "hz":
nodes.analyserL.getFloatFrequencyData( this.$audioDataL );
nodes.analyserR.getFloatFrequencyData( this.$audioDataR );
break;
case "td":
nodes.analyserL.getFloatTimeDomainData( this.$audioDataL );
nodes.analyserR.getFloatTimeDomainData( this.$audioDataR );
break;
}
}

// .........................................................................
#addChan( id ) {
const ctx = this.ctx;
const pan = new gswaStereoPanner( ctx );
const gain = ctx.createGain();
const input = ctx.createGain();
const output = ctx.createGain();
const splitter = ctx.createChannelSplitter( 2 );
const analyserL = ctx.createAnalyser();
const analyserR = ctx.createAnalyser();

analyserL.fftSize =
analyserR.fftSize = gswaMixer.fftSize;
analyserL.smoothingTimeConstant =
analyserR.smoothingTimeConstant = 0;
input.connect( pan.getInput() );
pan.connect( gain );
gain.connect( output );
gain.connect( splitter );
splitter.connect( analyserL, 0 );
splitter.connect( analyserR, 1 );
this.#chans[ id ] = {
input, pan, gain, output, splitter, analyserL, analyserR,
analyserData: new Uint8Array( analyserL.frequencyBinCount )
const chan = {
pan: new gswaStereoPanner( ctx ),
gain: ctx.createGain(),
input: ctx.createGain(),
output: ctx.createGain(),
splitter: ctx.createChannelSplitter( 2 ),
analyserL: ctx.createAnalyser(),
analyserR: ctx.createAnalyser(),
};

chan.analyserL.fftSize =
chan.analyserR.fftSize = gswaMixer.fftSize;
chan.analyserL.smoothingTimeConstant =
chan.analyserR.smoothingTimeConstant = 0;
chan.input.connect( chan.pan.getInput() );
chan.pan.connect( chan.gain );
chan.gain.connect( chan.output );
chan.gain.connect( chan.splitter );
chan.splitter.connect( chan.analyserL, 0 );
chan.splitter.connect( chan.analyserR, 1 );
this.#chans[ id ] = chan;
Object.entries( this.#ctrlMixer.$data.channels ).forEach( kv => {
if ( kv[ 1 ].dest === id ) {
this.#redirectChan( kv[ 0 ], id );
Expand Down

0 comments on commit bab3a46

Please sign in to comment.