vanilladocs
vanillapunch.com
API / core/soundsystem

core/soundsystem

소리. (배경음악과 효과음) 엔진의 AudioManager(공유 AudioContext)와 AudioAsset(MP3)을 쓴다. 받은 소리 버퍼를 Web Audio 로 튼다. (소리를 합성하지 않고 파일만 튼다) 소리 표를 넘긴다. 줄마다 { id, path 나 paths, volume, minimumInterval, isMusic, maximumVoices, pitchVariation, playSeconds, fadeOutSeconds } 이다. volume: 소리마다의 크기. (0 ~ 1, 없으면 1) minimumInterval: 같은 소리를 다시 낼 수 있는 간격. (초, 한꺼번에 몰려 시끄럽지 않게) paths: 같은 소리를 여러 번 녹음한 무리. 낼 때마다 하나를 고르고 바로 앞과 같은 것은 고르지 않는다. (하나면 path) maximumVoices: 같은 소리가 한꺼번에 날 수 있는 수. (넘으면 가장 오래된 것을 끊음, 없으면 효과음 전체의 수까지) pitchVariation: 낼 때마다 음 높이를 흔드는 비. (0.05 면 ±5%, 없으면 0) playSeconds, fadeOutSeconds: 효과음을 앞의 playSeconds 초만 틀고 fadeOutSeconds 초 동안 줄여 끈다. (긴 파일, 없거나 0 이면 끝까지) loadType: 읽기 방식. (AudioLoadType, 없으면 배경음악은 streaming, 효과음은 decompressOnLoad, 효과음은 겹쳐 트므로 통째로 풀어야 난다) 크기: 배경음악 = 설정의 음악 크기 × 음악의 비(멈춤 창의 반 크기 등) × 소리의 크기, 효과음 = 설정의 효과음 크기 × 소리의 크기 × 부를 때의 크기(거리에 따른 줄임 등). 배경음악은 겹쳐 바꿀 수 있고(fadeSeconds), 멈췄던 자리를 소리마다 기억해 이어 틀 수 있다. (isResumed) 음소거는 설정한 크기보다 먼저이다. 아래 가운데 하나라도 맞으면 설정과 상관없이 소리가 나지 않는다.

  • 플랫폼의 음소거. (setExternalMuteProvider 로 준 함수, 플랫폼 SDK 의 음소거 설정, 보상형 광고를 보이는 동안 등)
  • 사용자의 음소거 단추. (setUserMuted)
  • 페이지가 가려짐. (다른 탭, 앱 전환)
  • 터치가 주된 기기에서 창이 포커스를 잃음. (blur, 앱을 내리기 시작할 때) 아이폰은 페이지가 가려졌다는 알림이 앱이 내려간 뒤에 와서, 그때는 오디오가 멈추지 못한 채 얼어 마지막 소리 조각이 되풀이된다. 창이 포커스를 잃는 알림은 그보다 먼저 온다. 데스크탑은 캔버스 바깥(바깥 페이지)을 누를 때도 포커스를 잃으므로 따르지 않는다.

플랫폼의 음소거는 매 프레임(update) 읽고, 페이지가 가려지는 것은 그 순간에 적용한다. (가려지면 프레임이 멈춘다) 음소거인 동안은 AudioContext 도 멈춘다. (suspend, 풀리면 resume) 아이폰은 돌던 AudioContext 를 앱 전환이나 전면 광고가 가로채면 돌아와서 깨워도 소리가 나지 않는다. 그 전에 스스로 멈춰 두면 돌아올 때 다시 난다. 풀린 뒤에도 AudioContext 가 돌지 않으면 돌 때까지 잠깐마다 다시 깨워 본다. (아이폰은 앱으로 돌아온 순간의 깨우기를 듣지 않는 일이 있음) 허락하면(setAutoplayAllowedProvider, 주지 않으면 허락) 누르기 전에도 한 번 깨워 본다. 막히면 아래처럼 첫 누름에 켜진다. 브라우저는 사람이 처음 누르기 전에는 소리를 내지 못하게 한다. 엔진이 첫 누름에 AudioContext 를 만들고 깨우므로, 그 뒤에 소리의 길(음악과 효과음의 버스, AudioBus)을 만들고, AudioContext 가 돌고 있을 때만 소리를 낸다. (멈춘 동안 부른 소리가 깨어날 때 한꺼번에 나지 않게) 버스는 getMusicBus, getEffectBus 로 꺼낸다. 버스로 만든 플레이어(AudioBus.createAudioPlayer)도 설정 크기와 음소거를 따른다. 설정 크기는 버스의 GainNode 에 직접 건다. 그래서 버스의 setVolume, mute 로 건 값은 SoundSystem 이 크기를 다시 걸 때까지 간다. 소리 파일은 놀이를 막지 않게 뒤에서 받는다. 아직 못 받았거나 못 받은 소리는 나지 않을 뿐이다.

Sound. (background music and sound effects) Uses the engine's AudioManager (shared AudioContext) and AudioAsset (MP3). Plays downloaded sound buffers with Web Audio. (does not synthesize sound, only plays files) Takes a sound table. Each row is { id, path or paths, volume, minimumInterval, isMusic, maximumVoices, pitchVariation, playSeconds, fadeOutSeconds }. volume: per-sound volume. (0 ~ 1, 1 if absent) minimumInterval: interval before the same sound can play again. (seconds, so they do not pile up and get noisy) paths: a group of multiple recordings of the same sound. Picks one each time it plays, never the same as the one just before. (path if only one) maximumVoices: number of instances of the same sound that can play at once. (beyond that the oldest is cut off, if absent up to the total number of sound effects) pitchVariation: ratio by which the pitch varies on each play. (0.05 means ±5%, 0 if absent) playSeconds, fadeOutSeconds: plays only the first playSeconds seconds of a sound effect and fades it out over fadeOutSeconds seconds. (long files, to the end if absent or 0) loadType: load type. (AudioLoadType, background music uses streaming and sound effects use decompressOnLoad if absent, sound effects overlap so they must be fully decompressed to play) Volume: background music = music volume setting × music ratio (half volume for the pause window, etc.) × sound volume, sound effect = sound effect volume setting × sound volume × volume at call time (attenuation by distance, etc.). Background music can be crossfaded (fadeSeconds), and the stopped position is remembered per sound so it can resume from there. (isResumed) Mute takes precedence over the volume setting. If any one of the following applies, no sound plays regardless of the settings.

  • Platform mute. (the function given with setExternalMuteProvider, the platform SDK's mute setting, while a rewarded ad is shown, etc.)
  • The user's mute button. (setUserMuted)
  • Page hidden. (another tab, app switch)
  • The window loses focus on a touch-primary device. (blur, when the app starts going to the background) On iPhone the page-hidden notification arrives after the app has gone to the background, by which time audio freezes without stopping and the last sound chunk repeats. The window focus-loss notification arrives before that. On desktop, clicking outside the canvas (the outer page) also loses focus, so it is not followed there.

Platform mute is read every frame (update), and page hiding is applied at that moment. (frames stop when hidden) While muted, the AudioContext is also stopped. (suspend, resume when unmuted) On iPhone, if an app switch or interstitial ad takes over a running AudioContext, no sound plays even when it is woken on return. If it is stopped on its own beforehand, sound plays again on return. If the AudioContext is still not running after unmuting, it tries to wake it at short intervals until it runs. (iPhone sometimes ignores the wake at the moment of returning to the app) If allowed (setAutoplayAllowedProvider, allowed if not given), it tries to wake once even before a press. If blocked, it turns on at the first press as below. Browsers do not allow sound before the person first presses. Since the engine creates and wakes the AudioContext on the first press, the sound paths (music and sound effect buses, AudioBus) are created after that, and sound plays only while the AudioContext is running. (so sounds requested while stopped do not all play at once on wake) Buses are retrieved with getMusicBus and getEffectBus. Players made from a bus (AudioBus.createAudioPlayer) also follow the volume setting and mute. The volume setting is applied directly to the bus's GainNode. So values set with the bus's setVolume and mute last only until SoundSystem applies the volume again. Sound files are downloaded in the background so they do not block play. Sounds not yet downloaded or that failed to download simply do not play.

SoundSystem

짝Counterpart: vanilla-engine SoundSystem

소리. (배경음악과 효과음) 엔진의 AudioManager(공유 AudioContext)와 AudioAsset(MP3)을 쓴다. 받은 소리 버퍼를 Web Audio 로 튼다. (소리를 합성하지 않고 파일만 튼다) 소리 표를 넘긴다. 줄마다 { id, path 나 paths, volume, minimumInterval, isMusic, maximumVoices, pitchVariation, playSeconds, fadeOutSeconds } 이다. volume: 소리마다의 크기. (0 ~ 1, 없으면 1) minimumInterval: 같은 소리를 다시 낼 수 있는 간격. (초, 한꺼번에 몰려 시끄럽지 않게) paths: 같은 소리를 여러 번 녹음한 무리. 낼 때마다 하나를 고르고 바로 앞과 같은 것은 고르지 않는다. (하나면 path) maximumVoices: 같은 소리가 한꺼번에 날 수 있는 수. (넘으면 가장 오래된 것을 끊음, 없으면 효과음 전체의 수까지) pitchVariation: 낼 때마다 음 높이를 흔드는 비. (0.05 면 ±5%, 없으면 0) playSeconds, fadeOutSeconds: 효과음을 앞의 playSeconds 초만 틀고 fadeOutSeconds 초 동안 줄여 끈다. (긴 파일, 없거나 0 이면 끝까지) loadType: 읽기 방식. (AudioLoadType, 없으면 배경음악은 streaming, 효과음은 decompressOnLoad, 효과음은 겹쳐 트므로 통째로 풀어야 난다) 크기: 배경음악 = 설정의 음악 크기 × 음악의 비(멈춤 창의 반 크기 등) × 소리의 크기, 효과음 = 설정의 효과음 크기 × 소리의 크기 × 부를 때의 크기(거리에 따른 줄임 등). 배경음악은 겹쳐 바꿀 수 있고(fadeSeconds), 멈췄던 자리를 소리마다 기억해 이어 틀 수 있다. (isResumed) 음소거는 설정한 크기보다 먼저이다. 아래 가운데 하나라도 맞으면 설정과 상관없이 소리가 나지 않는다.

  • 플랫폼의 음소거. (setExternalMuteProvider 로 준 함수, 플랫폼 SDK 의 음소거 설정, 보상형 광고를 보이는 동안 등)
  • 사용자의 음소거 단추. (setUserMuted)
  • 페이지가 가려짐. (다른 탭, 앱 전환)
  • 터치가 주된 기기에서 창이 포커스를 잃음. (blur, 앱을 내리기 시작할 때) 아이폰은 페이지가 가려졌다는 알림이 앱이 내려간 뒤에 와서, 그때는 오디오가 멈추지 못한 채 얼어 마지막 소리 조각이 되풀이된다. 창이 포커스를 잃는 알림은 그보다 먼저 온다. 데스크탑은 캔버스 바깥(바깥 페이지)을 누를 때도 포커스를 잃으므로 따르지 않는다.

플랫폼의 음소거는 매 프레임(update) 읽고, 페이지가 가려지는 것은 그 순간에 적용한다. (가려지면 프레임이 멈춘다) 음소거인 동안은 AudioContext 도 멈춘다. (suspend, 풀리면 resume) 아이폰은 돌던 AudioContext 를 앱 전환이나 전면 광고가 가로채면 돌아와서 깨워도 소리가 나지 않는다. 그 전에 스스로 멈춰 두면 돌아올 때 다시 난다. 풀린 뒤에도 AudioContext 가 돌지 않으면 돌 때까지 잠깐마다 다시 깨워 본다. (아이폰은 앱으로 돌아온 순간의 깨우기를 듣지 않는 일이 있음) 허락하면(setAutoplayAllowedProvider, 주지 않으면 허락) 누르기 전에도 한 번 깨워 본다. 막히면 아래처럼 첫 누름에 켜진다. 브라우저는 사람이 처음 누르기 전에는 소리를 내지 못하게 한다. 엔진이 첫 누름에 AudioContext 를 만들고 깨우므로, 그 뒤에 소리의 길(음악과 효과음의 버스, AudioBus)을 만들고, AudioContext 가 돌고 있을 때만 소리를 낸다. (멈춘 동안 부른 소리가 깨어날 때 한꺼번에 나지 않게) 버스는 getMusicBus, getEffectBus 로 꺼낸다. 버스로 만든 플레이어(AudioBus.createAudioPlayer)도 설정 크기와 음소거를 따른다. 설정 크기는 버스의 GainNode 에 직접 건다. 그래서 버스의 setVolume, mute 로 건 값은 SoundSystem 이 크기를 다시 걸 때까지 간다. 소리 파일은 놀이를 막지 않게 뒤에서 받는다. 아직 못 받았거나 못 받은 소리는 나지 않을 뿐이다.

Sound. (background music and sound effects) Uses the engine's AudioManager (shared AudioContext) and AudioAsset (MP3). Plays downloaded sound buffers with Web Audio. (does not synthesize sound, only plays files) Takes a sound table. Each row is { id, path or paths, volume, minimumInterval, isMusic, maximumVoices, pitchVariation, playSeconds, fadeOutSeconds }. volume: per-sound volume. (0 ~ 1, 1 if absent) minimumInterval: interval before the same sound can play again. (seconds, so they do not pile up and get noisy) paths: a group of multiple recordings of the same sound. Picks one each time it plays, never the same as the one just before. (path if only one) maximumVoices: number of instances of the same sound that can play at once. (beyond that the oldest is cut off, if absent up to the total number of sound effects) pitchVariation: ratio by which the pitch varies on each play. (0.05 means ±5%, 0 if absent) playSeconds, fadeOutSeconds: plays only the first playSeconds seconds of a sound effect and fades it out over fadeOutSeconds seconds. (long files, to the end if absent or 0) loadType: load type. (AudioLoadType, background music uses streaming and sound effects use decompressOnLoad if absent, sound effects overlap so they must be fully decompressed to play) Volume: background music = music volume setting × music ratio (half volume for the pause window, etc.) × sound volume, sound effect = sound effect volume setting × sound volume × volume at call time (attenuation by distance, etc.). Background music can be crossfaded (fadeSeconds), and the stopped position is remembered per sound so it can resume from there. (isResumed) Mute takes precedence over the volume setting. If any one of the following applies, no sound plays regardless of the settings.

  • Platform mute. (the function given with setExternalMuteProvider, the platform SDK's mute setting, while a rewarded ad is shown, etc.)
  • The user's mute button. (setUserMuted)
  • Page hidden. (another tab, app switch)
  • The window loses focus on a touch-primary device. (blur, when the app starts going to the background) On iPhone the page-hidden notification arrives after the app has gone to the background, by which time audio freezes without stopping and the last sound chunk repeats. The window focus-loss notification arrives before that. On desktop, clicking outside the canvas (the outer page) also loses focus, so it is not followed there.

Platform mute is read every frame (update), and page hiding is applied at that moment. (frames stop when hidden) While muted, the AudioContext is also stopped. (suspend, resume when unmuted) On iPhone, if an app switch or interstitial ad takes over a running AudioContext, no sound plays even when it is woken on return. If it is stopped on its own beforehand, sound plays again on return. If the AudioContext is still not running after unmuting, it tries to wake it at short intervals until it runs. (iPhone sometimes ignores the wake at the moment of returning to the app) If allowed (setAutoplayAllowedProvider, allowed if not given), it tries to wake once even before a press. If blocked, it turns on at the first press as below. Browsers do not allow sound before the person first presses. Since the engine creates and wakes the AudioContext on the first press, the sound paths (music and sound effect buses, AudioBus) are created after that, and sound plays only while the AudioContext is running. (so sounds requested while stopped do not all play at once on wake) Buses are retrieved with getMusicBus and getEffectBus. Players made from a bus (AudioBus.createAudioPlayer) also follow the volume setting and mute. The volume setting is applied directly to the bus's GainNode. So values set with the bus's setVolume and mute last only until SoundSystem applies the volume again. Sound files are downloaded in the background so they do not block play. Sounds not yet downloaded or that failed to download simply do not play.

예제Example소리 표로 효과음과 배경음악 틀기Play sound effects and background music from a sound table
import { Engine, EngineConfiguration, Scene, SoundSystem, setSoundSystem, readSoundSystem } from "./build/vanilla.js";

class MainScene extends Scene {
	tick(timeDelta) {
		super.tick(timeDelta);
		const soundSystem = readSoundSystem();
		if (soundSystem !== null) {
			soundSystem.update();
		}
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const audioManager = engine.getAudioManager();
const soundSystem = new SoundSystem(audioManager, [
	{ id: "beep", path: "examples/assets/beep.wav", volume: 1, minimumInterval: 0.05, maximumVoices: 4, pitchVariation: 0.05 },
	{ id: "music", path: "examples/assets/beep.wav", volume: 0.6, isMusic: true },
]);
setSoundSystem(soundSystem);
soundSystem.setSoundEffectVolume(0.8);
soundSystem.setMusicVolume(0.5);
await soundSystem.loadSounds();
soundSystem.playMusic("music", 0.5);
soundSystem.playEffect("beep", 0.5, -0.3);
console.log(soundSystem.getMusicId(), soundSystem.getEffectVoiceCount());
engine.run(new MainScene());
생성자constructorconstructor(audioManager, soundTable)#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

audioManagerobject
엔진의 AudioManager (engine.getAudioManager())The engine's AudioManager (engine.getAudioManager())
soundTableobject[]
[{ id, path 나 paths, volume, minimumInterval, isMusic, maximumVoices, pitchVariation, playSeconds, fadeOutSeconds }][{ id, path or paths, volume, minimumInterval, isMusic, maximumVoices, pitchVariation, playSeconds, fadeOutSeconds }]

짝Counterpart: vanilla-engine SoundSystem.new

메서드methodaddSounds(soundTable)#0.4.0 부터since 0.4.0소스source

소리 표의 줄 더하기. (같은 id 는 바꿈, 받기는 loadSounds 가 함)

Adds rows to the sound table. (same id replaces, downloading is done by loadSounds)

soundTableobject[]
소리 표의 줄 목록. (생성자의 soundTable 과 같은 꼴)List of sound table rows. (same form as the constructor's soundTable)

짝Counterpart: vanilla-engine SoundSystem.add_sounds

메서드methodaddSoundAsset(soundId, audioAsset)#0.4.0 부터since 0.4.0소스source

소리 애셋 직접 더하기. (메모리에서 지은 소리처럼 파일로 받지 않는 것, 같은 id 의 녹음 무리에 덧붙인다)

  • 크기와 간격은 소리 표(addSounds)의 같은 id 줄을 따른다. (줄이 없으면 내지 않는다) 받기(loadSounds)는 이 id 를 다시 받지 않는다.

Adds a sound asset directly. (for sounds not downloaded from a file, such as sounds built in memory, appended to the recording group of the same id)

  • Volume and interval follow the row of the same id in the sound table (addSounds). (does not play if there is no row) Downloading (loadSounds) does not download this id again.
soundIdstring
소리 표의 id.Sound table id.
audioAssetAudioAsset
읽어 둔 오디오 애셋. (그 id 의 녹음 무리 끝에 붙인다)Audio asset already loaded. (appended to the end of that id's take group)

짝Counterpart: vanilla-engine SoundSystem.add_sound_asset

예제Example파일로 받지 않은 소리를 소리 표에 걸기Hook a sound not fetched from a file into the sound table
import { Engine, EngineConfiguration, AudioAsset, SoundSystem } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const audioManager = engine.getAudioManager();
const soundSystem = new SoundSystem(audioManager, []);
const response = await fetch("examples/assets/beep.wav");
const bytes = await response.arrayBuffer();
const audioAsset = new AudioAsset();
await audioAsset.loadFromBytes(bytes);
soundSystem.addSounds([{ id: "generated", volume: 1 }]);
soundSystem.addSoundAsset("generated", audioAsset);
soundSystem.update();
soundSystem.playEffect("generated");
메서드methodsetExternalMuteProvider(externalMuteProvider)#0.4.0 부터since 0.4.0소스source

바깥의 음소거를 읽는 함수 설정. (플랫폼 SDK 의 음소거, 보상형 광고를 보이는 동안 등, 매 프레임 읽는다, null 이면 없음)

Sets the function that reads external mute. (platform SDK mute, while a rewarded ad is shown, etc., read every frame, null for none)

externalMuteProviderfunction(): boolean | null
참을 돌려주면 음소거하는 함수. (null 이면 없음)Function that mutes when it returns true. (null if none)

짝Counterpart: vanilla-engine SoundSystem.set_external_mute_provider

예제Example광고를 보이는 동안 소리 끄기Mute sound while an ad is showing
import { Engine, EngineConfiguration, SoundSystem } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const audioManager = engine.getAudioManager();
const soundSystem = new SoundSystem(audioManager, []);
let isAdvertisementShowing = false;
soundSystem.setExternalMuteProvider(() => {
	return isAdvertisementShowing;
});
isAdvertisementShowing = true;
soundSystem.update();
console.log(soundSystem.readMuted());
메서드methodgetExternalMuteProvider()#0.4.0 부터since 0.4.0소스source

바깥의 음소거를 읽는 함수 반환.

Returns the function that reads external mute.

반환Returnsfunction(): boolean | null 바깥의 음소거를 읽는 함수. (없으면 null)Function that reads the external mute. (null if none)

짝Counterpart: vanilla-engine SoundSystem.get_external_mute_provider

메서드methodsetAutoplayAllowedProvider(autoplayAllowedProvider)#0.4.0 부터since 0.4.0소스source

누르기 전에 깨워 봐도 되는지 읽는 함수 설정. (웹뷰가 막는 플랫폼이면 false 를 돌려주는 함수, null 이면 허락)

Sets the function that reads whether waking before a press is allowed. (a function returning false on platforms where the webview blocks it, null means allowed)

autoplayAllowedProviderfunction(): boolean | null
누르기 전에 깨워 봐도 되면 참을 돌려주는 함수. (null 이면 허락)Function that returns true if waking before the first press is allowed. (allowed if null)

짝Counterpart: vanilla-engine SoundSystem.set_autoplay_allowed_provider

메서드methodgetAutoplayAllowedProvider()#0.4.0 부터since 0.4.0소스source

누르기 전에 깨워 봐도 되는지 읽는 함수 반환.

Returns the function that reads whether waking before a press is allowed.

반환Returnsfunction(): boolean | null 누르기 전에 깨워 봐도 되는지 읽는 함수. (없으면 null)Function that reads whether waking before the first press is allowed. (null if none)

짝Counterpart: vanilla-engine SoundSystem.get_autoplay_allowed_provider

메서드methodgetAudioManager()#0.4.0 부터since 0.4.0소스source

엔진의 AudioManager 반환. (생성자에 넘긴 것)

Returns the engine's AudioManager. (the one passed to the constructor)

반환Returnsobject 엔진의 AudioManager.The engine's AudioManager.

짝Counterpart: vanilla-engine SoundSystem.get_audio_manager

메서드methodgetMusicBus()#0.4.0 부터since 0.4.0소스source

배경음악과 효과음의 버스. (첫 누름 전에는 null)

Background music and sound effect buses. (null before the first press)

반환ReturnsAudioBus | null 배경음악의 버스. (첫 누름 전에는 null)Background music bus. (null before the first press)

짝Counterpart: vanilla-engine SoundSystem.get_music_bus

메서드methodgetEffectBus()#0.4.0 부터since 0.4.0소스source

효과음의 버스. (첫 누름 전에는 null)

Sound effect bus. (null before the first press)

반환ReturnsAudioBus | null 효과음의 버스. (첫 누름 전에는 null)Sound effect bus. (null before the first press)

짝Counterpart: vanilla-engine SoundSystem.get_effect_bus

메서드methodgetMusicId()#0.4.0 부터since 0.4.0소스source

틀어 달라고 한 배경음악. (없으면 "")

Background music requested to play. ("" if none)

반환Returnsstring 틀어 달라고 한 배경음악 id. (없으면 "")Requested background music id. ("" if none)

짝Counterpart: vanilla-engine SoundSystem.get_music_id

메서드methodgetMusicVolume()#0.4.0 부터since 0.4.0소스source

설정의 음악 크기.

Music volume setting.

반환Returnsnumber 음악 크기. (0 ~ 1, 기본 1)Music volume. (0 ~ 1, default 1)

짝Counterpart: vanilla-engine SoundSystem.get_music_volume

메서드methodgetMusicScale()#0.4.0 부터since 0.4.0소스source

음악의 비. (멈춤 창의 반 크기 등)

Music ratio. (half volume for the pause window, etc.)

반환Returnsnumber 음악의 비. (0 ~ 1, 기본 1)Music scale. (0 ~ 1, default 1)

짝Counterpart: vanilla-engine SoundSystem.get_music_scale

메서드methodgetSoundEffectVolume()#0.4.0 부터since 0.4.0소스source

설정의 효과음 크기.

Sound effect volume setting.

반환Returnsnumber 효과음 크기. (0 ~ 1, 기본 1)Sound effect volume. (0 ~ 1, default 1)

짝Counterpart: vanilla-engine SoundSystem.get_sound_effect_volume

메서드methodisUserMuted()#0.4.0 부터since 0.4.0소스source

사용자의 음소거 단추를 눌러 두었는지.

Whether the user's mute button is pressed.

반환Returnsboolean 사용자가 음소거했으면 참.True if the user muted.

짝Counterpart: vanilla-engine SoundSystem.is_user_muted

메서드methodisPageHidden()#0.4.0 부터since 0.4.0소스source

페이지가 가려져 있는지.

Whether the page is hidden.

반환Returnsboolean 페이지가 가려져 있으면 참.True if the page is hidden.

짝Counterpart: vanilla-engine SoundSystem.is_page_hidden

메서드methodisBlurMuteEnabled()#0.4.0 부터since 0.4.0소스source

창이 포커스를 잃으면 음소거하는지. (터치가 주된 기기)

Whether to mute when the window loses focus. (touch-primary devices)

반환Returnsboolean 창이 포커스를 잃으면 음소거하는 기기면 참. (pointer: coarse)True on a device that mutes when the window loses focus. (pointer: coarse)

짝Counterpart: vanilla-engine SoundSystem.is_blur_mute_enabled

메서드methodisWindowBlurred()#0.4.0 부터since 0.4.0소스source

창이 포커스를 잃었는지. (음소거하는 기기에서만 true)

Whether the window has lost focus. (true only on devices that mute)

반환Returnsboolean 창이 포커스를 잃었으면 참.True if the window lost focus.

짝Counterpart: vanilla-engine SoundSystem.is_window_blurred

메서드methodisContextPaused()#0.4.0 부터since 0.4.0소스source

음소거로 AudioContext 를 멈춰 두었는지.

Whether the AudioContext has been stopped due to mute.

반환Returnsboolean 음소거로 AudioContext 를 멈춰 두었으면 참.True if the AudioContext was suspended for muting.

짝Counterpart: vanilla-engine SoundSystem.is_context_paused

메서드methodgetLastContextResumeTime()#0.4.0 부터since 0.4.0소스source

마지막으로 다시 깨워 본 때. (초)

Last time a wake was attempted. (seconds)

반환Returnsnumber 마지막으로 다시 깨워 본 때. (초, performance.now 기준, 아직 없으면 음의 무한대)Last time a wake was retried. (seconds, based on performance.now, negative infinity if never)

짝Counterpart: vanilla-engine SoundSystem.get_last_context_resume_time

메서드methodreadMuted()#0.4.0 부터since 0.4.0소스source

지금 음소거여야 하는지. (플랫폼의 음소거, 사용자의 음소거 단추, 페이지가 가려짐, 창이 포커스를 잃음, 설정한 크기보다 먼저이다)

Whether it should be muted now. (platform mute, the user's mute button, page hidden, window lost focus, takes precedence over the volume setting)

반환Returnsboolean 음소거여야 하면 참.True if it should be muted.

짝Counterpart: vanilla-engine SoundSystem.read_muted

메서드methodisContextRunning()#0.4.0 부터since 0.4.0소스source

AudioContext 가 돌고 있는지. (돌지 않으면 소리를 내지 않는다)

Whether the AudioContext is running. (no sound plays if it is not)

반환Returnsboolean AudioContext 가 있고 "running" 이면 참.True if there is an AudioContext and it is "running".

짝Counterpart: vanilla-engine SoundSystem.is_context_running

메서드methodasync loadSounds()#0.4.0 부터since 0.4.0소스source

소리 받기. (효과음을 먼저 함께 받고, 큰 배경음악을 나중에 받는다, 못 받은 소리는 건너뜁다, 이미 받은 것은 다시 받지 않음)

Downloads sounds. (sound effects first, together, large background music later, skips sounds that fail, does not redownload ones already downloaded)

짝Counterpart: vanilla-engine SoundSystem.load_sounds

메서드methodasync loadSound(soundRow)#0.4.0 부터since 0.4.0소스source

소리 하나 받기. (무리면 모두, 못 받은 것은 null 로 두고 건너뜀)

Downloads one sound. (all of a group, leaves failures as null and skips them)

soundRowobject
소리 표의 줄.Sound table row.

짝Counterpart: vanilla-engine SoundSystem.load_sound

메서드methodsetMusicVolume(volume)#0.4.0 부터since 0.4.0소스source

설정의 음악 크기. (0 ~ 1)

Music volume setting. (0 ~ 1)

volumenumber
음악 크기. (0 ~ 1 로 자르고, 숫자가 아니면 0)Music volume. (clamped to 0 ~ 1, 0 if not a number)

짝Counterpart: vanilla-engine SoundSystem.set_music_volume

메서드methodsetMusicScale(scale)#0.4.0 부터since 0.4.0소스source

음악의 비. (0 ~ 1, 멈춤 창이 떠 있는 동안 반 크기처럼 설정과 따로 줄일 때)

Music ratio. (0 ~ 1, to lower it separately from the setting, such as half volume while the pause window is up)

scalenumber
음악의 비. (0 ~ 1 로 자르고, 숫자가 아니면 0)Music scale. (clamped to 0 ~ 1, 0 if not a number)

짝Counterpart: vanilla-engine SoundSystem.set_music_scale

메서드methodsetSoundEffectVolume(volume)#0.4.0 부터since 0.4.0소스source

설정의 효과음 크기. (0 ~ 1)

Sound effect volume setting. (0 ~ 1)

volumenumber
효과음 크기. (0 ~ 1 로 자르고, 숫자가 아니면 0)Sound effect volume. (clamped to 0 ~ 1, 0 if not a number)

짝Counterpart: vanilla-engine SoundSystem.set_sound_effect_volume

메서드methodsetUserMuted(isMuted)#0.4.0 부터since 0.4.0소스source

사용자의 음소거 단추. (음악과 효과음을 한꺼번에)

The user's mute button. (music and sound effects at once)

isMutedboolean
참이면 음소거. (true 가 아닌 값은 거짓으로 친다)True to mute. (values other than true count as false)

짝Counterpart: vanilla-engine SoundSystem.set_user_muted

메서드methodplayMusic(soundId, fadeSeconds = 0, isResumed = false)#0.4.0 부터since 0.4.0소스source

배경음악 틀기. (반복한다, "" 이면 끈다, 받기 전이거나 첫 누름 전이면 그때 튼다)

  • fadeSeconds 동안 앞 음악은 줄고 새 음악은 0 에서 오른다. (0 이면 바로)
  • isResumed 면 그 음악을 멈췄던 자리에서 잇는다. (아니면 처음부터)

Plays background music. (loops, "" stops it, if before downloading or before the first press it plays then)

  • Over fadeSeconds the previous music fades down and the new music rises from 0. (immediately if 0)
  • If isResumed, resumes that music from where it stopped. (otherwise from the start)
soundIdstring
소리 표의 배경음악 id. ("" 이면 끈다, 지금 틀어 달라고 한 것과 같으면 아무것도 하지 않는다)Background music id in the sound table. ("" turns it off, does nothing if it equals the currently requested one)
fadeSecondsnumber
겹쳐 바꾸는 시간. (초, 기본 0, 음수는 0)Crossfade time. (seconds, default 0, negative becomes 0)
isResumedboolean
참이면 그 음악을 멈췄던 자리에서 잇는다. (기본 거짓)If true, resumes that music from where it stopped. (default false)

짝Counterpart: vanilla-engine SoundSystem.play_music

메서드methodplayEffect(soundId, volume = 1, pan = 0)#0.4.0 부터since 0.4.0소스source

효과음 내기. (음소거, 첫 누름 전, 받기 전, 다시 낼 간격 안이면 내지 않는다)

Plays a sound effect. (does not play if muted, before the first press, before downloading, or within the replay interval)

soundIdstring
소리 표의 효과음 id. (표에 없거나 받지 않았으면 내지 않는다)Sound effect id in the sound table. (not played if missing from the table or not fetched)
volumenumber
이번의 크기. (0 ~ 1, 소리의 크기와 설정의 효과음 크기에 곱한다)Volume for this call. (0 ~ 1, multiplied by the sound volume and the sound effect volume setting)
pannumber
좌우. (-1 왼쪽 ~ 1 오른쪽, 0 가운데)Pan. (-1 left ~ 1 right, 0 center)

짝Counterpart: vanilla-engine SoundSystem.play_effect

메서드methodpickVariant(soundId, assets)#0.4.0 부터since 0.4.0소스source

무리에서 하나 고르기. (받은 것 가운데 바로 앞과 다른 것, 하나뿐이면 그것, 없으면 null)

Picks one from a group. (a downloaded one different from the one just before, that one if only one, null if none)

soundIdstring
소리 표의 id. (바로 앞에 고른 번호를 기억하는 열쇠)Sound table id. (key that remembers the index picked just before)
assetsArray<AudioAsset | null>
녹음 무리. (못 받은 것은 null)Take group. (entries that failed to fetch are null)

반환ReturnsAudioAsset | null 고른 애셋. (받은 것이 없으면 null)The picked asset. (null if none were fetched)

메서드methodtrimVoices(soundId, keepCount)#0.4.0 부터since 0.4.0소스source

나는 효과음을 그 수까지 줄이기. (오래된 것부터 끊음, soundId 가 "" 이면 모든 효과음)

Reduces playing sound effects to that count. (cuts off the oldest first, all sound effects if soundId is "")

soundIdstring
줄일 효과음 id. ("" 이면 모든 효과음)Sound effect id to reduce. ("" means all sound effects)
keepCountnumber
남길 수. (음수는 0)Number to keep. (negative becomes 0)
메서드methodstopVoice(voice)#0.4.0 부터since 0.4.0소스source

효과음 하나 끊기.

Cuts off one sound effect.

voiceobject
나고 있는 효과음. ({ soundId, source, gainNode, startTime })A playing sound effect. ({ soundId, source, gainNode, startTime })
메서드methodfadeOutEffects(soundId, fadeSeconds)#0.4.0 부터since 0.4.0소스source

나는 효과음을 줄여 끄기. (soundId 가 "" 이면 모든 효과음, 줄이는 초가 0 이면 바로 끊음)

Fades out playing sound effects. (all sound effects if soundId is "", cuts off immediately if the fade seconds are 0)

soundIdstring
줄일 효과음 id. ("" 이면 모든 효과음)Sound effect id to reduce. ("" means all sound effects)
fadeSecondsnumber
줄이는 시간. (초, 0 이하이면 바로 끊는다)Fade time. (seconds, cuts at once if 0 or less)

짝Counterpart: vanilla-engine SoundSystem.fade_out_effects

메서드methodgetEffectVoiceCount()#0.4.0 부터since 0.4.0소스source

나고 있는 효과음 수. (시험과 기록용)

Number of sound effects playing. (for tests and logging)

반환Returnsnumber 나고 있는 효과음 수.Number of playing sound effects.

짝Counterpart: vanilla-engine SoundSystem.get_effect_voice_count

메서드methodstopEffects()#0.4.0 부터since 0.4.0소스source

나는 효과음을 모두 끊기. (멈춤 창이 뜰 때 등)

Cuts off all playing sound effects. (when the pause window opens, etc.)

짝Counterpart: vanilla-engine SoundSystem.stop_effects

메서드methodupdate()#0.4.0 부터since 0.4.0소스source

매 프레임. (첫 누름 뒤 소리의 길 만들기, 플랫폼의 음소거 따르기, 배경음악 틀기)

Every frame. (creates the sound paths after the first press, follows platform mute, plays background music)

짝Counterpart: vanilla-engine SoundSystem.update

메서드methodretryContextResume()#0.4.0 부터since 0.4.0소스source

다시 깨워 보기. (음소거가 아닌데 AudioContext 가 돌지 않으면 CONTEXT_RESUME_RETRY_INTERVAL 마다) 아이폰은 앱으로 돌아온 순간(다시 보임)에 부른 resume() 을 오디오가 아직 돌아오기 전이라 듣지 않는 일이 있다. 그 뒤로는 끌기만 하는 손가락이 사람의 누름으로 치이지 않아, 버튼을 누르기 전까지 소리가 나지 않았다. 다시 깨운 뒤 돈다고 하는데 소리가 나지 않는 것(시계가 멈춤)은 엔진의 AudioManager 가 iOS 에서 확인한다. (엔진 v0.3.2, iOS 26.6.2 버전업 대응)

Tries waking again. (every CONTEXT_RESUME_RETRY_INTERVAL when not muted but the AudioContext is not running) On iPhone, resume() called at the moment of returning to the app (visible again) is sometimes ignored because audio has not come back yet. After that, touches that only drag do not count as a human press, so no sound played until a button was pressed. The case where it reports running after waking but no sound plays (the clock is stopped) is checked on iOS by the engine's AudioManager. (engine v0.3.2, iOS 26.6.2 update fix)

메서드methodtryAutoplay()#0.4.0 부터since 0.4.0소스source

누르기 전에 깨워 보기. (플랫폼이 허락할 때 처음 한 번, 웹뷰가 막으면 AudioContext 가 멈춘 채로 남고 첫 누름에 엔진이 깨운다)

Tries waking before a press. (once at first when the platform allows, if the webview blocks it the AudioContext stays stopped and the engine wakes it on the first press)

메서드methodensurePlayers()#0.4.0 부터since 0.4.0소스source

소리의 길 만들기. (첫 누름 뒤 한 번, AudioContext 를 그 전에 만들지 않게)

  • 엔진은 버스를 만들 때 AudioContext 를 만든다.

Creates the sound paths. (once after the first press, so the AudioContext is not created before then)

  • The engine creates the AudioContext when creating a bus.
메서드methodapplyVolumes()#0.4.0 부터since 0.4.0소스source

크기 적용. (음소거면 0)

Applies volume. (0 if muted)

메서드methodapplyMute()#0.4.0 부터since 0.4.0소스source

음소거 적용. (바뀔 때만, 음소거가 되면 나는 효과음을 끊음)

Applies mute. (only when it changes, cuts off playing sound effects when muted)

메서드methodapplyContextPause()#0.4.0 부터since 0.4.0소스source

음소거인 동안 AudioContext 멈추기와 풀리면 깨우기. (바뀔 때만, 첫 누름 전에는 AudioContext 가 없어 하지 않는다)

Stops the AudioContext while muted and wakes it when unmuted. (only when it changes, not done before the first press since there is no AudioContext)

메서드methodupdateMusic()#0.4.0 부터since 0.4.0소스source

배경음악 틀기와 바꾸기. (AudioContext 가 돌고 받아 둔 것만, 음소거 중에도 소리 없이 돌아 풀면 이어 들립다)

  • 바꾸라고 하면 앞 음악은 곧바로 줄이기 시작하고(멈춘 자리를 기억), 새 음악은 받아 두었으면 0 에서 올린다.

Plays and switches background music. (only when the AudioContext is running and it is downloaded, runs silently even while muted so it is heard continuing when unmuted)

  • When asked to switch, the previous music starts fading down at once (remembering where it stopped), and the new music rises from 0 if downloaded.
메서드methodfadeOutMusic(playingMusic, fadeSeconds)#0.4.0 부터since 0.4.0소스source

틀던 배경음악을 줄여 끄기. (fadeSeconds 동안, 다 줄어든 때의 자리를 기억)

Fades out the playing background music. (over fadeSeconds, remembering the position when fully faded)

playingMusicobject
틀던 배경음악. ({ soundId, source, player, gain, startTime, offset, duration })The background music that was playing. ({ soundId, source, player, gain, startTime, offset, duration })
fadeSecondsnumber
줄이는 시간. (초, 0 이면 바로 끈다)Fade time. (seconds, turns off at once if 0)

함수Functions

함수functionsetSoundSystem(soundSystem)#0.4.0 부터since 0.4.0소스source

함께 쓰는 소리 정하기.

Sets the shared sound.

soundSystemSoundSystem
함께 쓸 소리. (null 이면 비운다)Sound to share. (clears it if null)

짝Counterpart: vanilla-engine set_sound_system

함수functionreadSoundSystem()#0.4.0 부터since 0.4.0소스source

함께 쓰는 소리. (아직 없으면 null)

Shared sound. (null if none yet)

반환ReturnsSoundSystem | null 함께 쓰는 소리. (setSoundSystem 전이면 null)The shared sound. (null before setSoundSystem)

짝Counterpart: vanilla-engine read_sound_system