MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / tone

Function tone

apps/kimi-web/src/composables/client/useSoundNotification.ts:97–112  ·  view source on GitHub ↗
(ctx: AudioContext, freq: number, start: number, duration: number, peak: number)

Source from the content-addressed store, hash-verified

95}
96
97function tone(ctx: AudioContext, freq: number, start: number, duration: number, peak: number): void {
98 const osc = ctx.createOscillator();
99 const gain = ctx.createGain();
100 osc.type = 'sine';
101 osc.frequency.value = freq;
102 osc.connect(gain);
103 gain.connect(ctx.destination);
104 const t0 = ctx.currentTime + start;
105 // Exponential ramps can't target 0, so use a tiny floor to fade in/out
106 // without the click you get from an abrupt start/stop.
107 gain.gain.setValueAtTime(0.0001, t0);
108 gain.gain.exponentialRampToValueAtTime(peak, t0 + 0.01);
109 gain.gain.exponentialRampToValueAtTime(0.0001, t0 + duration);
110 osc.start(t0);
111 osc.stop(t0 + duration + 0.02);
112}
113
114function playChime(): void {
115 const ctx = getAudioContext();

Callers 1

playChimeFunction · 0.85

Calls 3

startMethod · 0.65
stopMethod · 0.65
connectMethod · 0.45

Tested by

no test coverage detected