示例#1
0
    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);
    }
示例#2
0
    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
    }
示例#3
0
 public void OnDestroy()
 {
     if (slot >= 0)
     {
         SunVoxUtils.CloseSlot(slot);
     }
 }
示例#4
0
    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);
    }
示例#5
0
 public void Stop()
 {
     SunVoxUtils.CloseSlot(slot);
 }