public void PreloadNextTrack(Track Track) { lock (preloadLock) { if (PreloadStream.Track != Track) { PreloadStream.Close(); PreloadStream.Dispose(); if (Track != null && Track.ConfirmExists) { PreloadStream = new AudioStreamFile(Track, gainDB + volumeDB, equalizer, numEqBands, equalizerOn, replayGain); if (PreloadStream.Frequency < 0) { PreloadStream = AudioStream.NullStream; } NextTrack = Track; } } } }
private bool startFileStream(Track Track) { try { oldStream = Stream; if ((Track == PreloadStream.Track) || File.Exists(Track.FilePath)) { PlayingTrack = Track; totalTime = PlayingTrack.Duration; if (oldStream != null && oldStream.Frequency != Track.SampleRate && output != null) { matchFrequenciesDelayBytes = output.BufferSize * 3 / 2; // factor of 3 to prevent 24 bit meltdown } if (Track == PreloadStream.Track) { Stream = PreloadStream; System.Diagnostics.Debug.WriteLine("Preload Track Hit"); } else { Stream = new AudioStreamFile(PlayingTrack, gainDB + volumeDB, equalizer, numEqBands, equalizerOn, controller.ReplayGain); System.Diagnostics.Debug.WriteLine("Preload Track Miss"); if (Stream.Frequency < 0) { return(false); } } PreloadStream = AudioStream.NullStream; Clock.DoOnMainThread(closeOldStream, 1000); return(true); } else { return(false); } } catch { return(false); } }
public void Dispose() { try { Stop(); System.Threading.Thread.Sleep(250); if (output != null) { output.Kill(); output.Dispose(); } stream.Close(); stream.Dispose(); stream = AudioStream.NullStream; preloadStream.Close(); preloadStream.Dispose(); preloadStream = AudioStream.NullStream; AudioStreamFile.FreeBassPlugins(); AudioStreamFile.UnregisterBASS(); OutputASIO.Unload(); } catch { } }
public void DoReplayGainAnalysis() { try { Controller.ShowMessage("Starting volume leveling analysis..."); List <List <Track> > albums = partitionByAlbum(tracks); byte[] buffer = new byte[READ_BUFFER_SIZE]; float[] left = new float[READ_BUFFER_SIZE / 4]; float[] right = new float[READ_BUFFER_SIZE / 4]; int numSamples; foreach (List <Track> album in albums) { try { if (rga.InitGainAnalysis(album[0].SampleRate)) { foreach (Track t in album) { AudioStream stream = new AudioStreamFile(t, 0, new float[10], 10, false, ReplayGainMode.Off); while ((numSamples = stream.Read(buffer, 0, READ_BUFFER_SIZE)) > 0) { int inputBufferSize = numSamples / 4; for (int i = 0; i < inputBufferSize; i++) { left[i] = AudioStreamBass.from16Bit(buffer[i * 4 + 1] * 0x100 + buffer[i * 4]); right[i] = AudioStreamBass.from16Bit(buffer[i * 4 + 3] * 0x100 + buffer[i * 4 + 2]); } rga.AnalyzeSamples(left, right, inputBufferSize); if (cancel) { callback(); return; } } stream.Close(); t.ReplayGainTrack = rga.GetTrackGain(); numTracksDone++; Controller.ShowMessage(String.Format("{0}/{1}: Volume analyzed for '{2}'", numTracksDone.ToString(), numTracks.ToString(), t.ToShortString())); } float albumGain = rga.GetAlbumGain(); foreach (Track t in album) { t.ReplayGainAlbum = albumGain; } if (Setting.WriteReplayGainTags) { foreach (Track t in album) { t.ChangeType |= ChangeType.WriteTags; } TrackWriter.AddToUnsavedTracks(album); TrackWriter.Start(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } callback(); }