playOscillators

View sourceplayOscillators(world: World): void

Drives AudioOscillator components from timer playback state.

AudioPlugin registers this exact function in AppSchedule.Update. Each update looks up AudioGraph and queries only entities that have both an AudioOscillator and a Timer using Query#each. No audio asset lookup is performed because the native oscillator is created from the component’s frequency, detune, and waveform settings.

When an oscillator has no graph slot, the system reserves an empty slot and connects it to attach or the graph root. It resets the timer while preserving its current elapsed position so the slot can be filled on a later update. When the timer reports a playback change, the system maps AudioOscillatorType to the corresponding Web Audio waveform (SawTooth → sawtooth, Sine → sine, Square → square, or Triangle → triangle), creates an OscillatorNode, starts it immediately, and replaces the slot through AudioGraph#update. An unknown numeric waveform throws before a native node is created.

A paused timer clears the native oscillator. A completed timer is cleared before playback-change handling; repeating timers do not report completion and can create the next oscillator when playback is requested again. When no playback change is reported, the current native source is left alone. Replacing or clearing a slot delegates stopping and disconnection of the previous source to AudioGraph#update; the reserved slot and graph edge remain available for reuse.

Examples

import { AudioOscillator, AudioOscillatorType } from '@wimaengine/audio'
import { Timer, TimerMode } from '@wimaengine/time'

// AudioPlugin registers playOscillators in the Update schedule.
function spawnSquareTone(world) {
  return world.spawn([
    new AudioOscillator({ type: AudioOscillatorType.Square, frequency: 220 }),
    new Timer({ duration: 1, mode: TimerMode.Once })
  ])
}

Parameters

NameDescriptionDefault
world

World containing the audio graph and oscillator entities.

—