core/audiobus
오디오 버스. (원본 core/audiobus.js 의 AudioBus)
- 여러 플레이어의 소리를 한 길로 모아 크기와 음소거를 한꺼번에 건다. (SoundSystem 의 배경음악 버스와 효과음 버스)
- 만드는 곳은 AudioManager::create_audio_bus() 나 AudioBus::new(매니저) 다. (원본 new AudioBus(audioContext)) 그 버스로 트는 플레이어는 create_audio_player() 로 만든다.
- 버스 자리는 백엔드가 채운다. (platform/audio 의 AudioBusBackend) 데스크탑: 엔진 믹서에서 출력에 이은 GainNode 하나. 버스로 만든 플레이어가 여기로 소리를 낸다. (셈은 크롬 WebAudio 와 같다) 웹: 원본처럼 출력에 이은 GainNode 하나. 버스로 만든 플레이어의 GainNode 가 여기에 이어진다.
- AudioContext 가 없을 때 만든 버스는 소리가 없고, 그 버스로 만든 플레이어도 소리를 내지 않는다. (원본과 같다)
- 크기와 음소거는 AudioPlayer 와 같은 규칙이다. (0 ~ 1 로 자르고, 음소거를 풀면 설정한 크기로 돌아간다)
- 원본과 다른 것:
- 상태를
Rc<RefCell>로 나눠 든다. SoundSystem 이 든 버스를 get_music_bus 로 빌려 준 채 크기를 바꾸고 플레이어를 만들 수 있게 메서드는 모두 &self 다. Clone 하면 같은 버스를 보는 손잡이가 하나 더 생긴다. - 버스로 만든 플레이어는 버스 손잡이를 하나 든다. 손잡이를 모두 버리면 버스가 출력에서 떨어진다. (원본은 이은 노드를 브라우저가 살려 둔다)
- get_gain_node(원본 getGainNode)는 AudioGainNode 를 돌려준다. 웹은 GainNode, 데스크탑은 믹서의 버스 노드를 나눠 드는
Rc<MixerGainNode>다. 어느 쪽이든 as_deref() 가 AudioPlayer::new 의 내보낼 곳이다. (AudioPlayer::new(&audio_manager, audio_bus.get_gain_node().as_deref()), 두 플랫폼이 같다)
Audio bus. (AudioBus in the original core/audiobus.js)
- Gathers the sound of several players into one path and applies volume and mute to all of them at once. (SoundSystem's music bus and sound effect bus)
- Created with AudioManager::create_audio_bus() or AudioBus::new(manager). (the original new AudioBus(audioContext)) Players that play through the bus are created with create_audio_player().
- The backend fills the bus slot. (AudioBusBackend in platform/audio) Desktop: one GainNode connected to the output in the engine mixer. Players created from the bus send their sound here. (the math matches Chrome WebAudio) Web: one GainNode connected to the output, as in the original. The GainNodes of players created from the bus connect to it.
- A bus created without an AudioContext is silent, and players created from it make no sound either. (same as the original)
- Volume and mute follow the same rules as AudioPlayer. (clamped to 0 ~ 1, unmuting returns to the set volume)
- Differences from the original:
- State is shared through
Rc<RefCell>. So that the volume can be changed and players created while SoundSystem lends its bus through get_music_bus, all methods take &self. Cloning makes one more handle to the same bus. - A player created from a bus holds one bus handle. When all handles are dropped the bus is disconnected from the output. (in the original the browser keeps connected nodes alive)
- get_gain_node (the original getGainNode) returns an AudioGainNode. On the web it is a GainNode, on desktop an
Rc<MixerGainNode>sharing the mixer's bus node. Either way, its as_deref() is the output destination for AudioPlayer::new. (AudioPlayer::new(&audio_manager, audio_bus.get_gain_node().as_deref()), same on both platforms)
AudioBusstruct traits Clone
오디오 버스.
- 버스로 만든 플레이어의 소리를 모아 크기와 음소거를 한꺼번에 건다. Clone 한 손잡이는 같은 버스를 본다.
Audio bus.
- Gathers the sound of players created from the bus and applies volume and mute to all of them at once. A cloned handle refers to the same bus.
use vanilla::{AudioManager, Engine};
fn play_effect(engine: &Engine) {
let audio_manager: &AudioManager = &engine.get_audio_manager();
let effect_bus = audio_manager.create_audio_bus();
effect_bus.set_volume(0.5);
let mut effect_player = effect_bus.create_audio_player();
let audio_asset = engine.load_audio_asset("tests/assets/audio/wav_s16_stereo.wav").unwrap();
effect_player.set_audio_asset(audio_asset);
effect_player.play(false);
effect_bus.mute();
assert_eq!(effect_bus.is_muted(), effect_bus.is_available());
effect_bus.unmute();
assert_eq!(effect_bus.get_volume(), 0.5);
}use vanilla::{AudioBus, AudioManager, AudioPlayer};
let audio_manager = AudioManager::new();
let audio_bus = AudioBus::new(&audio_manager);
let audio_player = AudioPlayer::new(&audio_manager, audio_bus.get_gain_node().as_deref());
assert!(!audio_player.is_playing());생성. (원본 new AudioBus(audioContext), 매니저의 AudioContext 가 없으면 만든다, 만들지 못하면 소리 없는 버스)
Constructor. (the original new AudioBus(audioContext), creates the manager's AudioContext if absent, a silent bus if it cannot be created)
- audio_manager&AudioManager
- AudioContext 를 든 매니저. (보통 engine.get_audio_manager())Manager holding the AudioContext. (usually engine.get_audio_manager())
반환ReturnsAudioBus 출력에 이은 새 버스. (크기 1, 음소거 아님)New bus connected to the output. (volume 1, not muted)
짝Counterpart: vanilla.js AudioBus.constructor
이 버스로 트는 오디오 플레이어 생성. (버스가 소리 없으면 소리 없는 플레이어)
Creates an audio player that plays through this bus. (a silent player if the bus is silent)
반환ReturnsAudioPlayer 이 버스로 소리를 내는 새 플레이어. (버스 손잡이를 하나 들어 버스를 살려 둔다)New player that sends its sound through this bus. (holds one bus handle to keep the bus alive)
짝Counterpart: vanilla.js AudioBus.createAudioPlayer
음소거. (소리 없는 버스면 아무것도 하지 않는다)
Mute. (does nothing on a silent bus)
짝Counterpart: vanilla.js AudioBus.mute
음소거 해제. (설정한 크기로 돌아간다)
Unmute. (returns to the set volume)
짝Counterpart: vanilla.js AudioBus.unmute
크기 설정. (0 ~ 1, 음소거 중이면 음소거를 풀 때 적용된다)
Sets the volume. (0 ~ 1, if muted it applies when unmuted)
- volumef64
- 버스 크기. (0 ~ 1 로 자른다, 유한하지 않으면 1)Bus volume. (clamped to 0 ~ 1, 1 if not finite)
짝Counterpart: vanilla.js AudioBus.setVolume
크기 반환.
Returns the volume.
반환Returnsf64 설정한 크기. (0 ~ 1, 음소거해도 바뀌지 않는다)The set volume. (0 ~ 1, does not change when muted)
짝Counterpart: vanilla.js AudioBus.getVolume
음소거 여부 반환.
Returns whether muted.
반환Returnsbool 음소거 중이면 true. (소리 없는 버스는 mute 를 불러도 false)true if muted. (false for a silent bus even if mute is called)
짝Counterpart: vanilla.js AudioBus.isMuted
소리를 모을 수 있는지. (AudioContext 가 있을 때 만든 버스)
Whether it can gather sound. (a bus created while an AudioContext exists)
반환Returnsbool 백엔드 노드가 있으면 true. (AudioContext 를 만들지 못했을 때 만든 버스는 false)true if there is a backend node. (false for a bus created when the AudioContext could not be created)
짝Counterpart: vanilla.js AudioBus.isAvailable
버스의 GainNode. (원본 getGainNode, 웹 GainNode, 데스크탑 버스의 믹서 크기 노드를 나눠 드는 Rc<MixerGainNode>, AudioContext 가 없을 때 만든 버스는 None)
- 노드에 직접 건 크기는 크기 칸과 음소거 칸을 바꾸지 않는다. (원본과 같다)
The bus's GainNode. (the original getGainNode; on the web a GainNode, on desktop an Rc<MixerGainNode> sharing the bus's mixer gain node; None for a bus created without an AudioContext)
- A gain set directly on the node does not change the volume field or the mute field. (same as the original)
반환ReturnsOption<AudioGainNode> 버스 노드를 나눠 드는 손잡이. (as_deref() 가 AudioPlayer::new 의 내보낼 곳이다, 소리 없는 버스는 None)Handle sharing the bus node. (its as_deref() is the output destination for AudioPlayer::new, None for a silent bus)
짝Counterpart: vanilla.js AudioBus.getGainNode