// The bulk of the clean-up code is implemented in Dispose(bool) protected virtual void Dispose(bool disposing) { if (disposing) { if (output != null) { output.Stop(); output.Dispose(); output = null; } if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } } }
public void Open(string filename) { if (output != null) { output.Stop(); while (output.PlaybackState != PlaybackState.Stopped) { Thread.Sleep(10); } } if (spectrum != null) { spectrum.SpectrumReady -= Spectrum_SpectrumReady; spectrum = null; } output?.Dispose(); reader?.Close(); reader?.Dispose(); reader = null; output = outputFactory(); reader = new AudioFileReader2(filename); spectrum = new SpectrumGenerator(reader); spectrum.SpectrumReady += Spectrum_SpectrumReady; output.Init(spectrum); TracksPlayed++; InvokePlayerStart(filename); // write out filter parameter names to our shader directory so that shaders can reference things by name instead of index. if (!paramsWritten) { int i = 0; File.WriteAllLines("Res/Shaders/Common/filterParameters.glsl", spectrum.FilterOutputNames.Select(s => $"#define A_{s} {i++}")); paramsWritten = true; } }