@ryohey/wavelet
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -394,2 +394,3 @@ const audioDataToAudioBuffer = (audioData) => { | ||
} | ||
this.currentEvents.sort(sortEvents); | ||
while (true) { | ||
@@ -408,2 +409,20 @@ const e = this.currentEvents.shift(); | ||
} | ||
function sortEvents(a, b) { | ||
// First, compare by scheduledFrame. | ||
if (a.scheduledFrame < b.scheduledFrame) { | ||
return -1; | ||
} | ||
else if (a.scheduledFrame > b.scheduledFrame) { | ||
return 1; | ||
} | ||
// If scheduledFrame is the same, compare by sequenceNumber. | ||
if (a.sequenceNumber < b.sequenceNumber) { | ||
return -1; | ||
} | ||
else if (a.sequenceNumber > b.sequenceNumber) { | ||
return 1; | ||
} | ||
// If both fields are the same. | ||
return 0; | ||
} | ||
@@ -828,4 +847,5 @@ var EnvelopePhase; | ||
const synth = new SynthProcessorCore(sampleRate, () => currentFrame); | ||
samples.forEach((e) => synth.addEvent(e)); | ||
events.forEach((e) => synth.addEvent(e)); | ||
let sequenceNumber = 0; | ||
samples.forEach((e) => synth.addEvent({ ...e, sequenceNumber: sequenceNumber++ })); | ||
events.forEach((e) => synth.addEvent({ ...e, sequenceNumber: sequenceNumber++ })); | ||
const songLengthFrame = getSongLength(events); | ||
@@ -832,0 +852,0 @@ const iterCount = Math.ceil(songLengthFrame / bufSize); |
@@ -386,2 +386,3 @@ (function () { | ||
} | ||
this.currentEvents.sort(sortEvents); | ||
while (true) { | ||
@@ -400,2 +401,20 @@ const e = this.currentEvents.shift(); | ||
} | ||
function sortEvents(a, b) { | ||
// First, compare by scheduledFrame. | ||
if (a.scheduledFrame < b.scheduledFrame) { | ||
return -1; | ||
} | ||
else if (a.scheduledFrame > b.scheduledFrame) { | ||
return 1; | ||
} | ||
// If scheduledFrame is the same, compare by sequenceNumber. | ||
if (a.sequenceNumber < b.sequenceNumber) { | ||
return -1; | ||
} | ||
else if (a.sequenceNumber > b.sequenceNumber) { | ||
return 1; | ||
} | ||
// If both fields are the same. | ||
return 0; | ||
} | ||
@@ -402,0 +421,0 @@ var EnvelopePhase; |
@@ -6,3 +6,3 @@ import { SampleParameter, SampleRange } from "../SynthEvent"; | ||
export type Sample = SampleParameter & { | ||
buffer: ArrayBuffer; | ||
buffer: Float32Array; | ||
}; | ||
@@ -9,0 +9,0 @@ export declare class SampleTable { |
@@ -10,5 +10,7 @@ import { ImmediateEvent, MIDIEventBody, SynthEvent } from "../SynthEvent"; | ||
private get currentFrame(); | ||
addEvent(e: SynthEvent): void; | ||
addEvent(e: SynthEvent & { | ||
sequenceNumber: number; | ||
}): void; | ||
processScheduledEvents(): void; | ||
removeScheduledEvents(channel: number): void; | ||
} |
@@ -13,3 +13,5 @@ import { SampleParameter, SampleRange, SynthEvent } from "../SynthEvent"; | ||
addSampleParameter(parameter: SampleParameter, range: SampleRange): void; | ||
addEvent(e: SynthEvent): void; | ||
addEvent(e: SynthEvent & { | ||
sequenceNumber: number; | ||
}): void; | ||
noteOn(channel: number, pitch: number, velocity: number): void; | ||
@@ -16,0 +18,0 @@ noteOff(channel: number, pitch: number): void; |
@@ -1,4 +0,4 @@ | ||
import { SampleData } from "../SynthEvent"; | ||
import { Sample } from "./SampleTable"; | ||
export declare class WavetableOscillator { | ||
readonly sample: SampleData<Float32Array>; | ||
readonly sample: Sample; | ||
private sampleIndex; | ||
@@ -18,3 +18,3 @@ private _isPlaying; | ||
isHold: boolean; | ||
constructor(sample: SampleData<Float32Array>, sampleRate: number); | ||
constructor(sample: Sample, sampleRate: number); | ||
noteOn(pitch: number, velocity: number): void; | ||
@@ -26,3 +26,3 @@ noteOff(): void; | ||
get isNoteOff(): boolean; | ||
get exclusiveClass(): any; | ||
get exclusiveClass(): number | undefined; | ||
} |
@@ -404,2 +404,3 @@ (function () { | ||
} | ||
this.currentEvents.sort(sortEvents); | ||
while (true) { | ||
@@ -418,2 +419,20 @@ const e = this.currentEvents.shift(); | ||
} | ||
function sortEvents(a, b) { | ||
// First, compare by scheduledFrame. | ||
if (a.scheduledFrame < b.scheduledFrame) { | ||
return -1; | ||
} | ||
else if (a.scheduledFrame > b.scheduledFrame) { | ||
return 1; | ||
} | ||
// If scheduledFrame is the same, compare by sequenceNumber. | ||
if (a.sequenceNumber < b.sequenceNumber) { | ||
return -1; | ||
} | ||
else if (a.sequenceNumber > b.sequenceNumber) { | ||
return 1; | ||
} | ||
// If both fields are the same. | ||
return 0; | ||
} | ||
@@ -838,4 +857,5 @@ var EnvelopePhase; | ||
const synth = new SynthProcessorCore(sampleRate, () => currentFrame); | ||
samples.forEach((e) => synth.addEvent(e)); | ||
events.forEach((e) => synth.addEvent(e)); | ||
let sequenceNumber = 0; | ||
samples.forEach((e) => synth.addEvent({ ...e, sequenceNumber: sequenceNumber++ })); | ||
events.forEach((e) => synth.addEvent({ ...e, sequenceNumber: sequenceNumber++ })); | ||
const songLengthFrame = getSongLength(events); | ||
@@ -842,0 +862,0 @@ const iterCount = Math.ceil(songLengthFrame / bufSize); |
@@ -46,2 +46,5 @@ import { AnyChannelEvent } from "midifile-ts"; | ||
export type SynthEvent = ImmediateEvent | MIDIEvent; | ||
export type SynthMessage = SynthEvent & { | ||
sequenceNumber: number; | ||
}; | ||
export declare const DrumInstrumentNumber = 128; |
{ | ||
"name": "@ryohey/wavelet", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "A wavetable synthesizer that never stops the UI thread created by AudioWorklet.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,3 +8,3 @@ import { SampleParameter, SampleRange } from "../SynthEvent" | ||
export type Sample = SampleParameter & { | ||
buffer: ArrayBuffer | ||
buffer: Float32Array | ||
} | ||
@@ -11,0 +11,0 @@ |
@@ -24,2 +24,3 @@ import { ImmediateEvent, MIDIEventBody } from "../SynthEvent" | ||
delayTime: 10, | ||
sequenceNumber: 0, | ||
}) | ||
@@ -36,2 +37,3 @@ scheduler.addEvent({ | ||
delayTime: 100, | ||
sequenceNumber: 1, | ||
}) | ||
@@ -48,2 +50,3 @@ scheduler.addEvent({ | ||
delayTime: 101, // This event should be ignored in first process | ||
sequenceNumber: 2, | ||
}) | ||
@@ -50,0 +53,0 @@ currentFrame = 100 |
@@ -10,3 +10,6 @@ import { | ||
type DelayedEvent = MIDIEvent & { scheduledFrame: number } | ||
type DelayedEvent = MIDIEvent & { | ||
scheduledFrame: number | ||
sequenceNumber: number | ||
} | ||
@@ -27,3 +30,3 @@ export class SynthEventScheduler { | ||
addEvent(e: SynthEvent) { | ||
addEvent(e: SynthEvent & { sequenceNumber: number }) { | ||
logger.log(e) | ||
@@ -62,2 +65,4 @@ | ||
this.currentEvents.sort(sortEvents) | ||
while (true) { | ||
@@ -81,1 +86,22 @@ const e = this.currentEvents.shift() | ||
} | ||
function sortEvents< | ||
T extends { scheduledFrame: number; sequenceNumber: number } | ||
>(a: T, b: T): number { | ||
// First, compare by scheduledFrame. | ||
if (a.scheduledFrame < b.scheduledFrame) { | ||
return -1 | ||
} else if (a.scheduledFrame > b.scheduledFrame) { | ||
return 1 | ||
} | ||
// If scheduledFrame is the same, compare by sequenceNumber. | ||
if (a.sequenceNumber < b.sequenceNumber) { | ||
return -1 | ||
} else if (a.sequenceNumber > b.sequenceNumber) { | ||
return 1 | ||
} | ||
// If both fields are the same. | ||
return 0 | ||
} |
@@ -79,3 +79,3 @@ import { SampleParameter, SampleRange, SynthEvent } from "../SynthEvent" | ||
addEvent(e: SynthEvent) { | ||
addEvent(e: SynthEvent & { sequenceNumber: number }) { | ||
this.eventScheduler.addEvent(e) | ||
@@ -82,0 +82,0 @@ } |
@@ -1,7 +0,7 @@ | ||
import { SampleData } from "../SynthEvent" | ||
import { AmplitudeEnvelope } from "./AmplitudeEnvelope" | ||
import { LFO } from "./LFO" | ||
import { Sample } from "./SampleTable" | ||
export class WavetableOscillator { | ||
readonly sample: SampleData<Float32Array> | ||
readonly sample: Sample | ||
private sampleIndex = 0 | ||
@@ -32,3 +32,3 @@ private _isPlaying = false | ||
constructor(sample: SampleData<Float32Array>, sampleRate: number) { | ||
constructor(sample: Sample, sampleRate: number) { | ||
this.sample = sample | ||
@@ -35,0 +35,0 @@ this.sampleRate = sampleRate |
@@ -44,4 +44,9 @@ import { | ||
samples.forEach((e) => synth.addEvent(e)) | ||
events.forEach((e) => synth.addEvent(e)) | ||
let sequenceNumber = 0 | ||
samples.forEach((e) => | ||
synth.addEvent({ ...e, sequenceNumber: sequenceNumber++ }) | ||
) | ||
events.forEach((e) => | ||
synth.addEvent({ ...e, sequenceNumber: sequenceNumber++ }) | ||
) | ||
@@ -48,0 +53,0 @@ const songLengthFrame = getSongLength(events) |
@@ -60,2 +60,8 @@ import { AnyChannelEvent } from "midifile-ts" | ||
// the type to be sent by postMessage | ||
export type SynthMessage = SynthEvent & { | ||
// A number assigned to each message to ensure the order in which they are sent is preserved upon reception. | ||
sequenceNumber: number | ||
} | ||
export const DrumInstrumentNumber = 128 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
518073
5106