vanilladocs
vanillapunch.com
API / misc/beepplayer

misc/beepplayer

절차적 비프 재생기.

Procedural beep player.

BeepPlayerextends Object

짝Counterpart: vanilla-engine BeepPlayer

절차적 비프 재생기.

  • 오디오 파일 없이 OscillatorNode + GainNode 로 UI 효과음을 합성한다. attack / sustain / release 엔벨로프로 클릭음이 나지 않게 스케줄링한다.
  • click / confirm / cancel / error / success / warning / notification 프리셋과 임의 톤 시퀀스 재생(playSequence)을 제공한다.
  • 사용:
const beepPlayer = new BeepPlayer(engine.getAudioManager());
beepPlayer.playPreset("confirm");

Procedural beep player.

  • Synthesizes UI sound effects with OscillatorNode + GainNode, without audio files. Schedules with an attack / sustain / release envelope to avoid clicks.
  • Provides click / confirm / cancel / error / success / warning / notification presets and arbitrary tone sequence playback (playSequence).
  • Usage:
const beepPlayer = new BeepPlayer(engine.getAudioManager());
beepPlayer.playPreset("confirm");
예제Example누를 때마다 프리셋 효과음 내기Play a preset sound effect on every press
import { Engine, EngineConfiguration, Scene, BeepPlayer } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const audioManager = engine.getAudioManager();
const beepPlayer = new BeepPlayer(audioManager, 0.3);

class MainScene extends Scene {
	touchPress(viewInputPosition) {
		super.touchPress(viewInputPosition);
		beepPlayer.playPreset("confirm");
	}
}

engine.run(new MainScene());
생성자constructorconstructor(audioManager, volume = 0.35)#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

audioManagerAudioManager
소리를 낼 오디오 관리자. (engine.getAudioManager())Audio manager that plays the sound. (engine.getAudioManager())
volumenumber
0 ~ 1.

짝Counterpart: vanilla-engine BeepPlayer.new

메서드methodplayTone(frequency, durationSeconds = 0.08, waveform = "sine", delaySeconds = 0, volumeScale = 1)#0.3.0 부터since 0.3.0소스source

단일 톤 재생.

Plays a single tone.

frequencynumber
주파수. (Hz)Frequency. (Hz)
durationSecondsnumber
길이. (초)Duration. (seconds)
waveformstring
"sine" | "square" | "sawtooth" | "triangle"
delaySecondsnumber
시작 지연. (초)Start delay. (seconds)
volumeScalenumber
이 톤만의 음량 배율.Volume multiplier for this tone only.

짝Counterpart: vanilla-engine BeepPlayer.play_tone

메서드methodplaySequence(toneList)#0.3.0 부터since 0.3.0소스source

톤 시퀀스 재생.

  • [{ frequency, duration, waveform?, volumeScale? }, ...] 를 차례로 이어 튼다.

Plays a tone sequence.

  • Plays [{ frequency, duration, waveform?, volumeScale? }, ...] one after another.
toneListobject[]
차례로 이어 틀 톤 목록. ({ frequency, duration, waveform?, volumeScale? }, duration 은 초)List of tones to play in sequence. ({ frequency, duration, waveform?, volumeScale? }, duration in seconds)

짝Counterpart: vanilla-engine BeepPlayer.play_sequence

예제Example도미솔 세 음을 이어 틀기Play the three notes C, E, G in sequence
import { Engine, EngineConfiguration, Scene, BeepPlayer } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const audioManager = engine.getAudioManager();
const beepPlayer = new BeepPlayer(audioManager);

class MainScene extends Scene {
	touchPress(viewInputPosition) {
		super.touchPress(viewInputPosition);
		beepPlayer.playSequence([
			{ frequency: 523, duration: 0.1 },
			{ frequency: 659, duration: 0.1, waveform: "triangle" },
			{ frequency: 784, duration: 0.2, volumeScale: 0.6 },
		]);
	}
}

engine.run(new MainScene());
메서드methodplayPreset(presetName)#0.3.0 부터since 0.3.0소스source

프리셋 재생.

Plays a preset.

presetNamestring
"click" | "confirm" | "cancel" | "error" | "success" | "warning" | "notification"

짝Counterpart: vanilla-engine BeepPlayer.play_preset

메서드methodsetVolume(volume)#0.3.0 부터since 0.3.0소스source

기본 음량 설정.

Sets the default volume.

volumenumber
0 ~ 1.

짝Counterpart: vanilla-engine BeepPlayer.set_volume

메서드methodgetVolume()#0.3.0 부터since 0.3.0소스source

기본 음량 반환.

Returns the default volume.

반환Returnsnumber 기본 음량. (0 ~ 1)Base volume. (0 ~ 1)

짝Counterpart: vanilla-engine BeepPlayer.get_volume

메서드methodsetMuted(isMuted)#0.3.0 부터since 0.3.0소스source

음소거 설정.

Sets mute.

isMutedboolean
참이면 소리를 내지 않는다.If true, plays no sound.

짝Counterpart: vanilla-engine BeepPlayer.set_muted

메서드methodisMuted()#0.3.0 부터since 0.3.0소스source

음소거 여부.

Whether muted.

반환Returnsboolean 음소거 중이면 참.True if muted.

짝Counterpart: vanilla-engine BeepPlayer.is_muted