@meframe/core 0.5.14 → 0.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +1 -0
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/model/types.d.ts +6 -0
- package/dist/model/types.d.ts.map +1 -1
- package/dist/model/types.js +9 -2
- package/dist/model/types.js.map +1 -1
- package/dist/node_modules/.pnpm/soundtouchjs@0.3.0/node_modules/soundtouchjs/dist/soundtouch.js +627 -0
- package/dist/node_modules/.pnpm/soundtouchjs@0.3.0/node_modules/soundtouchjs/dist/soundtouch.js.map +1 -0
- package/dist/orchestrator/AudioPreviewSession.d.ts.map +1 -1
- package/dist/orchestrator/AudioPreviewSession.js +12 -2
- package/dist/orchestrator/AudioPreviewSession.js.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.d.ts.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.js +2 -2
- package/dist/orchestrator/AudioWindowPreparer.js.map +1 -1
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +1 -0
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/stages/compose/OfflineAudioMixer.d.ts.map +1 -1
- package/dist/stages/compose/OfflineAudioMixer.js +16 -10
- package/dist/stages/compose/OfflineAudioMixer.js.map +1 -1
- package/dist/stages/compose/time-stretch.d.ts +14 -0
- package/dist/stages/compose/time-stretch.d.ts.map +1 -0
- package/dist/stages/compose/time-stretch.js +56 -0
- package/dist/stages/compose/time-stretch.js.map +1 -0
- package/dist/stages/decode/AudioChunkDecoder.d.ts +5 -0
- package/dist/stages/decode/AudioChunkDecoder.d.ts.map +1 -1
- package/dist/stages/decode/AudioChunkDecoder.js +38 -1
- package/dist/stages/decode/AudioChunkDecoder.js.map +1 -1
- package/dist/stages/load/ResourceLoader.d.ts +2 -0
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +10 -3
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/utils/loop-utils.d.ts +1 -1
- package/dist/utils/loop-utils.d.ts.map +1 -1
- package/dist/utils/loop-utils.js +6 -5
- package/dist/utils/loop-utils.js.map +1 -1
- package/package.json +3 -2
package/dist/node_modules/.pnpm/soundtouchjs@0.3.0/node_modules/soundtouchjs/dist/soundtouch.js
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
class FifoSampleBuffer {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._vector = new Float32Array();
|
|
4
|
+
this._position = 0;
|
|
5
|
+
this._frameCount = 0;
|
|
6
|
+
}
|
|
7
|
+
get vector() {
|
|
8
|
+
return this._vector;
|
|
9
|
+
}
|
|
10
|
+
get position() {
|
|
11
|
+
return this._position;
|
|
12
|
+
}
|
|
13
|
+
get startIndex() {
|
|
14
|
+
return this._position * 2;
|
|
15
|
+
}
|
|
16
|
+
get frameCount() {
|
|
17
|
+
return this._frameCount;
|
|
18
|
+
}
|
|
19
|
+
get endIndex() {
|
|
20
|
+
return (this._position + this._frameCount) * 2;
|
|
21
|
+
}
|
|
22
|
+
clear() {
|
|
23
|
+
this._vector.fill(0);
|
|
24
|
+
this._position = 0;
|
|
25
|
+
this._frameCount = 0;
|
|
26
|
+
}
|
|
27
|
+
put(numFrames) {
|
|
28
|
+
this._frameCount += numFrames;
|
|
29
|
+
}
|
|
30
|
+
putSamples(samples, position, numFrames = 0) {
|
|
31
|
+
position = position || 0;
|
|
32
|
+
const sourceOffset = position * 2;
|
|
33
|
+
if (!(numFrames >= 0)) {
|
|
34
|
+
numFrames = (samples.length - sourceOffset) / 2;
|
|
35
|
+
}
|
|
36
|
+
const numSamples = numFrames * 2;
|
|
37
|
+
this.ensureCapacity(numFrames + this._frameCount);
|
|
38
|
+
const destOffset = this.endIndex;
|
|
39
|
+
this.vector.set(samples.subarray(sourceOffset, sourceOffset + numSamples), destOffset);
|
|
40
|
+
this._frameCount += numFrames;
|
|
41
|
+
}
|
|
42
|
+
putBuffer(buffer, position, numFrames = 0) {
|
|
43
|
+
position = position || 0;
|
|
44
|
+
if (!(numFrames >= 0)) {
|
|
45
|
+
numFrames = buffer.frameCount - position;
|
|
46
|
+
}
|
|
47
|
+
this.putSamples(buffer.vector, buffer.position + position, numFrames);
|
|
48
|
+
}
|
|
49
|
+
receive(numFrames) {
|
|
50
|
+
if (!(numFrames >= 0) || numFrames > this._frameCount) {
|
|
51
|
+
numFrames = this.frameCount;
|
|
52
|
+
}
|
|
53
|
+
this._frameCount -= numFrames;
|
|
54
|
+
this._position += numFrames;
|
|
55
|
+
}
|
|
56
|
+
receiveSamples(output, numFrames = 0) {
|
|
57
|
+
const numSamples = numFrames * 2;
|
|
58
|
+
const sourceOffset = this.startIndex;
|
|
59
|
+
output.set(this._vector.subarray(sourceOffset, sourceOffset + numSamples));
|
|
60
|
+
this.receive(numFrames);
|
|
61
|
+
}
|
|
62
|
+
extract(output, position = 0, numFrames = 0) {
|
|
63
|
+
const sourceOffset = this.startIndex + position * 2;
|
|
64
|
+
const numSamples = numFrames * 2;
|
|
65
|
+
output.set(this._vector.subarray(sourceOffset, sourceOffset + numSamples));
|
|
66
|
+
}
|
|
67
|
+
ensureCapacity(numFrames = 0) {
|
|
68
|
+
const minLength = parseInt(numFrames * 2);
|
|
69
|
+
if (this._vector.length < minLength) {
|
|
70
|
+
const newVector = new Float32Array(minLength);
|
|
71
|
+
newVector.set(this._vector.subarray(this.startIndex, this.endIndex));
|
|
72
|
+
this._vector = newVector;
|
|
73
|
+
this._position = 0;
|
|
74
|
+
} else {
|
|
75
|
+
this.rewind();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
ensureAdditionalCapacity(numFrames = 0) {
|
|
79
|
+
this.ensureCapacity(this._frameCount + numFrames);
|
|
80
|
+
}
|
|
81
|
+
rewind() {
|
|
82
|
+
if (this._position > 0) {
|
|
83
|
+
this._vector.set(this._vector.subarray(this.startIndex, this.endIndex));
|
|
84
|
+
this._position = 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class AbstractFifoSamplePipe {
|
|
89
|
+
constructor(createBuffers) {
|
|
90
|
+
if (createBuffers) {
|
|
91
|
+
this._inputBuffer = new FifoSampleBuffer();
|
|
92
|
+
this._outputBuffer = new FifoSampleBuffer();
|
|
93
|
+
} else {
|
|
94
|
+
this._inputBuffer = this._outputBuffer = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
get inputBuffer() {
|
|
98
|
+
return this._inputBuffer;
|
|
99
|
+
}
|
|
100
|
+
set inputBuffer(inputBuffer) {
|
|
101
|
+
this._inputBuffer = inputBuffer;
|
|
102
|
+
}
|
|
103
|
+
get outputBuffer() {
|
|
104
|
+
return this._outputBuffer;
|
|
105
|
+
}
|
|
106
|
+
set outputBuffer(outputBuffer) {
|
|
107
|
+
this._outputBuffer = outputBuffer;
|
|
108
|
+
}
|
|
109
|
+
clear() {
|
|
110
|
+
this._inputBuffer.clear();
|
|
111
|
+
this._outputBuffer.clear();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class RateTransposer extends AbstractFifoSamplePipe {
|
|
115
|
+
constructor(createBuffers) {
|
|
116
|
+
super(createBuffers);
|
|
117
|
+
this.reset();
|
|
118
|
+
this._rate = 1;
|
|
119
|
+
}
|
|
120
|
+
set rate(rate) {
|
|
121
|
+
this._rate = rate;
|
|
122
|
+
}
|
|
123
|
+
reset() {
|
|
124
|
+
this.slopeCount = 0;
|
|
125
|
+
this.prevSampleL = 0;
|
|
126
|
+
this.prevSampleR = 0;
|
|
127
|
+
}
|
|
128
|
+
clear() {
|
|
129
|
+
super.clear();
|
|
130
|
+
this.reset();
|
|
131
|
+
}
|
|
132
|
+
clone() {
|
|
133
|
+
const result = new RateTransposer();
|
|
134
|
+
result.rate = this._rate;
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
process() {
|
|
138
|
+
const numFrames = this._inputBuffer.frameCount;
|
|
139
|
+
this._outputBuffer.ensureAdditionalCapacity(numFrames / this._rate + 1);
|
|
140
|
+
const numFramesOutput = this.transpose(numFrames);
|
|
141
|
+
this._inputBuffer.receive();
|
|
142
|
+
this._outputBuffer.put(numFramesOutput);
|
|
143
|
+
}
|
|
144
|
+
transpose(numFrames = 0) {
|
|
145
|
+
if (numFrames === 0) {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
const src = this._inputBuffer.vector;
|
|
149
|
+
const srcOffset = this._inputBuffer.startIndex;
|
|
150
|
+
const dest = this._outputBuffer.vector;
|
|
151
|
+
const destOffset = this._outputBuffer.endIndex;
|
|
152
|
+
let used = 0;
|
|
153
|
+
let i = 0;
|
|
154
|
+
while (this.slopeCount < 1) {
|
|
155
|
+
dest[destOffset + 2 * i] = (1 - this.slopeCount) * this.prevSampleL + this.slopeCount * src[srcOffset];
|
|
156
|
+
dest[destOffset + 2 * i + 1] = (1 - this.slopeCount) * this.prevSampleR + this.slopeCount * src[srcOffset + 1];
|
|
157
|
+
i = i + 1;
|
|
158
|
+
this.slopeCount += this._rate;
|
|
159
|
+
}
|
|
160
|
+
this.slopeCount -= 1;
|
|
161
|
+
if (numFrames !== 1) {
|
|
162
|
+
out: while (true) {
|
|
163
|
+
while (this.slopeCount > 1) {
|
|
164
|
+
this.slopeCount -= 1;
|
|
165
|
+
used = used + 1;
|
|
166
|
+
if (used >= numFrames - 1) {
|
|
167
|
+
break out;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const srcIndex = srcOffset + 2 * used;
|
|
171
|
+
dest[destOffset + 2 * i] = (1 - this.slopeCount) * src[srcIndex] + this.slopeCount * src[srcIndex + 2];
|
|
172
|
+
dest[destOffset + 2 * i + 1] = (1 - this.slopeCount) * src[srcIndex + 1] + this.slopeCount * src[srcIndex + 3];
|
|
173
|
+
i = i + 1;
|
|
174
|
+
this.slopeCount += this._rate;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
this.prevSampleL = src[srcOffset + 2 * numFrames - 2];
|
|
178
|
+
this.prevSampleR = src[srcOffset + 2 * numFrames - 1];
|
|
179
|
+
return i;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
class FilterSupport {
|
|
183
|
+
constructor(pipe) {
|
|
184
|
+
this._pipe = pipe;
|
|
185
|
+
}
|
|
186
|
+
get pipe() {
|
|
187
|
+
return this._pipe;
|
|
188
|
+
}
|
|
189
|
+
get inputBuffer() {
|
|
190
|
+
return this._pipe.inputBuffer;
|
|
191
|
+
}
|
|
192
|
+
get outputBuffer() {
|
|
193
|
+
return this._pipe.outputBuffer;
|
|
194
|
+
}
|
|
195
|
+
fillInputBuffer() {
|
|
196
|
+
throw new Error("fillInputBuffer() not overridden");
|
|
197
|
+
}
|
|
198
|
+
fillOutputBuffer(numFrames = 0) {
|
|
199
|
+
while (this.outputBuffer.frameCount < numFrames) {
|
|
200
|
+
const numInputFrames = 8192 * 2 - this.inputBuffer.frameCount;
|
|
201
|
+
this.fillInputBuffer(numInputFrames);
|
|
202
|
+
if (this.inputBuffer.frameCount < 8192 * 2) {
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
this._pipe.process();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
clear() {
|
|
209
|
+
this._pipe.clear();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const noop = function() {
|
|
213
|
+
return;
|
|
214
|
+
};
|
|
215
|
+
class SimpleFilter extends FilterSupport {
|
|
216
|
+
constructor(sourceSound, pipe, callback = noop) {
|
|
217
|
+
super(pipe);
|
|
218
|
+
this.callback = callback;
|
|
219
|
+
this.sourceSound = sourceSound;
|
|
220
|
+
this.historyBufferSize = 22050;
|
|
221
|
+
this._sourcePosition = 0;
|
|
222
|
+
this.outputBufferPosition = 0;
|
|
223
|
+
this._position = 0;
|
|
224
|
+
}
|
|
225
|
+
get position() {
|
|
226
|
+
return this._position;
|
|
227
|
+
}
|
|
228
|
+
set position(position) {
|
|
229
|
+
if (position > this._position) {
|
|
230
|
+
throw new RangeError("New position may not be greater than current position");
|
|
231
|
+
}
|
|
232
|
+
const newOutputBufferPosition = this.outputBufferPosition - (this._position - position);
|
|
233
|
+
if (newOutputBufferPosition < 0) {
|
|
234
|
+
throw new RangeError("New position falls outside of history buffer");
|
|
235
|
+
}
|
|
236
|
+
this.outputBufferPosition = newOutputBufferPosition;
|
|
237
|
+
this._position = position;
|
|
238
|
+
}
|
|
239
|
+
get sourcePosition() {
|
|
240
|
+
return this._sourcePosition;
|
|
241
|
+
}
|
|
242
|
+
set sourcePosition(sourcePosition) {
|
|
243
|
+
this.clear();
|
|
244
|
+
this._sourcePosition = sourcePosition;
|
|
245
|
+
}
|
|
246
|
+
onEnd() {
|
|
247
|
+
this.callback();
|
|
248
|
+
}
|
|
249
|
+
fillInputBuffer(numFrames = 0) {
|
|
250
|
+
const samples = new Float32Array(numFrames * 2);
|
|
251
|
+
const numFramesExtracted = this.sourceSound.extract(samples, numFrames, this._sourcePosition);
|
|
252
|
+
this._sourcePosition += numFramesExtracted;
|
|
253
|
+
this.inputBuffer.putSamples(samples, 0, numFramesExtracted);
|
|
254
|
+
}
|
|
255
|
+
extract(target, numFrames = 0) {
|
|
256
|
+
this.fillOutputBuffer(this.outputBufferPosition + numFrames);
|
|
257
|
+
const numFramesExtracted = Math.min(numFrames, this.outputBuffer.frameCount - this.outputBufferPosition);
|
|
258
|
+
this.outputBuffer.extract(target, this.outputBufferPosition, numFramesExtracted);
|
|
259
|
+
const currentFrames = this.outputBufferPosition + numFramesExtracted;
|
|
260
|
+
this.outputBufferPosition = Math.min(this.historyBufferSize, currentFrames);
|
|
261
|
+
this.outputBuffer.receive(Math.max(currentFrames - this.historyBufferSize, 0));
|
|
262
|
+
this._position += numFramesExtracted;
|
|
263
|
+
return numFramesExtracted;
|
|
264
|
+
}
|
|
265
|
+
handleSampleData(event) {
|
|
266
|
+
this.extract(event.data, 4096);
|
|
267
|
+
}
|
|
268
|
+
clear() {
|
|
269
|
+
super.clear();
|
|
270
|
+
this.outputBufferPosition = 0;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const USE_AUTO_SEQUENCE_LEN = 0;
|
|
274
|
+
const DEFAULT_SEQUENCE_MS = USE_AUTO_SEQUENCE_LEN;
|
|
275
|
+
const USE_AUTO_SEEKWINDOW_LEN = 0;
|
|
276
|
+
const DEFAULT_SEEKWINDOW_MS = USE_AUTO_SEEKWINDOW_LEN;
|
|
277
|
+
const DEFAULT_OVERLAP_MS = 8;
|
|
278
|
+
const _SCAN_OFFSETS = [[124, 186, 248, 310, 372, 434, 496, 558, 620, 682, 744, 806, 868, 930, 992, 1054, 1116, 1178, 1240, 1302, 1364, 1426, 1488, 0], [-100, -75, -50, -25, 25, 50, 75, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-20, -15, -10, -5, 5, 10, 15, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-4, -3, -2, -1, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
|
|
279
|
+
const AUTOSEQ_TEMPO_LOW = 0.25;
|
|
280
|
+
const AUTOSEQ_TEMPO_TOP = 4;
|
|
281
|
+
const AUTOSEQ_AT_MIN = 125;
|
|
282
|
+
const AUTOSEQ_AT_MAX = 50;
|
|
283
|
+
const AUTOSEQ_K = (AUTOSEQ_AT_MAX - AUTOSEQ_AT_MIN) / (AUTOSEQ_TEMPO_TOP - AUTOSEQ_TEMPO_LOW);
|
|
284
|
+
const AUTOSEQ_C = AUTOSEQ_AT_MIN - AUTOSEQ_K * AUTOSEQ_TEMPO_LOW;
|
|
285
|
+
const AUTOSEEK_AT_MIN = 25;
|
|
286
|
+
const AUTOSEEK_AT_MAX = 15;
|
|
287
|
+
const AUTOSEEK_K = (AUTOSEEK_AT_MAX - AUTOSEEK_AT_MIN) / (AUTOSEQ_TEMPO_TOP - AUTOSEQ_TEMPO_LOW);
|
|
288
|
+
const AUTOSEEK_C = AUTOSEEK_AT_MIN - AUTOSEEK_K * AUTOSEQ_TEMPO_LOW;
|
|
289
|
+
class Stretch extends AbstractFifoSamplePipe {
|
|
290
|
+
constructor(createBuffers) {
|
|
291
|
+
super(createBuffers);
|
|
292
|
+
this._quickSeek = true;
|
|
293
|
+
this.midBufferDirty = false;
|
|
294
|
+
this.midBuffer = null;
|
|
295
|
+
this.overlapLength = 0;
|
|
296
|
+
this.autoSeqSetting = true;
|
|
297
|
+
this.autoSeekSetting = true;
|
|
298
|
+
this._tempo = 1;
|
|
299
|
+
this.setParameters(44100, DEFAULT_SEQUENCE_MS, DEFAULT_SEEKWINDOW_MS, DEFAULT_OVERLAP_MS);
|
|
300
|
+
}
|
|
301
|
+
clear() {
|
|
302
|
+
super.clear();
|
|
303
|
+
this.clearMidBuffer();
|
|
304
|
+
}
|
|
305
|
+
clearMidBuffer() {
|
|
306
|
+
this.midBufferDirty = false;
|
|
307
|
+
this.midBuffer = null;
|
|
308
|
+
if (this.refMidBuffer) {
|
|
309
|
+
this.refMidBuffer.fill(0);
|
|
310
|
+
}
|
|
311
|
+
this.skipFract = 0;
|
|
312
|
+
}
|
|
313
|
+
setParameters(sampleRate, sequenceMs, seekWindowMs, overlapMs) {
|
|
314
|
+
if (sampleRate > 0) {
|
|
315
|
+
this.sampleRate = sampleRate;
|
|
316
|
+
}
|
|
317
|
+
if (overlapMs > 0) {
|
|
318
|
+
this.overlapMs = overlapMs;
|
|
319
|
+
}
|
|
320
|
+
if (sequenceMs > 0) {
|
|
321
|
+
this.sequenceMs = sequenceMs;
|
|
322
|
+
this.autoSeqSetting = false;
|
|
323
|
+
} else {
|
|
324
|
+
this.autoSeqSetting = true;
|
|
325
|
+
}
|
|
326
|
+
if (seekWindowMs > 0) {
|
|
327
|
+
this.seekWindowMs = seekWindowMs;
|
|
328
|
+
this.autoSeekSetting = false;
|
|
329
|
+
} else {
|
|
330
|
+
this.autoSeekSetting = true;
|
|
331
|
+
}
|
|
332
|
+
this.calculateSequenceParameters();
|
|
333
|
+
this.calculateOverlapLength(this.overlapMs);
|
|
334
|
+
this.tempo = this._tempo;
|
|
335
|
+
}
|
|
336
|
+
set tempo(newTempo) {
|
|
337
|
+
let intskip;
|
|
338
|
+
this._tempo = newTempo;
|
|
339
|
+
this.calculateSequenceParameters();
|
|
340
|
+
this.nominalSkip = this._tempo * (this.seekWindowLength - this.overlapLength);
|
|
341
|
+
this.skipFract = 0;
|
|
342
|
+
intskip = Math.floor(this.nominalSkip + 0.5);
|
|
343
|
+
this.sampleReq = Math.max(intskip + this.overlapLength, this.seekWindowLength) + this.seekLength;
|
|
344
|
+
}
|
|
345
|
+
get tempo() {
|
|
346
|
+
return this._tempo;
|
|
347
|
+
}
|
|
348
|
+
get inputChunkSize() {
|
|
349
|
+
return this.sampleReq;
|
|
350
|
+
}
|
|
351
|
+
get outputChunkSize() {
|
|
352
|
+
return this.overlapLength + Math.max(0, this.seekWindowLength - 2 * this.overlapLength);
|
|
353
|
+
}
|
|
354
|
+
calculateOverlapLength(overlapInMsec = 0) {
|
|
355
|
+
let newOvl;
|
|
356
|
+
newOvl = this.sampleRate * overlapInMsec / 1e3;
|
|
357
|
+
newOvl = newOvl < 16 ? 16 : newOvl;
|
|
358
|
+
newOvl -= newOvl % 8;
|
|
359
|
+
this.overlapLength = newOvl;
|
|
360
|
+
this.refMidBuffer = new Float32Array(this.overlapLength * 2);
|
|
361
|
+
this.midBuffer = new Float32Array(this.overlapLength * 2);
|
|
362
|
+
}
|
|
363
|
+
checkLimits(x, mi, ma) {
|
|
364
|
+
return x < mi ? mi : x > ma ? ma : x;
|
|
365
|
+
}
|
|
366
|
+
calculateSequenceParameters() {
|
|
367
|
+
let seq;
|
|
368
|
+
let seek;
|
|
369
|
+
if (this.autoSeqSetting) {
|
|
370
|
+
seq = AUTOSEQ_C + AUTOSEQ_K * this._tempo;
|
|
371
|
+
seq = this.checkLimits(seq, AUTOSEQ_AT_MAX, AUTOSEQ_AT_MIN);
|
|
372
|
+
this.sequenceMs = Math.floor(seq + 0.5);
|
|
373
|
+
}
|
|
374
|
+
if (this.autoSeekSetting) {
|
|
375
|
+
seek = AUTOSEEK_C + AUTOSEEK_K * this._tempo;
|
|
376
|
+
seek = this.checkLimits(seek, AUTOSEEK_AT_MAX, AUTOSEEK_AT_MIN);
|
|
377
|
+
this.seekWindowMs = Math.floor(seek + 0.5);
|
|
378
|
+
}
|
|
379
|
+
this.seekWindowLength = Math.floor(this.sampleRate * this.sequenceMs / 1e3);
|
|
380
|
+
this.seekLength = Math.floor(this.sampleRate * this.seekWindowMs / 1e3);
|
|
381
|
+
}
|
|
382
|
+
set quickSeek(enable) {
|
|
383
|
+
this._quickSeek = enable;
|
|
384
|
+
}
|
|
385
|
+
clone() {
|
|
386
|
+
const result = new Stretch();
|
|
387
|
+
result.tempo = this._tempo;
|
|
388
|
+
result.setParameters(this.sampleRate, this.sequenceMs, this.seekWindowMs, this.overlapMs);
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
seekBestOverlapPosition() {
|
|
392
|
+
return this._quickSeek ? this.seekBestOverlapPositionStereoQuick() : this.seekBestOverlapPositionStereo();
|
|
393
|
+
}
|
|
394
|
+
seekBestOverlapPositionStereo() {
|
|
395
|
+
let bestOffset;
|
|
396
|
+
let bestCorrelation;
|
|
397
|
+
let correlation;
|
|
398
|
+
let i = 0;
|
|
399
|
+
this.preCalculateCorrelationReferenceStereo();
|
|
400
|
+
bestOffset = 0;
|
|
401
|
+
bestCorrelation = Number.MIN_VALUE;
|
|
402
|
+
for (; i < this.seekLength; i = i + 1) {
|
|
403
|
+
correlation = this.calculateCrossCorrelationStereo(2 * i, this.refMidBuffer);
|
|
404
|
+
if (correlation > bestCorrelation) {
|
|
405
|
+
bestCorrelation = correlation;
|
|
406
|
+
bestOffset = i;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return bestOffset;
|
|
410
|
+
}
|
|
411
|
+
seekBestOverlapPositionStereoQuick() {
|
|
412
|
+
let bestOffset;
|
|
413
|
+
let bestCorrelation;
|
|
414
|
+
let correlation;
|
|
415
|
+
let scanCount = 0;
|
|
416
|
+
let correlationOffset;
|
|
417
|
+
let tempOffset;
|
|
418
|
+
this.preCalculateCorrelationReferenceStereo();
|
|
419
|
+
bestCorrelation = Number.MIN_VALUE;
|
|
420
|
+
bestOffset = 0;
|
|
421
|
+
correlationOffset = 0;
|
|
422
|
+
tempOffset = 0;
|
|
423
|
+
for (; scanCount < 4; scanCount = scanCount + 1) {
|
|
424
|
+
let j = 0;
|
|
425
|
+
while (_SCAN_OFFSETS[scanCount][j]) {
|
|
426
|
+
tempOffset = correlationOffset + _SCAN_OFFSETS[scanCount][j];
|
|
427
|
+
if (tempOffset >= this.seekLength) {
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
correlation = this.calculateCrossCorrelationStereo(2 * tempOffset, this.refMidBuffer);
|
|
431
|
+
if (correlation > bestCorrelation) {
|
|
432
|
+
bestCorrelation = correlation;
|
|
433
|
+
bestOffset = tempOffset;
|
|
434
|
+
}
|
|
435
|
+
j = j + 1;
|
|
436
|
+
}
|
|
437
|
+
correlationOffset = bestOffset;
|
|
438
|
+
}
|
|
439
|
+
return bestOffset;
|
|
440
|
+
}
|
|
441
|
+
preCalculateCorrelationReferenceStereo() {
|
|
442
|
+
let i = 0;
|
|
443
|
+
let context;
|
|
444
|
+
let temp;
|
|
445
|
+
for (; i < this.overlapLength; i = i + 1) {
|
|
446
|
+
temp = i * (this.overlapLength - i);
|
|
447
|
+
context = i * 2;
|
|
448
|
+
this.refMidBuffer[context] = this.midBuffer[context] * temp;
|
|
449
|
+
this.refMidBuffer[context + 1] = this.midBuffer[context + 1] * temp;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
calculateCrossCorrelationStereo(mixingPosition, compare) {
|
|
453
|
+
const mixing = this._inputBuffer.vector;
|
|
454
|
+
mixingPosition += this._inputBuffer.startIndex;
|
|
455
|
+
let correlation = 0;
|
|
456
|
+
let i = 2;
|
|
457
|
+
const calcLength = 2 * this.overlapLength;
|
|
458
|
+
let mixingOffset;
|
|
459
|
+
for (; i < calcLength; i = i + 2) {
|
|
460
|
+
mixingOffset = i + mixingPosition;
|
|
461
|
+
correlation += mixing[mixingOffset] * compare[i] + mixing[mixingOffset + 1] * compare[i + 1];
|
|
462
|
+
}
|
|
463
|
+
return correlation;
|
|
464
|
+
}
|
|
465
|
+
overlap(overlapPosition) {
|
|
466
|
+
this.overlapStereo(2 * overlapPosition);
|
|
467
|
+
}
|
|
468
|
+
overlapStereo(inputPosition) {
|
|
469
|
+
const input = this._inputBuffer.vector;
|
|
470
|
+
inputPosition += this._inputBuffer.startIndex;
|
|
471
|
+
const output = this._outputBuffer.vector;
|
|
472
|
+
const outputPosition = this._outputBuffer.endIndex;
|
|
473
|
+
let i = 0;
|
|
474
|
+
let context;
|
|
475
|
+
let tempFrame;
|
|
476
|
+
const frameScale = 1 / this.overlapLength;
|
|
477
|
+
let fi;
|
|
478
|
+
let inputOffset;
|
|
479
|
+
let outputOffset;
|
|
480
|
+
for (; i < this.overlapLength; i = i + 1) {
|
|
481
|
+
tempFrame = (this.overlapLength - i) * frameScale;
|
|
482
|
+
fi = i * frameScale;
|
|
483
|
+
context = 2 * i;
|
|
484
|
+
inputOffset = context + inputPosition;
|
|
485
|
+
outputOffset = context + outputPosition;
|
|
486
|
+
output[outputOffset + 0] = input[inputOffset + 0] * fi + this.midBuffer[context + 0] * tempFrame;
|
|
487
|
+
output[outputOffset + 1] = input[inputOffset + 1] * fi + this.midBuffer[context + 1] * tempFrame;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
process() {
|
|
491
|
+
let offset;
|
|
492
|
+
let temp;
|
|
493
|
+
let overlapSkip;
|
|
494
|
+
if (this.midBuffer === null) {
|
|
495
|
+
if (this._inputBuffer.frameCount < this.overlapLength) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
this.midBuffer = new Float32Array(this.overlapLength * 2);
|
|
499
|
+
this._inputBuffer.receiveSamples(this.midBuffer, this.overlapLength);
|
|
500
|
+
}
|
|
501
|
+
while (this._inputBuffer.frameCount >= this.sampleReq) {
|
|
502
|
+
offset = this.seekBestOverlapPosition();
|
|
503
|
+
this._outputBuffer.ensureAdditionalCapacity(this.overlapLength);
|
|
504
|
+
this.overlap(Math.floor(offset));
|
|
505
|
+
this._outputBuffer.put(this.overlapLength);
|
|
506
|
+
temp = this.seekWindowLength - 2 * this.overlapLength;
|
|
507
|
+
if (temp > 0) {
|
|
508
|
+
this._outputBuffer.putBuffer(this._inputBuffer, offset + this.overlapLength, temp);
|
|
509
|
+
}
|
|
510
|
+
const start = this._inputBuffer.startIndex + 2 * (offset + this.seekWindowLength - this.overlapLength);
|
|
511
|
+
this.midBuffer.set(this._inputBuffer.vector.subarray(start, start + 2 * this.overlapLength));
|
|
512
|
+
this.skipFract += this.nominalSkip;
|
|
513
|
+
overlapSkip = Math.floor(this.skipFract);
|
|
514
|
+
this.skipFract -= overlapSkip;
|
|
515
|
+
this._inputBuffer.receive(overlapSkip);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const testFloatEqual = function(a, b) {
|
|
520
|
+
return (a > b ? a - b : b - a) > 1e-10;
|
|
521
|
+
};
|
|
522
|
+
class SoundTouch {
|
|
523
|
+
constructor() {
|
|
524
|
+
this.transposer = new RateTransposer(false);
|
|
525
|
+
this.stretch = new Stretch(false);
|
|
526
|
+
this._inputBuffer = new FifoSampleBuffer();
|
|
527
|
+
this._intermediateBuffer = new FifoSampleBuffer();
|
|
528
|
+
this._outputBuffer = new FifoSampleBuffer();
|
|
529
|
+
this._rate = 0;
|
|
530
|
+
this._tempo = 0;
|
|
531
|
+
this.virtualPitch = 1;
|
|
532
|
+
this.virtualRate = 1;
|
|
533
|
+
this.virtualTempo = 1;
|
|
534
|
+
this.calculateEffectiveRateAndTempo();
|
|
535
|
+
}
|
|
536
|
+
clear() {
|
|
537
|
+
this.transposer.clear();
|
|
538
|
+
this.stretch.clear();
|
|
539
|
+
}
|
|
540
|
+
clone() {
|
|
541
|
+
const result = new SoundTouch();
|
|
542
|
+
result.rate = this.rate;
|
|
543
|
+
result.tempo = this.tempo;
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
546
|
+
get rate() {
|
|
547
|
+
return this._rate;
|
|
548
|
+
}
|
|
549
|
+
set rate(rate) {
|
|
550
|
+
this.virtualRate = rate;
|
|
551
|
+
this.calculateEffectiveRateAndTempo();
|
|
552
|
+
}
|
|
553
|
+
set rateChange(rateChange) {
|
|
554
|
+
this._rate = 1 + 0.01 * rateChange;
|
|
555
|
+
}
|
|
556
|
+
get tempo() {
|
|
557
|
+
return this._tempo;
|
|
558
|
+
}
|
|
559
|
+
set tempo(tempo) {
|
|
560
|
+
this.virtualTempo = tempo;
|
|
561
|
+
this.calculateEffectiveRateAndTempo();
|
|
562
|
+
}
|
|
563
|
+
set tempoChange(tempoChange) {
|
|
564
|
+
this.tempo = 1 + 0.01 * tempoChange;
|
|
565
|
+
}
|
|
566
|
+
set pitch(pitch) {
|
|
567
|
+
this.virtualPitch = pitch;
|
|
568
|
+
this.calculateEffectiveRateAndTempo();
|
|
569
|
+
}
|
|
570
|
+
set pitchOctaves(pitchOctaves) {
|
|
571
|
+
this.pitch = Math.exp(0.69314718056 * pitchOctaves);
|
|
572
|
+
this.calculateEffectiveRateAndTempo();
|
|
573
|
+
}
|
|
574
|
+
set pitchSemitones(pitchSemitones) {
|
|
575
|
+
this.pitchOctaves = pitchSemitones / 12;
|
|
576
|
+
}
|
|
577
|
+
get inputBuffer() {
|
|
578
|
+
return this._inputBuffer;
|
|
579
|
+
}
|
|
580
|
+
get outputBuffer() {
|
|
581
|
+
return this._outputBuffer;
|
|
582
|
+
}
|
|
583
|
+
calculateEffectiveRateAndTempo() {
|
|
584
|
+
const previousTempo = this._tempo;
|
|
585
|
+
const previousRate = this._rate;
|
|
586
|
+
this._tempo = this.virtualTempo / this.virtualPitch;
|
|
587
|
+
this._rate = this.virtualRate * this.virtualPitch;
|
|
588
|
+
if (testFloatEqual(this._tempo, previousTempo)) {
|
|
589
|
+
this.stretch.tempo = this._tempo;
|
|
590
|
+
}
|
|
591
|
+
if (testFloatEqual(this._rate, previousRate)) {
|
|
592
|
+
this.transposer.rate = this._rate;
|
|
593
|
+
}
|
|
594
|
+
if (this._rate > 1) {
|
|
595
|
+
if (this._outputBuffer != this.transposer.outputBuffer) {
|
|
596
|
+
this.stretch.inputBuffer = this._inputBuffer;
|
|
597
|
+
this.stretch.outputBuffer = this._intermediateBuffer;
|
|
598
|
+
this.transposer.inputBuffer = this._intermediateBuffer;
|
|
599
|
+
this.transposer.outputBuffer = this._outputBuffer;
|
|
600
|
+
}
|
|
601
|
+
} else {
|
|
602
|
+
if (this._outputBuffer != this.stretch.outputBuffer) {
|
|
603
|
+
this.transposer.inputBuffer = this._inputBuffer;
|
|
604
|
+
this.transposer.outputBuffer = this._intermediateBuffer;
|
|
605
|
+
this.stretch.inputBuffer = this._intermediateBuffer;
|
|
606
|
+
this.stretch.outputBuffer = this._outputBuffer;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
process() {
|
|
611
|
+
if (this._rate > 1) {
|
|
612
|
+
this.stretch.process();
|
|
613
|
+
this.transposer.process();
|
|
614
|
+
} else {
|
|
615
|
+
this.transposer.process();
|
|
616
|
+
this.stretch.process();
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
export {
|
|
621
|
+
AbstractFifoSamplePipe,
|
|
622
|
+
RateTransposer,
|
|
623
|
+
SimpleFilter,
|
|
624
|
+
SoundTouch,
|
|
625
|
+
Stretch
|
|
626
|
+
};
|
|
627
|
+
//# sourceMappingURL=soundtouch.js.map
|