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


// a very simple script to make a G-above-middle-C 'beep' on startup

public class wind : MonoBehaviour {
    int objno = 0;
    rtcmixmain RTcmix;
    private bool did_start = false;


    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);

        // send a note using the WAVETABLE() instrument
        string score = "setup(irand(200, 400), 10, 1) " +
            "ampenv = maketable(\"line\", 1000, 0,0, 50,1, 100,0) " +
            "IINOISE(0, 7, 20000*ampenv, 0.5) " +
            "MAXBANG(3.5) ";


        RTcmix.SendScore(score, objno);

        did_start = true;
    }
	

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


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

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

        if (RTcmix.checkbangRTcmix(objno) == 1)
        {
            string score = "setup(irand(200, 400), 10, 1) " +
                "ampenv = maketable(\"line\", 1000, 0,0, 50,1, 100,0) " +
                "IINOISE(0, 7, 20000*ampenv, 0.5) " +
                "MAXBANG(3.5) ";
            RTcmix.SendScore(score, objno);
        }
    }


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