Skip to content

Commit

Permalink
transfer audio data
Browse files Browse the repository at this point in the history
I have no idea why i didn't do this before
the audio data is now a transferable buffer instead of a copied float32array
  • Loading branch information
spessasus committed May 22, 2024
1 parent 1330d52 commit 222e0a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/spessasynth_lib/soundfont/chunk/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ export class Sample {
return audioData;
}

/**
* forces the sample to load the buffer data again on next getAudioData
*/
pruneCache()
{
this.isSampleLoaded = false;
}

/**
* @returns {Promise<Float32Array>}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ class WorkletProcessor extends AudioWorkletProcessor {
break;

case workletMessageType.sampleDump:
workletDumpedSamplesList[data.sampleID] = data.sampleData;
// new because it's a transferred buffer
workletDumpedSamplesList[data.sampleID] = new Float32Array(data.sampleData);
// the sample maybe was loaded after the voice was sent... adjust the end position!

// not for all channels because the system tells us for what channel this voice was dumped! yay!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ dumpSample(channel, sample, id, messagePort)

// load the data
sample.getAudioData().then(sampleData => {
// the audio has been transferred, clear the cache!
sample.pruneCache();
messagePort.postMessage({
channelNumber: channel,
messageType: workletMessageType.sampleDump,
messageData: {
sampleID: id,
sampleData: sampleData
}
});
}, [sampleData.buffer]);
})
}

Expand Down
9 changes: 7 additions & 2 deletions src/website/ui/synthesizer_ui/synthetizer_ui.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { DEFAULT_GAIN, DEFAULT_PERCUSSION, Synthetizer } from '../../../spessasynth_lib/synthetizer/synthetizer.js'
import {
DEFAULT_GAIN,
DEFAULT_PERCUSSION,
Synthetizer,
VOICE_CAP,
} from '../../../spessasynth_lib/synthetizer/synthetizer.js'
import { getDrumsSvg, getLoopSvg, getMuteSvg, getNoteSvg, getVolumeSvg } from '../icons.js'
import { ShiftableByteArray } from '../../../spessasynth_lib/utils/shiftable_array.js'
import { Meter } from './synthui_meter.js'
Expand Down Expand Up @@ -112,7 +117,7 @@ export class SynthetizerUI
this.voiceMeter = new Meter("#206",
"Voices: ",
0,
this.synth.voiceCap,
VOICE_CAP,
"The total amount of voices currently playing");
this.voiceMeter.bar.classList.add("voice_meter_bar_smooth");

Expand Down

0 comments on commit 222e0a0

Please sign in to comment.