Ejemplo n.º 1
0
    // Awake is called when the script instance
    // is being loaded.
    void Awake()
    {
        midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40);
        midiStreamSynthesizer.LoadBank(bankFilePath);
        sampleBuffer = new float[midiStreamSynthesizer.BufferSize];

        audioFiles = Resources.LoadAll<AudioClip> ("Audio/Instruments");

        soundAreaSelector = GameObject.Find("SoundManagers").GetComponent<SoundAreaSelector>();
        pitchRangeSelector = GameObject.Find("SoundManagers").GetComponent<PitchRangeSelector>();
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        soundAreaSelector = GameObject.Find("SoundManagers").GetComponent<SoundAreaSelector>();
        pitchRangeSelector = GameObject.Find("SoundManagers").GetComponent<PitchRangeSelector>();
        soundDirectionManager = GameObject.Find("SoundManagers").GetComponent<SoundDirectionManager>();
        audioPlayer = GameObject.Find("Listener").GetComponent<AudioPlayer>();

        setNoteManager = GameObject.Find("SoundManagers").GetComponent<SetNoteManager>();
        setNoteManager.setOnLoopEvent.AddListener(SetOnLoop);

        simulator = GameObject.Find("SecondTarget").GetComponent<SimulateRotation>();
        simulator.setOnLoopEvent.AddListener(SetOnLoop);

        // create beat
        beatInstruments = Resources.LoadAll<AudioClip> ("Audio/BeatInstruments");

        if (beatInstruments.Length >= 2) {
            AudioClip bassDrum = beatInstruments [0];
            AudioClip hihat = beatInstruments [1];

            float time = 0;

            for (int i = 0; i < numberOfBeats; i++) {
                loopNotes.Add (new LoopNote (bassDrum, soundAreaSelector.activeColor, soundAreaSelector.activeSoundArea, soundAreaSelector.activeInstrument, 0, 1, time, new Vector3 (0, 0, 0), true));
                time += loopDuration / numberOfBeats;
            }

            time -= (loopDuration / numberOfBeats) * 0.5f;
            print ("Hihat Time: " + time);
            loopNotes.Add (new LoopNote (hihat, soundAreaSelector.activeColor, soundAreaSelector.activeSoundArea, soundAreaSelector.activeInstrument, 0, 1, time, new Vector3 (0, 0, 0), true));
        }

        // sort notes by time
        loopNotes.Sort((x, y) => x.time.CompareTo(y.time));

        timer = 0;
        noteIndex = 0;

        if (loopNotes.Count > 0)
            currentNote = loopNotes[noteIndex];
    }