-
Notifications
You must be signed in to change notification settings - Fork 36
/
constant-source-node.ts
49 lines (35 loc) · 2.08 KB
/
constant-source-node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { AUDIO_PARAM_STORE } from '../globals';
import { connectAudioParam } from '../helpers/connect-audio-param';
import { getNativeNode } from '../helpers/get-native-node';
import { isOwnedByContext } from '../helpers/is-owned-by-context';
import { renderAutomation } from '../helpers/render-automation';
import { IAudioParam, IConstantSourceNode, INativeConstantSourceNode } from '../interfaces';
import { TNativeAudioParam, TUnpatchedOfflineAudioContext } from '../types';
import { AudioNodeRenderer } from './audio-node';
export class ConstantSourceNodeRenderer extends AudioNodeRenderer {
private _nativeNode: null | INativeConstantSourceNode;
private _proxy: IConstantSourceNode;
constructor (proxy: IConstantSourceNode) {
super();
this._nativeNode = null;
this._proxy = proxy;
}
public async render (offlineAudioContext: TUnpatchedOfflineAudioContext): Promise<INativeConstantSourceNode> {
if (this._nativeNode !== null) {
return this._nativeNode;
}
this._nativeNode = <INativeConstantSourceNode> getNativeNode(this._proxy);
// If the initially used nativeNode was not constructed on the same OfflineAudioContext it needs to be created again.
if (!isOwnedByContext(this._nativeNode, offlineAudioContext)) {
const offsetAudioParam = <IAudioParam> (<any> this._nativeNode.offset);
// @todo TypeScript doesn't know yet about createConstantSource().
this._nativeNode = <INativeConstantSourceNode> (<any> offlineAudioContext).createConstantSource();
await renderAutomation(offlineAudioContext, offsetAudioParam, this._nativeNode.offset);
} else {
const offsetNativeAudioParam = <TNativeAudioParam> AUDIO_PARAM_STORE.get(this._proxy.offset);
await connectAudioParam(offlineAudioContext, <IAudioParam> (<any> this._nativeNode.offset), offsetNativeAudioParam);
}
await this._connectSources(offlineAudioContext, <INativeConstantSourceNode> this._nativeNode);
return <INativeConstantSourceNode> this._nativeNode;
}
}