Exemplo n.º 1
0
    private IEnumerator GenerateAllWaveforms()
    {
        yield return(new WaitUntil(() => !SceneTransitionManager.IsLoading)); //How we know "Start" has been called

        // Start the background worker
        audioManager.Begin(WaveformType == 2, WaveformType == 2 ? spectrogramHeightGradient : spectrogramGradient2d, source.clip, waveformData, atsc, BeatmapObjectContainerCollection.ChunkSize);

        int chunkId;

        // Loop while we have completed calulations waiting to be rendered
        //  or there are threads still running generating new chunks
        //  or we are still writing a previous save to disk (we save again at the end)
        while (audioManager.chunksComplete.Count > 0 || audioManager.IsAlive())
        {
            if (audioManager.chunksComplete.TryDequeue(out chunkId))
            {
                float[][] toRender = new float[audioManager.ColumnsPerChunk][];
                waveformData.GetChunk(chunkId, audioManager.ColumnsPerChunk, ref toRender);

                SpectrogramChunk chunk = Instantiate(spectrogramChunkPrefab, spectroParent).GetComponent <SpectrogramChunk>();
                chunk.UpdateMesh(toRender, waveformData.BandColors[chunkId], chunkId, this);

                // Wait 2 frames for smoooth
                yield return(new WaitForEndOfFrame());
            }
            yield return(new WaitForEndOfFrame());
        }

        Debug.Log("WaveformGenerator: Main thread done");
    }
Exemplo n.º 2
0
    private IEnumerator RefreshVisuals()
    {
        if (BeatSaberSongContainer.Instance.loadedSong == null)
        {
            yield break;
        }

        foreach (RawImage image in activeTiles)
        {
            image.gameObject.SetActive(false);
        }
        cachedTiles = new Queue <RawImage>(activeTiles);
        activeTiles.Clear();
        previewSelection.gameObject.SetActive(false);

        WaveformData = new WaveformData();

        audioManager.SetSecondPerChunk(5);
        audioManager.Begin(false, spectrogramGradient2d, BeatSaberSongContainer.Instance.loadedSong, WaveformData, null, 5);

        while (audioManager.IsAlive())
        {
            previewGenerationSlider.value = (float)WaveformData.ProcessedChunks / WaveformData.Chunks;
            yield return(new WaitForEndOfFrame());
        }

        for (int i = 0; i < WaveformData.Chunks; i++)
        {
            float[][] toRender = new float[audioManager.ColumnsPerChunk][];
            WaveformData.GetChunk(i, audioManager.ColumnsPerChunk, ref toRender);

            RawImage image = RetrieveOrCreateRawImage();
            image.texture = WaveformData.BandColors[i];
            image.gameObject.SetActive(true);
            activeTiles.Add(image);
        }

        UpdatePreviewSelection();
        previewSelection.gameObject.SetActive(true);
    }