Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit d84c38e

Browse files
authored
Revert feat: DEV-4034: Rendering performance improvements for large-duration audio (#1138) (#1160)
Revert "feat: DEV-4034: Rendering performance improvements for large-duration audio (#1138)" This reverts commit 5a7210b.
1 parent 83ce830 commit d84c38e

19 files changed

+445
-936
lines changed

Diff for: package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"start": "yarn run copy-examples && node dev-server.js",
4545
"test:coverage": "yarn test -- --coverage",
4646
"test:watch": "react-scripts test",
47-
"test": "yarn jest src",
48-
"postinstall": "sh scripts/postinstall.sh"
47+
"test": "yarn jest src"
4948
},
5049
"husky": {
5150
"hooks": {
@@ -86,7 +85,6 @@
8685
],
8786
"dependencies": {
8887
"@thi.ng/rle-pack": "^2.1.6",
89-
"audio-file-decoder": "^2.3.0",
9088
"babel-preset-react-app": "^9.1.1",
9189
"d3": "^5.16.0",
9290
"magic-wand-js": "^1.0.0",
@@ -116,8 +114,8 @@
116114
"@types/jest": "^29.2.3",
117115
"@types/keymaster": "^1.6.30",
118116
"@types/lodash.ismatch": "^4.4.6",
119-
"@types/nanoid": "^3.0.0",
120117
"@types/offscreencanvas": "^2019.6.4",
118+
"@types/nanoid": "^3.0.0",
121119
"@types/react-dom": "^17.0.11",
122120
"@types/react-window": "^1.8.5",
123121
"@types/strman": "^2.0.0",
@@ -142,7 +140,6 @@
142140
"enzyme-to-json": "^3.5.0",
143141
"eslint": "^8.28.0",
144142
"eslint-webpack-plugin": "^3.0.1",
145-
"file-loader": "^6.2.0",
146143
"html-webpack-plugin": "^5.3.1",
147144
"husky": "^3.1.0",
148145
"identity-obj-proxy": "^3.0.0",

Diff for: scripts/postinstall.sh

-1
This file was deleted.

Diff for: src/components/Timeline/Controls/AudioControl.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IconSoundConfig, IconSoundMutedConfig } from '../../../assets/icons/tim
66
import { ControlButton } from '../Controls';
77
import { Slider } from './Slider';
88

9-
const MAX_VOL = 100;
9+
const MAX_VOL = 200;
1010

1111
export interface AudioControlProps {
1212
volume: number;
@@ -38,15 +38,15 @@ export const AudioControl: FC<AudioControlProps> = ({
3838
onVolumeChange?.(0);
3939
return;
4040
}
41-
if (_volumeValue > MAX_VOL) {
41+
if (_volumeValue > (MAX_VOL)) {
4242
onVolumeChange?.(MAX_VOL / 100);
4343
return;
4444
} else if (_volumeValue < 0) {
4545
onVolumeChange?.(0);
4646
return;
4747
}
4848

49-
onVolumeChange?.(_volumeValue / MAX_VOL);
49+
onVolumeChange?.(_volumeValue / MAX_VOL * 2);
5050
};
5151

5252
const handleSetMute = () => {
@@ -60,7 +60,7 @@ export const AudioControl: FC<AudioControlProps> = ({
6060
<Slider
6161
min={0}
6262
max={MAX_VOL}
63-
value={Math.round(volume * MAX_VOL)}
63+
value={Math.round(volume * MAX_VOL / 2)}
6464
onChange={handleSetVolume}
6565
description={'Volume'}
6666
info={'Increase or decrease the volume of the audio'}

Diff for: src/lib/AudioUltra/Controls/Player.ts

+26-45
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export class Player extends Destructable {
2727
* Get current playback speed
2828
*/
2929
get rate() {
30-
if (this.audio) {
31-
if (this.audio.speed !== this._rate) {
32-
this.audio.speed = this._rate; // restore the correct rate
30+
if (this.audio?.source?.playbackRate.value) {
31+
if (this.audio.source.playbackRate.value !== this._rate) {
32+
this.audio.source.playbackRate.value = this._rate; // restore the correct rate
3333
}
3434
}
3535

@@ -44,8 +44,8 @@ export class Player extends Destructable {
4444

4545
this._rate = value;
4646

47-
if (this.audio) {
48-
this.audio.speed = value;
47+
if (this.audio?.source) {
48+
this.audio.source.playbackRate.value = value;
4949

5050
if (rateChanged) {
5151
this.wf.invoke('rateChanged', [value]);
@@ -54,28 +54,22 @@ export class Player extends Destructable {
5454
}
5555

5656
get duration() {
57-
return this.audio?.duration ?? 0;
57+
return this.audio?.buffer?.duration ?? 0;
5858
}
5959

6060
get volume() {
61-
return this.audio?.volume ?? 1;
61+
return this.audio?.gain?.gain.value ?? 1;
6262
}
6363

6464
set volume(value: number) {
6565
if (this.audio) {
6666

6767
const volumeChanged = this.volume !== value;
6868

69+
this.audio.volume = value;
70+
6971
if (volumeChanged) {
70-
if (value === 0) {
71-
this.muted = true;
72-
} else if(this.muted) {
73-
this.muted = false;
74-
} else {
75-
this.audio.volume = value;
76-
}
77-
78-
this.wf.invoke('volumeChanged', [this.volume]);
72+
this.wf.invoke('volumeChange', [value]);
7973
}
8074
}
8175
}
@@ -97,12 +91,13 @@ export class Player extends Destructable {
9791
}
9892

9993
get muted() {
100-
return this.audio?.muted ?? false;
94+
return this.audio?.volume === 0;
10195
}
10296

10397
set muted(muted: boolean) {
10498
if (!this.audio) return;
105-
if (this.muted === muted) return;
99+
100+
if (this.audio.muted === muted) return;
106101

107102
if (muted) {
108103
this.audio.mute();
@@ -139,14 +134,11 @@ export class Player extends Destructable {
139134

140135
handleEnded = () => {
141136
if (this.loop) return;
142-
this.updateCurrentTime(true);
143-
};
144-
145-
private playEnded() {
146137
this.ended = true;
138+
this.updateCurrentTime(true);
147139
this.pause();
148140
this.wf.invoke('playend');
149-
}
141+
};
150142

151143
pause() {
152144
if (this.isDestroyed || !this.playing || !this.audio) return;
@@ -191,7 +183,7 @@ export class Player extends Destructable {
191183
this.timestamp = performance.now();
192184
this.recreateSource();
193185

194-
if (!this.audio) return;
186+
if (!this.audio?.source) return;
195187

196188
this.playing = true;
197189

@@ -204,12 +196,8 @@ export class Player extends Destructable {
204196
start = clamp(this.loop.start, 0, duration);
205197
}
206198

207-
if (this.audio.el) {
208-
this.audio.el.currentTime = this.currentTime;
209-
this.audio.el.addEventListener('ended', this.handleEnded);
210-
this.audio.el.play();
211-
}
212-
199+
this.audio.source.start(0, start ?? 0, duration ?? this.duration);
200+
this.audio.source.addEventListener('ended', this.handleEnded);
213201
this.watch();
214202
}
215203

@@ -253,16 +241,16 @@ export class Player extends Destructable {
253241
private disconnectSource() {
254242
if (this.isDestroyed || !this.audio || !this.connected) return;
255243
this.connected = false;
256-
257-
if (this.audio.el) {
258-
this.audio.el.removeEventListener('ended', this.handleEnded);
259-
}
244+
this.audio.source?.removeEventListener('ended', this.handleEnded);
245+
this.audio.source?.stop(0);
260246
this.audio.disconnect();
261247
}
262248

263249
private cleanupSource() {
264250
if (this.isDestroyed || !this.audio) return;
265251
this.disconnectSource();
252+
253+
delete this.audio.source;
266254
delete this.audio;
267255
}
268256

@@ -285,25 +273,18 @@ export class Player extends Destructable {
285273
}
286274
}
287275

288-
private updateCurrentTime(forceEnd = false) {
276+
private updateCurrentTime(forceTimeToEnd?: boolean) {
289277
const now = performance.now();
290-
const tick = ((now - this.timestamp) / 1000) * this.rate;
278+
const tick = (( now - this.timestamp) / 1000) * this.rate;
291279

292280
this.timestamp = now;
293281

294282
const end = this.loop?.end ?? this.duration;
295283

296-
const newTime = forceEnd ? this.duration : clamp(this.time + tick, 0, end);
284+
const newTime = forceTimeToEnd ? this.duration : clamp(this.time + tick, 0, end);
297285

298286
this.time = newTime;
299-
300-
if (!this.loop && this.time >= this.duration - tick) {
301-
this.time = this.duration;
302-
this.wf.invoke('playing', [this.duration]);
303-
this.playEnded();
304-
} else {
305-
this.wf.invoke('playing', [this.time]);
306-
}
287+
this.wf.invoke('playing', [this.time]);
307288
}
308289

309290
private stopWatch() {

0 commit comments

Comments
 (0)