using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class volcsoundscript : MonoBehaviour
{
    int objno = 1;
    rtcmixmain RTcmix;
    private bool did_start = false;

    string sfpath;

    private void Awake()
    {
        // find the RTcmixmain object with the RTcmix function definitions
        RTcmix = GameObject.Find("RTcmixmain").GetComponent<rtcmixmain>();
    }


    // Use this for initialization
    void Start()
    {
        // initialize RTcmix
        RTcmix.initRTcmix(objno);

        sfpath = Application.dataPath;

        string score = "rtinput(\"" + sfpath + "/volccat.wav\") ";  // this is how you get the path to the soundfile
        RTcmix.SendScore(score, objno);

        did_start = true;
    }


    // Update is called once per frame
    void Update()
    {
    }

    public void startSound()
    {
        RTcmix.SendScore("TRANS(0, 0, 0.5, 1.0, irand(0.01, 0.11))", objno);
        RTcmix.SendScore("MAXBANG(irand(0.05, 0.2))", objno);
    }


    void OnAudioFilterRead(float[] data, int channels)
    {
        if (!did_start) return;

        // compute sound samples
        RTcmix.runRTcmix(data, objno, 0);

        if (RTcmix.checkbangRTcmix(objno) == 1)
        {
            RTcmix.SendScore("TRANS(0, 0, 0.5, 1.0, irand(0.01, 0.11))", objno);
            RTcmix.SendScore("MAXBANG(irand(0.05, 0.2))", objno);
        }
    }


    void OnApplicationQuit()
    {
        did_start = false;
        RTcmix = null;
    }
}
