private IEnumerator GenerateAllWaveforms() { yield return(new WaitUntil(() => !SceneTransitionManager.IsLoading)); //How we know "Start" has been called mixer.SetFloat("WaveformVolume", -80); source.Play(); while (chunksGenerated * secondPerChunk < source.clip.length) { for (int i = 0; i < audioManager.ColumnsPerChunk; i++) { float newTime = (chunksGenerated * secondPerChunk) + (secondPerChunk / audioManager.ColumnsPerChunk * i); if (newTime >= source.clip.length) { break; } source.time = newTime; yield return(new WaitForFixedUpdate()); audioManager.PopulateData(); } SpectrogramChunk chunk = Instantiate(spectrogramChunkPrefab, spectroParent).GetComponent <SpectrogramChunk>(); chunk.UpdateMesh(AudioManager._bandVolumes, chunksGenerated, this); audioManager.Start(); //WE GO AGANE chunksGenerated++; } source.Stop(); source.time = 0; mixer.SetFloat("WaveformVolume", 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"); }