Example #1
0
    void Update()
    {
        double currTime = AudioSettings.dspTime;

        if (currSegment != null)
        {
            if (currTime + prefetchTime >= nextSegmentStartTime)
            {
                currSegment = nextSegment;
                nextSegment = currSegment.transitions[random.Next(0, currSegment.transitions.Length)];
                if (currSegment.mixerSnapshot != null)
                {
                    currSegment.mixerSnapshot.TransitionTo(currSegment.snapshotTransitionTime);
                }

                float  beatLength = 60.0f / currSegment.bpm;
                double len        = currSegment.lengthInBeats * beatLength;
                for (int n = 0; n < layers.Length; n++)
                {
                    layers[n].NextClip(this);
                    if (n == 0 && layers[n].currDebugRect != null)
                    {
                        DrawStuff.AddTextMesh(gameObject, layers[n].currDebugRect.x1, -3.0f, currSegment.name);
                    }
                }

                currSegmentStartTime  = nextSegmentStartTime;
                nextSegmentStartTime += len + nextSegment.startTime * beatLength;
            }

            for (int n = 0; n < layers.Length; n++)
            {
                layers[n].Update(this, currTime);
            }
        }

        foreach (var s in scheduledStingers)
        {
            if (s.time < currTime)
            {
                stingerSource.PlayOneShot(s.clip, s.level);
                s.disposed = true;
            }
        }

        scheduledStingers.RemoveAll(item => item.disposed);

        if (camera != null)
        {
            camPosition += (camTarget - camPosition) * 0.02f;
            camera.transform.position = new Vector3(camPosition, camera.transform.position.y, camera.transform.position.z);
        }
    }
Example #2
0
        public void NextClip(MusicScheduler musicScheduler)
        {
            if (index < musicScheduler.currSegment.layers.Length)
            {
                MusicSegment.Layer layer = musicScheduler.currSegment.layers[index];
                if (layer.clips.Length > 0)
                {
                    currSource = 1 - currSource;
                    var s = sources[currSource];

                    var nextClip = layer.clips[random.Next(0, layer.clips.Length)];
                    while (nextClip == currClip)
                    {
                        nextClip = layer.clips[random.Next(0, layer.clips.Length)];
                    }

                    s.Stop();

                    float  beatLength = 60.0f / musicScheduler.currSegment.bpm;
                    double t0         = musicScheduler.GetNextEventStartTime() + layer.startTime * beatLength;
                    s.outputAudioMixerGroup = layer.mixerGroup;
                    s.clip          = nextClip;
                    s.volume        = (musicScheduler.currSegment.fadeInTime > 0.0f) ? 0.0f : layer.volume;
                    s.panStereo     = layer.pan;
                    s.reverbZoneMix = layer.reverbZoneMix;
                    s.PlayScheduled(t0);
                    sourceStartTime[currSource] = t0;
                    sourceEndTime[currSource]   = t0 + nextClip.length;

                    prevDebugRect = currDebugRect;
                    float x = (float)(t0 - musicScheduler.GetStartTime()), y = index * 5.0f + currSource * 2.0f;
                    currDebugRect = new DebugRect(x, y, x + nextClip.length, y + 2.0f);
                    debugRects.Add(currDebugRect);

                    DrawStuff.AddTextMesh(go, x, y, nextClip.name);

                    musicScheduler.camTarget = Mathf.Max(musicScheduler.camTarget, (float)(musicScheduler.GetNextEventStartTime() - musicScheduler.GetStartTime() + nextClip.length * 0.5));
                }
            }
        }