@raucheacho/phono-web 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +41 -2
- package/assets/goul-audio.wasm +0 -0
- package/assets/goul-ptt-worklets.js +256 -0
- package/dist/announcements.d.ts +23 -0
- package/dist/audio.d.ts +79 -0
- package/dist/client.d.ts +265 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1204 -0
- package/dist/phone.d.ts +110 -0
- package/dist/react.d.ts +13 -0
- package/dist/react.js +18 -0
- package/dist/realtime.d.ts +39 -0
- package/dist/talkie.d.ts +85 -0
- package/dist/tones.d.ts +14 -0
- package/dist/types.d.ts +284 -0
- package/dist/types.js +0 -0
- package/package.json +53 -4
- package/src/announcements.ts +57 -0
- package/src/audio.ts +313 -0
- package/src/client.ts +433 -0
- package/src/index.ts +13 -0
- package/src/phone.ts +340 -0
- package/src/react.ts +34 -0
- package/src/realtime.ts +174 -0
- package/src/talkie.ts +342 -0
- package/src/tones.ts +58 -0
- package/src/types.ts +339 -0
package/src/talkie.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Le talkie dans le navigateur : un canal où l'on parle à tour de rôle.
|
|
3
|
+
*
|
|
4
|
+
* Repris de la console de dispatch de Livro (apps/dispatch/src/lib/ptt.ts),
|
|
5
|
+
* qui le fait tourner sur le terrain : le même fil que les téléphones — des
|
|
6
|
+
* trames Opus sur un sujet Konet, une voix à la fois, arbitrée par le serveur
|
|
7
|
+
* (le « floor ») — et les mêmes worklets de goul-audio pour capter, encoder,
|
|
8
|
+
* décoder et lisser la lecture. Ce fichier n'orchestre que le reste : les
|
|
9
|
+
* permissions, le canal, le floor, et l'état dont une interface a besoin.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const talkie = phono.talkie(channelId);
|
|
13
|
+
* talkie.subscribe(({ state, holder }) => render(state, holder));
|
|
14
|
+
* await talkie.start(); // on entend le canal
|
|
15
|
+
* button.onpointerdown = () => talkie.press(); // on parle
|
|
16
|
+
* button.onpointerup = () => talkie.release();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { KonetClient } from "@raucheacho/konet-js";
|
|
21
|
+
|
|
22
|
+
import type { AudioAssets, Phono } from "./client";
|
|
23
|
+
import type { ChannelAudioCredentials } from "./types";
|
|
24
|
+
|
|
25
|
+
const AUDIO_EVENT = "a";
|
|
26
|
+
/** Le tampon de lecture : six trames de 20 ms, le compromis réglé dans Goul. */
|
|
27
|
+
const TARGET_MS = 120;
|
|
28
|
+
const MAX_MS = 400;
|
|
29
|
+
const JOIN_TIMEOUT_MS = 8_000;
|
|
30
|
+
/** Une trame plus courte est un silence (DTX) : on ne la compte pas comme voix. */
|
|
31
|
+
const VOICE_MIN_BYTES = 12;
|
|
32
|
+
|
|
33
|
+
export type TalkieState =
|
|
34
|
+
| "idle"
|
|
35
|
+
| "connecting"
|
|
36
|
+
/** Canal rejoint : on entend. Le micro est une autre affaire (micReady). */
|
|
37
|
+
| "ready"
|
|
38
|
+
/** On tient le canal et on parle. */
|
|
39
|
+
| "transmitting"
|
|
40
|
+
/** Quelqu'un d'autre parle. */
|
|
41
|
+
| "listening"
|
|
42
|
+
| "denied"
|
|
43
|
+
| "error";
|
|
44
|
+
|
|
45
|
+
export interface TalkieSnapshot {
|
|
46
|
+
state: TalkieState;
|
|
47
|
+
/** L'id de l'identifiant qui tient le canal, ou null. */
|
|
48
|
+
holder: string | null;
|
|
49
|
+
/** Vrai quand la voix d'en face arrive vraiment (pas seulement le floor). */
|
|
50
|
+
remoteSpeaking: boolean;
|
|
51
|
+
/** Faux tant que le micro n'est pas accordé et branché. */
|
|
52
|
+
micReady: boolean;
|
|
53
|
+
/** Les identifiants (ids) à l'écoute du canal en ce moment, soi compris. */
|
|
54
|
+
online: string[];
|
|
55
|
+
error: string | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Listener = (snapshot: TalkieSnapshot) => void;
|
|
59
|
+
|
|
60
|
+
function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
|
|
61
|
+
return Promise.race([promise, new Promise<T>((_, reject) => setTimeout(() => reject(new Error(message)), ms))]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class Talkie {
|
|
65
|
+
private listeners = new Set<Listener>();
|
|
66
|
+
private snapshot: TalkieSnapshot = {
|
|
67
|
+
state: "idle",
|
|
68
|
+
holder: null,
|
|
69
|
+
remoteSpeaking: false,
|
|
70
|
+
micReady: false,
|
|
71
|
+
online: [],
|
|
72
|
+
error: null,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
private client: KonetClient | null = null;
|
|
76
|
+
private channel: ReturnType<KonetClient["channel"]> | null = null;
|
|
77
|
+
private context: AudioContext | null = null;
|
|
78
|
+
private micStream: MediaStream | null = null;
|
|
79
|
+
private capture: AudioWorkletNode | null = null;
|
|
80
|
+
private playback: AudioWorkletNode | null = null;
|
|
81
|
+
private wasmBytes: ArrayBuffer | null = null;
|
|
82
|
+
private speakingTimer: ReturnType<typeof setTimeout> | null = null;
|
|
83
|
+
private renewTimer: ReturnType<typeof setTimeout> | null = null;
|
|
84
|
+
private stopped = false;
|
|
85
|
+
|
|
86
|
+
constructor(
|
|
87
|
+
private readonly phono: Phono,
|
|
88
|
+
readonly channelId: string,
|
|
89
|
+
private readonly assets: AudioAssets = {}
|
|
90
|
+
) {}
|
|
91
|
+
|
|
92
|
+
subscribe(listener: Listener): () => void {
|
|
93
|
+
this.listeners.add(listener);
|
|
94
|
+
listener(this.snapshot);
|
|
95
|
+
return () => this.listeners.delete(listener);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get state(): TalkieSnapshot {
|
|
99
|
+
return this.snapshot;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Rejoint le canal et commence à écouter. Le micro n'est **pas** sur ce
|
|
104
|
+
* chemin : écouter ne demande aucune permission, et ne doit pas attendre
|
|
105
|
+
* qu'on réponde à une question du navigateur. Il est demandé au premier
|
|
106
|
+
* appui — un geste, le seul moment où le navigateur l'affiche à coup sûr —
|
|
107
|
+
* ou tout de suite s'il est déjà accordé.
|
|
108
|
+
*/
|
|
109
|
+
async start(): Promise<void> {
|
|
110
|
+
if (this.stopped) return;
|
|
111
|
+
this.emit({ state: "connecting", error: null });
|
|
112
|
+
try {
|
|
113
|
+
const creds = await this.phono.request<ChannelAudioCredentials>(
|
|
114
|
+
`/v1/channels/${encodeURIComponent(this.channelId)}/audio`,
|
|
115
|
+
{ method: "POST" }
|
|
116
|
+
);
|
|
117
|
+
await this.buildPlayback();
|
|
118
|
+
|
|
119
|
+
const client = new KonetClient(creds.url, { token: creds.token }).connect();
|
|
120
|
+
this.client = client;
|
|
121
|
+
const channel = client.channel(creds.topic);
|
|
122
|
+
this.channel = channel;
|
|
123
|
+
|
|
124
|
+
channel.on("konet:floor", (payload) => {
|
|
125
|
+
this.onFloorChanged((payload as { holder: string | null }).holder);
|
|
126
|
+
});
|
|
127
|
+
// Qui écoute : Konet envoie la liste complète à chaque changement.
|
|
128
|
+
// L'auditeur du serveur n'est pas quelqu'un.
|
|
129
|
+
channel.on("presence", (payload) => {
|
|
130
|
+
const list = Array.isArray(payload) ? (payload as { id: string }[]) : [];
|
|
131
|
+
this.emit({ online: list.map((e) => e.id).filter((id) => id && id !== "talkie-listener") });
|
|
132
|
+
});
|
|
133
|
+
channel.on(creds.event || AUDIO_EVENT, (data) => {
|
|
134
|
+
const frame = data as Uint8Array;
|
|
135
|
+
this.playback?.port.postMessage({ type: "frame", frame });
|
|
136
|
+
if (frame.length > VOICE_MIN_BYTES) this.markRemoteSpeaking();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await withTimeout(channel.subscribe(), JOIN_TIMEOUT_MS, "Le canal n'a pas répondu. Vérifiez que le temps réel est joignable.");
|
|
140
|
+
this.emit({ state: "ready", error: null });
|
|
141
|
+
// Rejoindre suit un clic : le navigateur laisse alors démarrer le son.
|
|
142
|
+
void this.context?.resume();
|
|
143
|
+
|
|
144
|
+
// Un nouvel accès avant que le jeton n'expire : on reconnecte, sans bruit.
|
|
145
|
+
const ttl = new Date(creds.expires_at).getTime() - Date.now();
|
|
146
|
+
if (ttl > 60_000) this.renewTimer = setTimeout(() => void this.reconnect(), ttl - 60_000);
|
|
147
|
+
|
|
148
|
+
void this.prepareMicIfAlreadyGranted();
|
|
149
|
+
} catch (error) {
|
|
150
|
+
this.emit({ state: "error", error: this.describe(error) });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async reconnect(): Promise<void> {
|
|
155
|
+
if (this.stopped) return;
|
|
156
|
+
this.client?.disconnect();
|
|
157
|
+
this.client = null;
|
|
158
|
+
this.channel = null;
|
|
159
|
+
this.playback?.port.postMessage({ type: "close" });
|
|
160
|
+
this.playback?.disconnect();
|
|
161
|
+
this.capture?.disconnect();
|
|
162
|
+
this.capture = null;
|
|
163
|
+
this.playback = null;
|
|
164
|
+
void this.context?.close();
|
|
165
|
+
this.context = null;
|
|
166
|
+
this.emit({ micReady: false });
|
|
167
|
+
await this.start();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private async prepareMicIfAlreadyGranted(): Promise<void> {
|
|
171
|
+
try {
|
|
172
|
+
const status = await navigator.permissions.query({ name: "microphone" as PermissionName });
|
|
173
|
+
if (status.state === "granted") await this.ensureCapture();
|
|
174
|
+
} catch {
|
|
175
|
+
// Firefox ne connaît pas « microphone » : on demandera au premier appui.
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Appuyer : prend le canal et commence à émettre. */
|
|
180
|
+
async press(): Promise<void> {
|
|
181
|
+
if (!this.channel || this.snapshot.state === "transmitting") return;
|
|
182
|
+
// Le micro avant le canal : prendre le canal sans micro le rendrait muet
|
|
183
|
+
// pour tout le monde.
|
|
184
|
+
try {
|
|
185
|
+
await this.ensureCapture();
|
|
186
|
+
} catch (error) {
|
|
187
|
+
this.emit({ state: this.isPermissionDenied(error) ? "denied" : "error", error: this.describe(error) });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
await this.channel.acquireFloor();
|
|
192
|
+
} catch {
|
|
193
|
+
// Quelqu'un parle : ce n'est pas une erreur, l'interface montre qui.
|
|
194
|
+
this.emit({ error: "Quelqu'un parle déjà." });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
await this.context?.resume();
|
|
198
|
+
const streamId = (Math.random() * 0xffffffff) >>> 0;
|
|
199
|
+
this.capture?.port.postMessage({ type: "start", streamId, bitrate: 24_000 });
|
|
200
|
+
this.emit({ state: "transmitting", error: null });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Relâcher : rend le canal. */
|
|
204
|
+
async release(): Promise<void> {
|
|
205
|
+
if (this.snapshot.state !== "transmitting") return;
|
|
206
|
+
this.capture?.port.postMessage({ type: "stop" });
|
|
207
|
+
try {
|
|
208
|
+
await this.channel?.releaseFloor();
|
|
209
|
+
} catch {
|
|
210
|
+
// Le serveur rend le canal quand la socket tombe : l'interface ne doit
|
|
211
|
+
// pas rester bloquée sur « émission ».
|
|
212
|
+
}
|
|
213
|
+
this.emit({ state: "ready" });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Quitte le canal et coupe tout. */
|
|
217
|
+
stop(): void {
|
|
218
|
+
this.stopped = true;
|
|
219
|
+
if (this.speakingTimer) clearTimeout(this.speakingTimer);
|
|
220
|
+
if (this.renewTimer) clearTimeout(this.renewTimer);
|
|
221
|
+
this.capture?.port.postMessage({ type: "stop" });
|
|
222
|
+
this.playback?.port.postMessage({ type: "close" });
|
|
223
|
+
this.capture?.disconnect();
|
|
224
|
+
this.playback?.disconnect();
|
|
225
|
+
this.micStream?.getTracks().forEach((t) => t.stop());
|
|
226
|
+
void this.context?.close();
|
|
227
|
+
this.client?.disconnect();
|
|
228
|
+
this.client = null;
|
|
229
|
+
this.channel = null;
|
|
230
|
+
this.context = null;
|
|
231
|
+
this.micStream = null;
|
|
232
|
+
this.capture = null;
|
|
233
|
+
this.playback = null;
|
|
234
|
+
this.emit({ state: "idle", holder: null, remoteSpeaking: false, online: [] });
|
|
235
|
+
this.listeners.clear();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// --- le son ---------------------------------------------------------------------
|
|
239
|
+
|
|
240
|
+
private async buildPlayback(): Promise<void> {
|
|
241
|
+
if (!window.isSecureContext) {
|
|
242
|
+
throw new Error("Le talkie demande une page sécurisée : https://, ou localhost en développement.");
|
|
243
|
+
}
|
|
244
|
+
const context = new AudioContext({ sampleRate: 48_000 });
|
|
245
|
+
if (!context.audioWorklet) {
|
|
246
|
+
void context.close();
|
|
247
|
+
throw new Error("Ce navigateur ne permet pas l'audio temps réel (AudioWorklet).");
|
|
248
|
+
}
|
|
249
|
+
this.context = context;
|
|
250
|
+
await context.audioWorklet.addModule(this.assets.workletUrl ?? "/goul-ptt-worklets.js");
|
|
251
|
+
const res = await fetch(this.assets.wasmUrl ?? "/goul-audio.wasm");
|
|
252
|
+
if (!res.ok) throw new Error("goul-audio.wasm introuvable : voir « Le cœur audio » dans le README de @raucheacho/phono-web.");
|
|
253
|
+
const bytes = await res.arrayBuffer();
|
|
254
|
+
this.wasmBytes = bytes;
|
|
255
|
+
|
|
256
|
+
const playback = new AudioWorkletNode(context, "goul-playback", {
|
|
257
|
+
numberOfInputs: 0,
|
|
258
|
+
numberOfOutputs: 1,
|
|
259
|
+
outputChannelCount: [1],
|
|
260
|
+
});
|
|
261
|
+
await this.initWorklet(playback, bytes.slice(0));
|
|
262
|
+
playback.connect(context.destination);
|
|
263
|
+
playback.port.postMessage({ type: "open", targetMs: TARGET_MS, maxMs: MAX_MS });
|
|
264
|
+
this.playback = playback;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private async ensureCapture(): Promise<void> {
|
|
268
|
+
const context = this.context;
|
|
269
|
+
const bytes = this.wasmBytes;
|
|
270
|
+
if (this.capture || !context || !bytes) return;
|
|
271
|
+
this.micStream = await navigator.mediaDevices.getUserMedia({
|
|
272
|
+
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true, channelCount: 1 },
|
|
273
|
+
});
|
|
274
|
+
const capture = new AudioWorkletNode(context, "goul-capture", {
|
|
275
|
+
numberOfInputs: 1,
|
|
276
|
+
numberOfOutputs: 0,
|
|
277
|
+
channelCount: 1,
|
|
278
|
+
});
|
|
279
|
+
await this.initWorklet(capture, bytes.slice(0));
|
|
280
|
+
capture.port.onmessage = ({ data }) => {
|
|
281
|
+
if (data.type === "frame") this.sendFrame(data.frame as Uint8Array);
|
|
282
|
+
};
|
|
283
|
+
context.createMediaStreamSource(this.micStream).connect(capture);
|
|
284
|
+
this.capture = capture;
|
|
285
|
+
this.emit({ micReady: true });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private initWorklet(node: AudioWorkletNode, bytes: ArrayBuffer): Promise<void> {
|
|
289
|
+
return new Promise((resolve, reject) => {
|
|
290
|
+
const timer = setTimeout(() => reject(new Error("Le cœur audio n'a pas démarré.")), 5_000);
|
|
291
|
+
node.port.onmessage = ({ data }) => {
|
|
292
|
+
if (data.type === "ready") {
|
|
293
|
+
clearTimeout(timer);
|
|
294
|
+
resolve();
|
|
295
|
+
} else if (data.type === "error") {
|
|
296
|
+
clearTimeout(timer);
|
|
297
|
+
reject(new Error(data.message ?? "Le cœur audio a refusé de démarrer."));
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
node.port.postMessage({ type: "init", bytes }, [bytes]);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private sendFrame(frame: Uint8Array): void {
|
|
305
|
+
try {
|
|
306
|
+
this.channel?.sendBinary(AUDIO_EVENT, frame);
|
|
307
|
+
} catch {
|
|
308
|
+
/* pas rejoint : le canal sera perdu avec la socket de toute façon */
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private markRemoteSpeaking(): void {
|
|
313
|
+
if (!this.snapshot.remoteSpeaking) this.emit({ remoteSpeaking: true });
|
|
314
|
+
if (this.speakingTimer) clearTimeout(this.speakingTimer);
|
|
315
|
+
this.speakingTimer = setTimeout(() => this.emit({ remoteSpeaking: false }), 300);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
private onFloorChanged(holder: string | null): void {
|
|
319
|
+
if (holder === null) {
|
|
320
|
+
this.playback?.port.postMessage({ type: "end" });
|
|
321
|
+
if (this.snapshot.state !== "transmitting") this.emit({ state: "ready", holder: null });
|
|
322
|
+
else this.emit({ holder: null });
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
// Notre propre prise revient aussi ici : elle ne doit pas nous rétrograder.
|
|
326
|
+
this.emit({ holder, state: this.snapshot.state === "transmitting" ? "transmitting" : "listening" });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private isPermissionDenied(error: unknown): boolean {
|
|
330
|
+
return error instanceof DOMException && error.name === "NotAllowedError";
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private describe(error: unknown): string {
|
|
334
|
+
if (this.isPermissionDenied(error)) return "Micro refusé par le navigateur.";
|
|
335
|
+
return error instanceof Error ? error.message : "Erreur inconnue.";
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private emit(patch: Partial<TalkieSnapshot>): void {
|
|
339
|
+
this.snapshot = { ...this.snapshot, ...patch };
|
|
340
|
+
this.listeners.forEach((l) => l(this.snapshot));
|
|
341
|
+
}
|
|
342
|
+
}
|
package/src/tones.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les sonneries, en WebAudio : rien à télécharger.
|
|
3
|
+
*
|
|
4
|
+
* Un navigateur ne joue pas de son tant que la page n'a pas reçu de geste.
|
|
5
|
+
* La sonnerie d'un appel entrant peut donc rester muette ; `titleAlert` fait
|
|
6
|
+
* clignoter le titre de l'onglet, qui se voit toujours.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type Stop = () => void;
|
|
10
|
+
|
|
11
|
+
/** Deux bips toutes les deux secondes. */
|
|
12
|
+
export function ringtone(): Stop {
|
|
13
|
+
return loop(2000, (ctx) => {
|
|
14
|
+
beep(ctx, 0, 0.35, 0.08);
|
|
15
|
+
beep(ctx, 0.5, 0.35, 0.08);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** La tonalité de retour : 440 Hz, 1,5 s toutes les 5 s, comme en France. */
|
|
20
|
+
export function ringback(): Stop {
|
|
21
|
+
return loop(5000, (ctx) => beep(ctx, 0, 1.5, 0.06));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function titleAlert(text: string): Stop {
|
|
25
|
+
if (typeof document === "undefined") return () => {};
|
|
26
|
+
const original = document.title;
|
|
27
|
+
let on = false;
|
|
28
|
+
const t = setInterval(() => {
|
|
29
|
+
on = !on;
|
|
30
|
+
document.title = on ? text : original;
|
|
31
|
+
}, 1000);
|
|
32
|
+
return () => {
|
|
33
|
+
clearInterval(t);
|
|
34
|
+
document.title = original;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function loop(everyMs: number, play: (ctx: AudioContext) => void): Stop {
|
|
39
|
+
if (typeof AudioContext === "undefined") return () => {};
|
|
40
|
+
const ctx = new AudioContext();
|
|
41
|
+
play(ctx);
|
|
42
|
+
const t = setInterval(() => play(ctx), everyMs);
|
|
43
|
+
return () => {
|
|
44
|
+
clearInterval(t);
|
|
45
|
+
void ctx.close();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function beep(ctx: AudioContext, at: number, length: number, volume: number) {
|
|
50
|
+
const osc = ctx.createOscillator();
|
|
51
|
+
const gain = ctx.createGain();
|
|
52
|
+
osc.frequency.value = 440;
|
|
53
|
+
gain.gain.setValueAtTime(volume, ctx.currentTime + at);
|
|
54
|
+
gain.gain.setValueAtTime(0, ctx.currentTime + at + length);
|
|
55
|
+
osc.connect(gain).connect(ctx.destination);
|
|
56
|
+
osc.start(ctx.currentTime + at);
|
|
57
|
+
osc.stop(ctx.currentTime + at + length + 0.05);
|
|
58
|
+
}
|