コード例 #1
0
ファイル: Analyzer.cs プロジェクト: DomCristaldi/Coda
        /// <summary>
        /// Writes waveform to xml file.
        /// </summary>
        /// <param name="data">Raw data from FFT.</param>
        /// <param name="name">Xml file name.</param>
        public static void WaveformToFile(double[] data, string name)
        {
            Waveform newWave = new Waveform(data, name);

            WaveformSerializer.WriteWaveformData(newWave);
        }
コード例 #2
0
        //UPDATE LOOP FOR UNITY EDITOR
        void OnGUI()
        {
            int waveformWidth = (int)(position.width - _controlsWidth);

            _controlsPos = new Rect(0, 0, _controlsWidth, 200);
            _waveformPos = new Rect(_controlsWidth, 0,
                                    waveformWidth, 300);

            HandleWindowInstantiation();    //make sure the UI exists

            _waveformMarkupWindow.Setup(_waveformPos);


            //read in xml beatmap file if it exists for the supplied audio file
            if (_analysisControlWindow.musicToAnalyze != _prevAudioClip)              //only load if new

            //ANALYZER SONG IF ONE IS ASSIGNED IN THE EDITOR GUI
            {
                if (_analysisControlWindow.musicToAnalyze != null)
                {
                    _filePath = WaveformSerializer.filePath + "/Waveform_" + _analysisControlWindow.musicToAnalyze.name + ".xml"; //location of possibly saved Wavefrom

                    if (System.IO.File.Exists(_filePath))                                                                         //retrieve the Waveform if we computed one in the past
                    {
                        Waveform newWave = WaveformSerializer.ReadWaveformData(_filePath);
                        _waveformMarkupWindow.waveform = newWave.data;
                    }
                    else
                    {
                        _waveformMarkupWindow.waveform = null;
                    }

                    _filePath = BeatMapSerializer.filePath + "/BeatMap_" + _analysisControlWindow.musicToAnalyze.name + ".xml"; // location of possibly saved Beatmap

                    if (System.IO.File.Exists(_filePath))                                                                       //load Beatmap for current song if it could be found
                    {
                        BeatMap newMap = BeatMapSerializer.BeatMapReader.ReadBeatMap(_filePath);
                        _waveformMarkupWindow.beatmap = newMap;
                    }
                    else
                    {
                        _waveformMarkupWindow.beatmap = null;
                    }
                }

                //NO SONG WAS ASSIGNED
                else
                {
                    _waveformMarkupWindow.waveform = null;
                    _waveformMarkupWindow.beatmap  = null;
                }

                _prevAudioClip = _analysisControlWindow.musicToAnalyze;                //audio clip from previous frame
            }


            //DRAW SUBWINDOWS
            HandleDrawingSubwindow(_analysisControlWindow,
                                   _waveformMarkupWindow);

            /*
             * //waveformMarkupWindow.DrawWindowDebug();//shows borders of Subwinows
             *
             * if (waveformMarkupWindow.IsInSubwindow(Event.current.mousePosition)) {//check if we can click inside a subwindow
             *  //Debug.LogFormat("waveform has it");
             * }
             */

            //USER HAS TRIGGERED ANALYSIS VIA ANALYZER CONTROLLER SUBWINDOW
            if (_analysisControlWindow.triggerAnalysis == true)
            {
                _analysisControlWindow.triggerAnalysis = false;

                //ANALYSIS
                //feed Analyzer the user-defined audio file to get audio as frequency data
                double[] waveformData = _analyzer.ProcessAudio(_analysisControlWindow.musicToAnalyze,
                                                               _analysisControlWindow.numPartitions,
                                                               _analysisControlWindow.dataAbstractionOverlapPercent);
                //feed in frequency data to get a Beatmap
                BeatMap beats = _analyzer.AnalyzeData(waveformData,
                                                      _analysisControlWindow.musicToAnalyze,
                                                      _analysisControlWindow.threshold);

                //SERIALIZATOIN
                AnalyzerTools.WaveformToFile(waveformData, _analysisControlWindow.musicToAnalyze.name);
                AnalyzerTools.BeatMapToFile(beats, _analysisControlWindow.musicToAnalyze.name);

                //DRAWING
                _waveformMarkupWindow.waveform = waveformData;
                _waveformMarkupWindow.beatmap  = beats;
            }

            Repaint();    //force GUI to draw every update even if not clicked on
        }