public override void BehaviorEnabled() { if (slot < 0) { return; } if (playMode != PlayMode.BKGND) { if (fadeIn == 0) { currentVolume = volume; } else { currentVolume = 0; } } fadingIn = true; fadingOut = false; UpdateSunVoxVolume(); if (playMode != PlayMode.BKGND) { SunVox.sv_play_from_beginning(slot); } }
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 SunVoxPlayer(byte[] data) { slot = SunVoxUtils.OpenUnusedSlot(); int result = SunVox.sv_load_from_memory(slot, data, data.Length); if (result != 0) { Debug.LogError("Error loading file"); return; } SunVox.sv_play_from_beginning(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 onBinaryFileLoaded() { var music = SunVox.sv_load_from_memory(0, sunvox_song, sunvox_song_size); if (music >= 0) { log("Loaded."); } else { log("Load error."); } SunVox.sv_volume(0, 256); var songName = Marshal.PtrToStringAnsi(SunVox.sv_get_song_name(0)); log("song_name: " + songName); SunVox.sv_play_from_beginning(0); }
private void Start() { log("-Press Space for toggle music-\n"); try { int ver = SunVox.sv_init("0", 44100, 2, 0); if (ver >= 0) { int major = (ver >> 16) & 255; int minor1 = (ver >> 8) & 255; int minor2 = (ver) & 255; log(String.Format("SunVox lib version: {0}.{1}.{2}", major, minor1, minor2)); SunVox.sv_open_slot(0); log("Loading SunVox song from file..."); var path = "Assets/StreamingAssets/test.sunvox"; // This path is correct only for standalone if (SunVox.sv_load(0, path) == 0) { log("Loaded."); } else { log("Load error."); SunVox.sv_volume(0, 256); } SunVox.sv_play_from_beginning(0); } else { log("sv_init() error " + ver); } } catch (Exception e) { log("Exception: " + e); } }