public void ReadStream(Stream stream) { byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); string name = null; int slot = SunVoxUtils.OpenUnusedSlot(); int result = SunVox.sv_load_from_memory(slot, bytes, bytes.Length); if (result == 0) { name = System.Runtime.InteropServices.Marshal.PtrToStringAuto(SunVox.sv_get_song_name(slot)); } SunVoxUtils.CloseSlot(slot); if (name != null) { name = name.Trim(); } if (name != null && name.Length > 32) { name = name.Substring(0, 32); } if (name == null || name == "") { name = "imported"; } data = new EmbeddedData(name, bytes, EmbeddedDataType.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 OnDestroy() { if (slot >= 0) { SunVoxUtils.CloseSlot(slot); } }
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); }
public void Stop() { SunVoxUtils.CloseSlot(slot); }