private void updateAudioEvent() { AudioAnalyzer aa = GetComponent <AudioAnalyzer>(); float bass = aa.bass; float treb = aa.treb; float vol = aa.vol; bool bassHit = aa.bassHit; bool trebHit = aa.trebHit; bool volHit = aa.volHit; mCs.SetFloat("uBass", bass); mCs.SetFloat("uTreb", treb); mCs.SetFloat("uVol", vol); mCs.SetBool("uBassHit", bassHit); mCs.SetBool("uTrebHit", trebHit); mCs.SetBool("uVolHit", volHit); mSurfaceMat.SetFloat("uVol", vol); // normal event shuffleNormal(bassHit); // rotation event shuffleRot(bassHit); }
public void TestMethod() { const double silence = 0.0001; var wavDataSmall = new float[] { 0.0001f, -0.8f, 0.05f, -0.05f, 0.2f, 0.4f, 1.0f, 0.0001f }; Bitmap png = AudioAnalyzer.DrawWaveformMono(wavDataSmall, new Size(1000, 600), 1, 1, 0, 44100); string fileName = String.Format("wave-small-dataset-{0}.png", 1); png.Save(fileName); // crop float[] wavDataSmallCropped = AudioUtils.CropAudioAtSilence(wavDataSmall, silence, false, 0); png = AudioAnalyzer.DrawWaveformMono(wavDataSmallCropped, new Size(1000, 600), 1, 1, 0, 44100); fileName = String.Format("wave-small-dataset-cropped{0}.png", 1); png.Save(fileName); // init audio system var audioSystem = BassProxy.Instance; float[] wavDataBig = BassProxy.ReadMonoFromFile(WAVE_INPUT_FILEPATH, 44100, 10, 0); png = AudioAnalyzer.DrawWaveformMono(wavDataBig, new Size(1000, 600), 2000, 1, 0, 44100); fileName = String.Format("wave-big-dataset-{0}.png", 1); png.Save(fileName); // crop float[] wavDataBigCropped = AudioUtils.CropAudioAtSilence(wavDataBig, silence, false, 0); png = AudioAnalyzer.DrawWaveformMono(wavDataBigCropped, new Size(1000, 600), 1, 1, 0, 44100); fileName = String.Format("wave-big-dataset-cropped{0}.png", 1); png.Save(fileName); }
public void AnalyzeSignal_KnownSignal_ReturnsExpectedValues() { var audioStream = new MemoryStream(); var audioGenerator = new AudioGenerator(audioStream); var fskAudioGenerator = new FskAudioGenerator(audioGenerator); fskAudioGenerator.GenerateAudio(_binaryFskAnalyzerSettings.BaudRate, _binaryFskAnalyzerSettings.SpaceFrequency, _binaryFskAnalyzerSettings.MarkFrequency, _bitManipulator.StringToBits(Resources.LoremIpsumTestString)); var audioAnalyzer = new AudioAnalyzer(audioStream, audioGenerator); var binaryFskAnalyzer = (IBinaryFskAnalyzer) new BinaryFskAnalyzer(audioAnalyzer, new ZeroCrossingsFrequencyDetector(), _binaryFskAnalyzerSettings); var results = binaryFskAnalyzer.AnalyzeSignal(); var result = binaryFskAnalyzer.AnalyzeSignal(); var bits = new List <bool>(); foreach (var frame in result.AnalysisFrames) { if (frame.Bit.HasValue == true) { bits.Add(frame.Bit.Value); } } var ascii = BitManipulator.BitsToString(bits); Assert.AreEqual(Resources.LoremIpsumTestString, ascii); }
public void AudioAnalyzer_Configure_With_NotPo2FFT_Throws() { Assert.ThrowsException <ArgumentException>(() => { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 400, 2047, false); }); }
public void AudioAnalyzer_Buffer_SequenceReadIsCorrect() { // Generate audio signal with steps after 600 frames, packaged in frame of length 800 frames. // Output frames should contain exactly steps var sut = new AudioAnalyzer(2400, 2, 48000, 600, 300, 2048, false); RegisterOutputHandler(sut); AudioFrame[] frames = new AudioFrame[3] { new AudioFrame(4 * 2 * 800), new AudioFrame(4 * 2 * 800), new AudioFrame(4 * 2 * 800) }; frames[0].Generate(2, 0, (frameIndex, channelIndex) => { return(frameIndex >= 600 ? 1.0f : 0.0f); }); frames[1].Generate(2, 800, (frameIndex, channelIndex) => { return(frameIndex >= 1200 ? 2.0f : 1.0f); }); frames[2].Generate(2, 1600, (frameIndex, channelIndex) => { return(frameIndex >= 1800 ? 3.0f : 2.0f); }); foreach (var frame in frames) { sut.ProcessInput(frame); } for (int outputFrameIndex = 0; outputFrameIndex < 4; outputFrameIndex++) { float expectedValue = (float)outputFrameIndex; Assert.AreEqual(expectedValue, outputFrames[outputFrameIndex].Peak[0], "Channel 0"); Assert.AreEqual(expectedValue, outputFrames[outputFrameIndex].Peak[1], "Channel 1"); } }
public void UpdateJellifier(ref double[] fftOutput) { int batchSize = fftOutput.Length / _binRange.Length; double[] bins = null; AudioAnalyzer.BinFFTOutput(ref fftOutput, ref bins, _binRange, sampleRate); for (int i = 0; i < _toManipulate.vertexCount - 1; ++i) { for (; i % batchSize < batchSize && i < _toManipulate.vertexCount; ++i) { float distToBe = (float)((bins[i / batchSize] / (float)fftOutput.Length)); distToBe = Mathf.Clamp(distToBe, 0.01f, float.MaxValue); distToBe += 0.5f; Vector3 currentDist = verts [i]; if (currentDist.magnitude != distToBe) { verts [i] = Vector3.Lerp(Vector3.zero, currentDist.normalized, distToBe); colors [i] = Color.Lerp(Color.green * 0.6f, Color.red * 2, distToBe - 0.5f); } } } _toManipulate.colors = colors; _toManipulate.vertices = verts; Vector3 rot = _filter.gameObject.transform.rotation.eulerAngles; rot.y += Time.deltaTime * 20; _filter.gameObject.transform.rotation = Quaternion.Euler(rot); float normalizedBassEnergy = Mathf.Clamp01((float)(bins [0] * 0.75f + bins [1] * 0.25f) / fftOutput.Length); _skyboxMat.SetColor("_SkyTint", Color.Lerp(Color.yellow, Color.red * 1.5f, normalizedBassEnergy)); _skyboxMat.SetColor("_GroundColor", Color.Lerp(Color.green * 0.25f, Color.blue * 0.25f, normalizedBassEnergy)); _skyboxMat.SetFloat("_Exposure", Mathf.Clamp(normalizedBassEnergy, 0.25f, 1.0f)); }
public void AudioAnalyzer_Sync_Performance() { var sut = new AudioAnalyzer(48000, 2, 48000, 800, 400, 2048, false); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); List <TimeSpan> outTimes = new List <TimeSpan>(); sut.Output += new Windows.Foundation.TypedEventHandler <AudioAnalyzer, VisualizationDataFrame>( (a, data) => { outTimes.Add(sw.Elapsed); } ); AudioFrame frame = new AudioFrame(24000 * 4 * 2); // 0.5 sec worth of audio data sw.Start(); sut.ProcessInput(frame); List <TimeSpan> durations = new List <TimeSpan>(); for (int i = 0; i < outTimes.Count(); i++) { durations.Add(outTimes[i].Subtract(i != 0 ? outTimes[i - 1] : TimeSpan.Zero)); } double avg = durations.Average((time) => { return(time.TotalMilliseconds); }); Logger.LogMessage($"Analyzer performance {avg}ms per run"); Assert.IsTrue(avg < 5); }
public void AnalyzeSong(string fileDirectory) { visualFacade.SetProgress("Loading Song...", 0.0f); SongFile songFile = MyAudioFileReader.ReadAudioFile(fileDirectory); visualFacade.SetSongFile(songFile); List <SongPropertyValues> songPropertyValuesList = new List <SongPropertyValues>(); visualFacade.SetProgress("Analyze...", 0.1f); AudioAnalyzer audioAnalyzer = new AudioAnalyzer(); audioAnalyzer.LoadAudioFromFile(fileDirectory); audioAnalyzer.Analyze(); songPropertyValuesList.Add(GetSingleBeatsSPV(audioAnalyzer.SongElements)); songPropertyValuesList.Add(GetHeldNoteSPV(audioAnalyzer.SongElements)); visualFacade.PlotSongPropertyValues(songPropertyValuesList); visualFacade.SetProgress("done :)", 1); }
public void AudioAnalyzer_Configure_SpectrumStepSetWithDownsample() { // As 2*(1600+800) > 3200 input will be downsampled by 2 var sut = new AudioAnalyzer(2400, 2, 96000, 1600, 800, 2048, false); Assert.AreEqual(96000.0f / 2048.0f / 2.0f, sut.SpectrumStep); }
public void AudioAnalyzer_Configure_With_ZeroStepThrows() { Assert.ThrowsException <ArgumentException>(() => { var sut = new AudioAnalyzer(1200, 2, 48000, 0, 0, 2048, false); }); }
public void AudioAnalyzer_Configure_With_BufferSizeLTOL_plus_StepThrows() { Assert.ThrowsException <ArgumentException>(() => { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 401, 2048, false); }); }
private void Start() { //Get components audioController = GameObject.Find("AudioController"); audioAnalyzer = audioController.GetComponent <AudioAnalyzer>(); spectrumAnalyzer = audioController.GetComponent <AudioAnalyzer>().spectrumAnalyzer; Vector3 topLeft = getScreenTopLeft(); Vector3 bottomRight = getScreenBottomRight(); float screenXlength = bottomRight.x - topLeft.x; //Generate new wave GameObject floor = new GameObject("floor"); floor.AddComponent <MeshRenderer>(); floor.AddComponent <MeshFilter>(); floor.AddComponent <MeshCollider>(); floor.AddComponent <floor>(); floor.GetComponent <MeshFilter>().mesh = CreatePlaneMesh(); floor.GetComponent <MeshFilter>().mesh.SetVertices(vertexList); floor.GetComponent <MeshRenderer>().material = floorMaterial; floor.GetComponent <MeshCollider>().sharedMesh = floor.GetComponent <MeshFilter>().mesh; floor.transform.position = new Vector3(topLeft.x + screenXlength / 2, 0, 0); previousFrameGameObject = floor; }
public static GameScreen CreateImportSongGameScreen(MyGameWindow gameWindow, string fileDirectory, bool removeSingleBeats = false, bool removeHeldNotes = false, string levelName = "") { if (!System.IO.File.Exists(fileDirectory)) { Console.WriteLine("FILE NOT FOUND"); return(null); } SongElements songElements = AudioAnalyzer.GetSongElements(fileDirectory); if (removeSingleBeats) { songElements.SingleBeats.Clear(); } if (removeHeldNotes) { songElements.HeldNotes.Clear(); } Level level = LevelGenerator.GenerateLevel(songElements); level.Name = levelName; GameScreen gameScreen = new GameScreen(gameWindow, level, fileDirectory); return(gameScreen); }
public void AudioAnalyzer_ProcessInput_IsFirstOutputFrameTimeCorrect() { var sut = new AudioAnalyzer(1600, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.ProcessInput(inputFrame); Assert.AreEqual(TimeSpan.FromSeconds(1), outputFrames.First().Time); }
public void AudioAnalyzer_ProcessInput_IsOutputFrameDurationCorrect() { var sut = new AudioAnalyzer(1600, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.ProcessInput(inputFrame); Assert.AreEqual(outputFrames.First().Duration, TimeSpan.FromTicks(166666)); }
/// <summary> /// 分析波形 /// </summary> /// <param name="testData">测试波形</param> /// <param name="sampleDelay">测试数据前面的无效数据长度</param> /// <param name="dataSize">有效测试波形长度</param> public override void Analyze(double[] testData, uint sampleDelay = 0, uint dataSize = 0) { double[] validTestData = GetValidTestData(testData, ref dataSize, sampleDelay); uint pathDelay = AudioAnalyzer.AnalyzePathDelay(validTestData, RefWaveform.GetWaveData()); //analyzer.SetDataDelayCounts(pathDelay); base.Analyze(validTestData, 0, 0); }
// ***************************************************** // MONO BEHAVIOUR OVERRIDE // ***************************************************** // Start is called before the first frame update void Start() { // State // Cache userConfigs = FindObjectOfType <UserConfigs>(); audioAnalyzer = FindObjectOfType <AudioAnalyzer>(); }
public void AudioAnalyzer_ProcessInput_GeneratesOneOutputFrame() { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.ProcessInput(inputFrame); Assert.AreEqual(1, outputFrames.Count); }
public void AudioAnalyzer_ProcessInput_IsSpectrumNotNull() { var sut = new AudioAnalyzer(1600, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.ProcessInput(inputFrame); Assert.IsNotNull(outputFrames.First().Spectrum); }
public void AudioAnalyzer_SetOutput() { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 400, 2048, false); sut.Output += new Windows.Foundation.TypedEventHandler <AudioAnalyzer, VisualizationDataFrame>( (analyzer, frame) => { } ); }
void Update() { for (int i = 0; i < mats.Length; i++) { mats[i].color = Color.Lerp(low, high, AudioAnalyzer.GetScaledOutput(band, maxInput, .1f, 1f)); } rend.materials = mats; }
void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { SceneManager.LoadScene(0); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { SceneManager.LoadScene(1); } else if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } amplitude = AudioAnalyzer.GetScaledOutput(0, Config.limits.x, Config.limits.y); //currentPitch = float.MinValue; //if (amplitudeAverage > Config.AmplitudeMin) //{ // float out0 = AudioAnalyzer.GetScaledOutput(0, 0f, 1f); // float out1 = AudioAnalyzer.GetScaledOutput(1, 0f, 1f); // float out2 = AudioAnalyzer.GetScaledOutput(2, 0f, 1f); // float out3 = AudioAnalyzer.GetScaledOutput(3, 0f, 1f); // float out4 = AudioAnalyzer.GetScaledOutput(4, 0f, 1f); // float out5 = AudioAnalyzer.GetScaledOutput(5, 0f, 1f); // float out6 = AudioAnalyzer.GetScaledOutput(6, 0f, 1f); // float out7 = AudioAnalyzer.GetScaledOutput(7, 0f, 1f); // float out8 = AudioAnalyzer.GetScaledOutput(8, 0f, 1f); // float out9 = AudioAnalyzer.GetScaledOutput(9, 0f, 1f); // currentPitch = out0 * 4.5f; // 12.5f Max // currentPitch = currentPitch + out1 * 3.5f; // currentPitch = currentPitch + out2 * 2.5f; // currentPitch = currentPitch + out3 * 1.5f; // currentPitch = currentPitch + out4 * 0.5f; // currentPitch = currentPitch - out5 * 0.5f; // currentPitch = currentPitch - out6 * 1.5f; // currentPitch = currentPitch - out7 * 2.5f; // currentPitch = currentPitch - out8 * 3.5f; // currentPitch = currentPitch - out9 * 4.5f; // -12.5f Min // currentPitch = (currentPitch + 12.5f) / 25f; // } //currentPitchHeight = Config.PitchSpan * currentPitch; if (amplitude > Config.AmplitudeMin) { currentPitchHeight = Config.PitchSpan * amplitude; } else { currentPitchHeight = float.MinValue; } Debug.Log("AmplitudeAvg: " + amplitude + " currentPitchHeight: " + currentPitchHeight); }
public void AudioAnalyzer_ProcessInput_SetIsSuspendedStopsAsyncProcessing() { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 400, 2048, true); RegisterOutputHandler(sut); sut.IsSuspended = true; sut.ProcessInput(inputFrame); Assert.AreEqual(0, outputFrames.Count); }
public void AudioAnalyzer_ProcessInput_IsSecondOutputFrameTimeCorrect() { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.ProcessInput(inputFrame); sut.ProcessInput(inputFrame); Assert.AreEqual(TimeSpan.FromTicks(10166666), outputFrames[1].Time); }
public void AudioAnalyzer_IsCloseable() { var sut = new AudioAnalyzer(1200, 2, 48000, 800, 400, 2048, false); using (sut) { } sut.Dispose(); // Second close should also succeed }
public void AudioAnalyzer_ProcessInput_IsTimeCorrectAfterFlushWithSeed() { var sut = new AudioAnalyzer(1600, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.Flush(480000); sut.ProcessInput(inputFrame); Assert.AreEqual(outputFrames.First().Time, TimeSpan.FromSeconds(10)); }
public void AudioAnalyzer_ProcessInput_IsRmsCorrectForSawTooth() { var sut = new AudioAnalyzer(2400, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.AnalyzerTypes = AnalyzerType.RMS; sut.ProcessInput(inputFrame); Assert.AreEqual((float)0.1f / Math.Sqrt(3), outputFrames.First().RMS[1], 2e-5); }
public void AudioAnalyzer_ProcessInput_AnalyzerTypeCleared_IsPeakNull() { var sut = new AudioAnalyzer(1600, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.AnalyzerTypes = AnalyzerType.None; sut.ProcessInput(inputFrame); Assert.IsNull(outputFrames.First().Peak); }
public void AudioAnalyzer_Buffer_WrapOverEnd() { var sut = new AudioAnalyzer(2400, 2, 48000, 700, 0, 2048, false); RegisterOutputHandler(sut); sut.ProcessInput(inputFrame); sut.ProcessInput(inputFrame); Assert.AreEqual(2, outputFrames.Count); }
public void AudioAnalyzer_ProcessInput_IsPeakCorrectForSawTooth() { var sut = new AudioAnalyzer(1600, 2, 48000, 800, 400, 2048, false); RegisterOutputHandler(sut); sut.AnalyzerTypes = AnalyzerType.Peak; sut.ProcessInput(inputFrame); Assert.AreEqual(0.1f, outputFrames.First().Peak[1]); }
void Start() { audio_ = audioObject.GetComponent<AudioAnalyzer>(); if (audio_ == null) { audio_ = audioObject.AddComponent<AudioAnalyzer>(); } cyalume_ = cyalumeObject.GetComponent<CyalumeController>(); if (cyalume_ == null) { cyalume_ = cyalumeObject.AddComponent<CyalumeController>(); } }