Skip to content

Commit dd73135

Browse files
authored
fix: web stretcher node parameter handling (#343)
* fix: web stretcher node parameter handling * fix: typos and spellcheck
1 parent bb0bbaa commit dd73135

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

.github/actions/spelling/allow.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ website
3636
audiodocs
3737
Doxygen
3838
mjs
39-
occuring
4039
UMD

packages/react-native-audio-api/src/web-core/StretcherNode.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default class StretcherNode extends AudioNode {
4646
_playbackRate: number = 1;
4747
_loopStart: number = -1;
4848
_loopEnd: number = -1;
49+
_loop = false;
4950
_isPlaying = false;
5051

5152
constructor(context: BaseAudioContext, node: IStretcherNode) {
@@ -59,7 +60,7 @@ export default class StretcherNode extends AudioNode {
5960

6061
public set buffer(buffer: AudioBuffer) {
6162
this._buffer = buffer;
62-
const channelArrays = [];
63+
const channelArrays: Float32Array[] = [];
6364

6465
for (let i = 0; i < buffer.numberOfChannels; i += 1) {
6566
channelArrays.push(buffer.getChannelData(i));
@@ -87,7 +88,9 @@ export default class StretcherNode extends AudioNode {
8788
public set loopStart(value: number) {
8889
this._loopStart = value;
8990

90-
(this.node as unknown as IStretcherNode).schedule({ loopStart: value });
91+
if (this._isPlaying) {
92+
(this.node as unknown as IStretcherNode).schedule({ loopStart: value });
93+
}
9194
}
9295

9396
public get loopEnd(): number {
@@ -97,7 +100,17 @@ export default class StretcherNode extends AudioNode {
97100
public set loopEnd(value: number) {
98101
this._loopEnd = value;
99102

100-
(this.node as unknown as IStretcherNode).schedule({ loopEnd: value });
103+
if (this._isPlaying) {
104+
(this.node as unknown as IStretcherNode).schedule({ loopEnd: value });
105+
}
106+
}
107+
108+
public get loop(): boolean {
109+
return this._loop;
110+
}
111+
112+
public set loop(value: boolean) {
113+
this._loop = value;
101114
}
102115

103116
public start(
@@ -109,12 +122,19 @@ export default class StretcherNode extends AudioNode {
109122
): void {
110123
this._isPlaying = true;
111124

125+
if (this.loop && this._loopStart !== -1 && this._loopEnd !== -1) {
126+
(this.node as unknown as IStretcherNode).schedule({
127+
loopStart: this._loopStart,
128+
loopEnd: this._loopEnd,
129+
});
130+
}
131+
112132
(this.node as unknown as IStretcherNode).start(
113-
when,
114-
offset,
115-
duration,
116-
rate,
117-
semitones
133+
when ?? 0,
134+
offset ?? 0,
135+
duration ?? this._buffer?.duration ?? 0,
136+
rate ?? this._playbackRate ?? 0,
137+
semitones ?? 0
118138
);
119139
}
120140

packages/react-native-audio-api/src/web-core/custom/signalsmithStretch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The current input time, within the sample buffer. You can change how often this
1414

1515
### `stretch.schedule({...})`
1616

17-
This adds a scheduled change, removing any scheduled changes occuring after this one. The object properties are:
17+
This adds a scheduled change, removing any scheduled changes occurring after this one. The object properties are:
1818

1919
- `output` (seconds): audio context time for this change. The node compensates for its own latency, but this means you might want to schedule some things ahead of time, otherwise you'll have a softer transition as it catches up.
2020
- `active` (bool): processing audio

packages/react-native-audio-api/src/web-core/custom/signalsmithStretch/SignalsmithStretch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
var SignalsmithStretch = (() => {
23
var _scriptName =
34
typeof document != 'undefined' ? document.currentScript?.src : undefined;

0 commit comments

Comments
 (0)