public float SecondsRemaining(SoundTag snd) { if (SoundTagEmitters.TryGetValue(snd.Id, out var emitter)) { return((float)emitter.RemainingTime().TotalSeconds); } return(0); }
private AudioClip GetClip(SoundTag soundTag) { foreach (SoundItem s in clips) { if (s.tag == soundTag) { return(s.clip); } } return(null); }
private void PlaySound(SoundTag soundTag) { AudioSource player = audioSourcePool.GetAvailableAudioSource(); if (player == null) { Debug.LogWarning("there is no available audio source left available"); return; } player.clip = GetClip(soundTag); player.Play(); }
private ClipData GetClip(SoundTag snd) { var soundEntry = soundMapping.SoundEntries[snd.SoundEntryIndex]; var clipIndex = rng.Next(0, soundEntry.NamedSoundClipCount); var clipInfo = soundMapping.NamedSoundClips[soundEntry.NamedSoundClipIndex + clipIndex]; var result = new ClipData(); result.Encoding = snd.Encoding switch { EncodingType.ImaAdpcmMono => AudioEncoding.MonoImaAdpcm, EncodingType.ImaAdpcmStereo => AudioEncoding.StereoImaAdpcm, _ => AudioEncoding.Mono16, }; result.SampleRate = snd.SampleRate switch { Core.Tags.SampleRate.hz22k05 => SampleRate._22k05, Core.Tags.SampleRate.hz44k1 => SampleRate._44k1, _ => SampleRate._44k1 }; var clipSize = 0; for (var c = 0; c < clipInfo.SoundDataChunkCount; c++) { var chunk = soundMapping.SoundDataChunks[clipInfo.SoundDataChunkIndex + c]; clipSize += (int)(chunk.Length & 0x3FFFFFFF); } Span <byte> clipData = new byte[clipSize]; var clipDataCurrent = 0; for (var c = 0; c < clipInfo.SoundDataChunkCount; c++) { var chunk = soundMapping.SoundDataChunks[clipInfo.SoundDataChunkIndex + c]; var len = (int)(chunk.Length & 0x3FFFFFFF); var chunkData = this.scene.Map.ReadData(chunk.Offset.Location, chunk.Offset, len); chunkData.Span.CopyTo(clipData.Slice(clipDataCurrent)); clipDataCurrent += len; } result.Data = clipData; return(result); }
void Update() { while (callQueue.Count > 0) { Action action = callQueue.Dequeue(); SoundTag param = paramQueue.Dequeue(); switch (action) { case Action.PlaySound: PlaySound(param); break; case Action.PlayBGM: PlayBGM(); break; case Action.StopAll: StopAll(); break; } } }
public void Start(SoundTag sound, IGameObject target) { var clip = GetClip(sound); ISoundEmitter emitter; if (target is GameObjectEntity e) { if (e.SoundEmitter.Emitter == null) { // TODO: destroy emitter e.SoundEmitter.Emitter = this.audioAdapter.CreateEmitter(); } emitter = e.SoundEmitter.Emitter; } else { emitter = globalEmitter; } emitter.PlayImmediate(clip.Encoding, clip.SampleRate, clip.Data); SoundTagEmitters[sound.Id] = emitter; }
public AudioClip GetClip(SoundTag sound) { return(_generalSFX[(int)sound]); }
/// <summary>plays an impulse sound from the specified source object (or "none"), with the specified scale.</summary> public void sound_impulse_trigger(SoundTag sound, IGameObject source, float floatValue, int intValue) { this.audioSystem.Start(sound, source); }
/// <summary>stops the specified impulse sound.</summary> public void sound_impulse_stop(SoundTag sound) { }
/// <summary>plays an impulse sound from the specified source object (or "none"), with the specified scale and effect.</summary> public void sound_impulse_start_effect(SoundTag sound, IGameObject entity, float floatValue, string /*id*/ effect) { this.audioSystem.Start(sound, entity); }
/// <summary>plays an impulse sound from the specified source object (or "none"), with the specified scale.</summary> public void sound_impulse_start(SoundTag sound, IGameObject entity, float floatValue) { this.audioSystem.Start(sound, entity); }
/// <summary>returns the time remaining for the specified impulse sound. DO NOT CALL IN CUTSCENES.</summary> public int sound_impulse_language_time(SoundTag soundRef) { return((int)(this.audioSystem.SecondsRemaining(soundRef) * TicksPerSecond)); }
static public void CallFunction(Action action, SoundTag tag) { callQueue.Enqueue(action); paramQueue.Enqueue(tag); }
/// <summary>your mom part 2.</summary> public void sound_impulse_predict(SoundTag soundRef) { }