public void PlayMusic(string filename, bool repeat = false, byte volume = Byte.MaxValue) { if (Disabled) { return; } // var path = $"Assets/StreamingAssets/Tracker/{filename}"; var path = GetDataPath("Tracker/" + filename); Logger.Log($"Loading track {filename} from {path}", Category.SunVox); int loadResult = SunVox.sv_load((int)Slot.Music, path); if (loadResult == 0) { SunVox.sv_stop((int)Slot.Music); SunVox.sv_set_autostop((int)Slot.Music, repeat ? 0 : 1); SunVox.sv_volume((int)Slot.Music, volume); SunVox.sv_play_from_beginning((int)Slot.Music); } else { Logger.LogWarning($"Music load error: {path}", Category.SunVox); } }
private void Stop(Slot slot) { if (Disabled) { return; } SunVox.sv_stop((int)slot); }
private IEnumerator VolumeUpdateCoroutine() { yield return(null); // wait a frame to allow world to finish loading if (playMode == PlayMode.BKGND) { SunVox.sv_play_from_beginning(slot); } while (true) { if (fadingIn) { if (fadeIn == 0) { currentVolume = volume; } else { currentVolume += volume / fadeIn * Time.unscaledDeltaTime; } if (currentVolume >= volume) { currentVolume = volume; fadingIn = false; } UpdateSunVoxVolume(); } else if (fadingOut) { if (fadeOut == 0) { currentVolume = 0; } else { currentVolume -= volume / fadeOut * Time.unscaledDeltaTime; } if (currentVolume <= 0) { currentVolume = 0; fadingOut = false; if (playMode != PlayMode.BKGND) { SunVox.sv_stop(slot); } } UpdateSunVoxVolume(); } yield return(null); } }
public void PlayAnnouncement(byte[] sound) { try { SunVox.sv_stop((int)Slot.Announce); SunVox.sv_sampler_load_from_memory((int)Slot.Announce, SamplerModule, sound, sound.Length, -1); SunVox.sv_set_autostop((int)Slot.Announce, 1); //play announcement tune SunVox.sv_play_from_beginning((int)Slot.Announce); //speak tts with effects StartCoroutine(SpeakAnnouncement()); } catch (Exception e) { Logger.LogWarning("Exception: " + e, Category.SunVox); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { if (SunVox.sv_end_of_song(0) == 1) { SunVox.sv_play(0); } else { SunVox.sv_stop(0); } } }
private void Stop(Slot slot) { SunVox.sv_stop((int)slot); }