Esempio n. 1
0
    //int timeIndex;

    // Use this for initialization
    void Start()
    {
        //List of notes currently playing
        noteFreqs = new List <float>();

        //List of notes to be queued
        timedNotes = new List <TimedNote>();

        //Synth wave type
        type = SynthType.sine;
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        //Check player Input
        Vector2 input = GetInput();


        //Checks if there are any timed notes left to play
        if (timedNotes.Count > 0)
        {
            //If no notes are currently playing add first note from timed notes
            if (noteFreqs.Count <= 0)
            {
                AddNote(timedNotes[0].midiNumber);
            }
            //Otherwise increase the time of the currently playing note
            else
            {
                timedNotes[0].timer += Time.deltaTime;
            }

            //If currently playing timed note has played for set time then remove from both timednotes and notefreqs
            if (timedNotes[0].timer > timedNotes[0].maxTime)
            {
                RemoveNote(timedNotes[0].midiNumber);
                timedNotes.RemoveAt(0);
            }
        }

        //Change synth wave type when K is pressed
        if (Input.GetKeyDown(KeyCode.K))
        {
            type++;
            if ((int)type > 2)
            {
                type = SynthType.sine;
            }
        }

        //set gain
        gain = volume;

        //Half the gain if its a square wave because my ears
        if (type == SynthType.square)
        {
            gain = volume / 2;
        }
    }