private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var flag = false; for (var i = 0; i < _files.Length; i++) { if (backgroundWorker1.CancellationPending) { e.Cancel = true; break; } var fileName = _files[i]; if (WaveformData.Analysis(fileName)) { flag = true; backgroundWorker1.ReportProgress(i, fileName); } else { backgroundWorker1.ReportProgress(i); } } if (!flag) { throw new Exception("Mismatched files!"); } }
public bool CanParse(string filePath, DateTime fileCreationTime) { try { string folderPath = Path.GetDirectoryName(filePath); foreach (string waveformDataFile in Directory.EnumerateFiles(folderPath)) { using (FileStream fileStream = File.OpenRead(waveformDataFile)) using (MemoryStream emcbStream = new MemoryStream()) { fileStream.CopyTo(emcbStream); if (waveformDataFile.EndsWith("waveform")) { WaveformData.Add(emcbStream.ToArray()); } else if (waveformDataFile.EndsWith("fastRMS")) { FastRMSData.Add(emcbStream.ToArray()); } } } return(true); } catch { return(false); } }
private void Start() { WaveformType = Settings.Instance.Waveform; waveformData = new WaveformData(); audioManager.SetSecondPerChunk(atsc.GetSecondsFromBeat(BeatmapObjectContainerCollection.ChunkSize)); spectroParent.localPosition = new Vector3(0, 0, -atsc.offsetBeat * EditorScaleController.EditorScale * 2); if (WaveformType > 0) { StartCoroutine(GenerateAllWaveforms()); } else { gameObject.SetActive(false); } }
public void Update_waveform_when_changing_source() { var ctx = new ContextFor <WaveformDisplayViewModel>(); var sut = ctx.BuildSut(); var uri = new Uri("my://source/"); var getWaveform = ctx.For <IGetWaveform>(); var waveform = new WaveformData(TimeSpan.FromSeconds(2), new[] { new PeakInfo(-1f, 1) }); getWaveform.For(uri).Returns(waveform); sut.Source = uri; getWaveform.Received().For(uri); sut.CurrentStreamTime.Should().BeCloseTo(DateTime.UtcNow, 200); sut.Duration.Should().Be(waveform.Duration.TotalSeconds); }
// We use the unity api on the main thread to pull data to be processed in the background public void Begin(bool is3d, Gradient spectrogramHeightGradient, AudioClip audioClip, WaveformData waveformData, AudioTimeSyncController atsc, int chunkSize) { this.spectrogramHeightGradient = spectrogramHeightGradient; this.is3d = is3d; this.waveformData = waveformData; this.atsc = atsc; this.chunkSize = chunkSize; numChannels = audioClip.channels; numTotalSamples = audioClip.samples; clipLength = audioClip.length; sampleRate = audioClip.frequency; multiChannelSamples = new float[numTotalSamples * numChannels]; audioClip.GetData(multiChannelSamples, 0); waveformData.Chunks = (int)Math.Ceiling(clipLength / secondPerChunk); // How many audio samples wide a column is, we will likely use more samples // than the width to perform the FFT which has a smoothing effect if (is3d) { sampleOffset = secondPerChunk / ColumnsPerChunk * sampleRate; waveformData.InitBandVolumes(ColumnsPerChunk, _bands.Length - 1); } else { int samples = (int)GetSampleCount() / 2; float samplesPerChunk = sampleRate * secondPerChunk; ColumnsPerChunk = (int)samplesPerChunk / samples; sampleOffset = samplesPerChunk / ColumnsPerChunk; waveformData.InitBandVolumes(ColumnsPerChunk, samples + 1); } Debug.Log("WaveformGenerator: Starting Background Thread"); Thread bgThread = new Thread(PreProcessData); backgroundThreads.Add(bgThread); bgThread.Start(); }
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); }
/// <summary> /// This gets a block of data and saves it to specified file. /// </summary> /// <param name="awg"></param> /// <param name="wfmName"></param> /// <param name="filePath"></param> /// <param name="dataType"></param> /// <param name="startIndex"></param> /// <param name="blockSize"></param> // public void TransferWaveformDataToPath(IAWG awg, string wfmName, string filePath, WaveformData dataType, public void TransferWaveformDataToPath(IAWG awg, string wfmName, WaveformData dataType, string startIndex = "", string blockSize = "") { /*string floatingPoints = */ awg.GetWListWaveformData(wfmName, startIndex, blockSize); /* File.WriteAllText(filePath, floatingPoints); */ }
/// <summary> /// Assumes that data is floating point and needs to be converted in to a block to be transferred.<para> /// It does not take apart the original file and break into blocks.</para><para> /// The parameters passed are the parameters to be sent in the PI command to where this</para><para> /// block goes in the destination waveform.</para> /// </summary> /// <param name="awg"></param> /// <param name="wfmName"></param> /// <param name="filePath"></param> /// <param name="dataType"></param> /// <param name="startIndex"></param> /// <param name="blockSize"></param> public void TransferWaveformDataFromPath(IAWG awg, string wfmName, string filePath, WaveformData dataType, string startIndex = "", string blockSize = "") { string blockOfData = ""; try { if (File.Exists(filePath)) { // Get a line of text. It assumes(?) that each line has 3 fields. // The first field is the analog value. For the first pass, this is what we are interested in. foreach (string line in File.ReadLines(filePath)) { if (dataType == WaveformData.AnalogOnly) { string[] divided = line.Split(','); if (blockOfData != "") { blockOfData += ","; } blockOfData += divided[0]; } } } else { Assert.Fail("File " + filePath + " does not exist"); } // A string of floats (first pass at implementation) has been extracted. // Off we go to the next step awg.SetWListWaveformData(wfmName, startIndex, blockSize, blockOfData); } catch (Exception ex) { Assert.Fail("Reading file has failed because " + ex.Message); } }