/// <summary>
        /// Reads the waveform data from file.
        /// </summary>
        /// <returns>An instance of the waveform class read from file.</returns>
        /// <param name="fileName">Xml file name.</param>
        public static Waveform ReadWaveformData(string fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Waveform));
            FileStream    stream     = new FileStream(fileName, FileMode.Open);
            Waveform      newWave    = (Waveform)serializer.Deserialize(stream);

            stream.Close();
            return(newWave);
        }
        /// <summary>
        /// Writes the waveform data to xml file.
        /// </summary>
        /// <param name="waveform">Waveform to write to file.</param>
        public static void WriteWaveformData(Waveform waveform)
        {
            if (!Directory.Exists(filePath)) {
                Directory.CreateDirectory(filePath);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(Waveform));
            FileStream stream = new FileStream(filePath + "/Waveform_" + waveform.fileName + ".xml", FileMode.Create);
            serializer.Serialize(stream, waveform);
            stream.Close();
        }
        /// <summary>
        /// Writes the waveform data to xml file.
        /// </summary>
        /// <param name="waveform">Waveform to write to file.</param>
        public static void WriteWaveformData(Waveform waveform)
        {
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(Waveform));
            FileStream    stream     = new FileStream(filePath + "/Waveform_" + waveform.fileName + ".xml", FileMode.Create);

            serializer.Serialize(stream, waveform);
            stream.Close();
        }
Exemple #4
0
 /// <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);
 }
Exemple #5
0
        /// <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);
        }
        //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
        }