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); } }
public void Init() { if (songData.bytes.Length == 0) { return; } slot = SunVoxUtils.OpenUnusedSlot(); if (slot < 0) { return; } int result = SunVox.sv_load_from_memory(slot, songData.bytes, songData.bytes.Length); if (result != 0) { throw new MapReadException("Error reading SunVox file"); } //Debug.Log(System.Runtime.InteropServices.Marshal.PtrToStringAuto(SunVox.sv_get_song_name(0))); currentVolume = 0; UpdateSunVoxVolume(); if (playMode == PlayMode.ONCE || playMode == PlayMode._1SHOT) { SunVox.sv_set_autostop(slot, 1); } else { SunVox.sv_set_autostop(slot, 0); } StartCoroutine(VolumeUpdateCoroutine()); // runs even while disabled }
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); } }