Skip to content

Commit 23bccaf

Browse files
add extra fillSampleBufferWithNumSamples to exported wasm methods
1 parent 79c25e7 commit 23bccaf

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

wasmaudioworklet/synth1/assembly/__tests__/midi/midisynth.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class UpperKeys extends MidiVoice {
117117

118118
class LinearVoice extends MidiVoice {
119119
pos: f32 = 0.0;
120-
nextframe(): void {
120+
nextframe(): void {
121121
const val = this.pos / 128;
122122
this.channel.signal.add(val, val);
123123
this.pos++;
@@ -686,17 +686,17 @@ describe("midisynth", () => {
686686
for (let n = 0; n < 64; n++) {
687687
expect<f32>(samplebuffer[n]).toBe((n / 128.0) as f32);
688688
}
689-
689+
690690
for (let n = 64; n < 128; n++) {
691691
expect<f32>(samplebuffer[n]).toBe(0);
692692
}
693693

694694
fillSampleBufferWithNumSamples(64);
695-
695+
696696
for (let n = 0; n < 64; n++) {
697-
expect<f32>(samplebuffer[n]).toBe(((n+64) / 128.0) as f32);
697+
expect<f32>(samplebuffer[n]).toBe(((n + 64) / 128.0) as f32);
698698
}
699-
699+
700700
for (let n = 64; n < 128; n++) {
701701
expect<f32>(samplebuffer[n]).toBe(0);
702702
}

wasmaudioworklet/synth1/assembly/midi/midisynth.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class MidiChannel {
8383
if (voice.note === note) {
8484
if (this.controllerValues[CONTROL_SUSTAIN] >= 64) {
8585
this.sustainedVoices[note] = voice;
86-
} else {
86+
} else {
8787
voice.noteoff();
8888
}
8989
break;
@@ -142,15 +142,15 @@ export class MidiChannel {
142142
}
143143
if (oldestVoice !== null) {
144144
const voice = (oldestVoice as MidiVoice);
145-
for (let n = 0;n<sampleBufferFrames;n++) {
145+
for (let n = 0; n < sampleBufferFrames; n++) {
146146
voice.nextframe();
147147
const fact: f32 = ((sampleBufferFrames as f32) - (n as f32)) / (sampleBufferFrames as f32);
148-
this.voiceTransitionBuffer[n<<1] += this.signal.left * fact;
149-
this.voiceTransitionBuffer[(n<<1) + 1] += this.signal.right * fact;
148+
this.voiceTransitionBuffer[n << 1] += this.signal.left * fact;
149+
this.voiceTransitionBuffer[(n << 1) + 1] += this.signal.right * fact;
150150
this.signal.clear();
151151
}
152152
voice.activationCount = voiceActivationCount++;
153-
this.removeFromSustainedVoices(voice);
153+
this.removeFromSustainedVoices(voice);
154154
}
155155
return oldestVoice;
156156
}
@@ -237,10 +237,10 @@ export function shortmessage(val1: u8, val2: u8, val3: u8): void {
237237
}
238238

239239
export function getActiveVoicesStatusSnapshot(): usize {
240-
for (let n=0;n<activeVoices.length;n++) {
240+
for (let n = 0; n < activeVoices.length; n++) {
241241
const activeVoicesStatusSnapshotIndex = n * 3;
242-
if (activeVoices[n] != null) {
243-
const voice = (activeVoices[n] as MidiVoice);
242+
if (activeVoices[n] != null) {
243+
const voice = (activeVoices[n] as MidiVoice);
244244
activeVoicesStatusSnapshot[activeVoicesStatusSnapshotIndex] = voice.channelNo;
245245
activeVoicesStatusSnapshot[activeVoicesStatusSnapshotIndex + 1] = voice.note;
246246
activeVoicesStatusSnapshot[activeVoicesStatusSnapshotIndex + 2] = voice.velocity;
@@ -303,11 +303,11 @@ export function fillSampleBufferWithNumSamples(numSamples: i32): void {
303303

304304
channelsignal.left += midichannel.voiceTransitionBuffer[voiceTransitionBufferNdx];
305305
midichannel.voiceTransitionBuffer[voiceTransitionBufferNdx] = 0;
306-
channelsignal.right +=midichannel.voiceTransitionBuffer[voiceTransitionBufferNdx+1];
307-
midichannel.voiceTransitionBuffer[voiceTransitionBufferNdx+1] = 0;
308-
309-
midichannel.preprocess();
310-
306+
channelsignal.right += midichannel.voiceTransitionBuffer[voiceTransitionBufferNdx + 1];
307+
midichannel.voiceTransitionBuffer[voiceTransitionBufferNdx + 1] = 0;
308+
309+
midichannel.preprocess();
310+
311311
channelsignal.left *= midichannel.pan.leftLevel * midichannel.volume;
312312
channelsignal.right *= midichannel.pan.rightLevel * midichannel.volume;
313313

wasmaudioworklet/synth1/assembly/mixes/globalimports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export { sampleBufferFrames } from '../midi/midisynth';
6363
export { sampleBufferBytesPerChannel } from '../midi/midisynth';
6464
export { sampleBufferChannels } from '../midi/midisynth';
6565
export { samplebuffer } from '../midi/midisynth';
66+
export { freeverb } from '../midi/midisynth';
6667
export { outputline } from '../midi/midisynth';
6768
export { MidiChannel } from '../midi/midisynth';
6869
export { MidiVoice } from '../midi/midisynth';

wasmaudioworklet/synth1/browsercompilerwebworker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function createWebAssemblySongData(song, mode = EXPORT_MODE_MIDISYNTH_MULTIPART_
2828
export const midipartschedule: MidiSequencerPartSchedule[] = [new MidiSequencerPartSchedule(0, 0)];
2929
`;
3030
assemblyscriptsynthsources[wasi_main_src] = `
31-
export { fillSampleBuffer, samplebuffer, allNotesOff, shortmessage, getActiveVoicesStatusSnapshot } from './midi/midisynth';
31+
export { fillSampleBuffer, fillSampleBufferWithNumSamples, samplebuffer, allNotesOff, shortmessage, getActiveVoicesStatusSnapshot } from './midi/midisynth';
3232
export { seek, playEventsAndFillSampleBuffer, currentTimeMillis } from './midi/sequencer/midisequencer';
3333
import { midipartschedule } from './midi/sequencer/midiparts';
3434

wasmaudioworklet/synth1/wasmsynthassemblyscriptsources.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)