Example #1
0
        /// <summary>
        /// Compute the spectral flux data for beat analysis
        /// </summary>
        /// <param name="bmc">BeatmapContainer of the song to analyze</param>
        /// <param name="clipData">AudioClipData of the song to analyze</param>
        /// <returns>The SpectralFluxData of the analyzed song</returns>
        public static SpectralFluxData AnalyzeAudio(BeatmapContainer bmc, AudioClipData clipData)
        {
            if (!new DirectoryInfo(Application.streamingAssetsPath + "/SpectrumData/").Exists)
            {
                Directory.CreateDirectory(Application.streamingAssetsPath + "/SpectrumData/");
            }

            SpectralFluxData spectralFluxData;

            if (new FileInfo(Application.streamingAssetsPath + "/SpectrumData/" + bmc.sourceFile + ".json").Exists)
            {
                StreamReader reader = new StreamReader(Application.streamingAssetsPath + "/SpectrumData/" + bmc.sourceFile + ".json");
                spectralFluxData = JsonConvert.DeserializeObject <SpectralFluxData>(reader.ReadToEnd());
                reader.Close();
            }
            else
            {
                BeatAnalyzer analyzer = new BeatAnalyzer(clipData);
                spectralFluxData = analyzer.GetFullSpectrum();
                analyzer         = null;

                StreamWriter writer = new StreamWriter(Application.streamingAssetsPath + "/SpectrumData/" + bmc.sourceFile + ".json");
                writer.Write(JsonConvert.SerializeObject(spectralFluxData));
                writer.Close();
            }

            return(spectralFluxData);
        }
Example #2
0
    public void SetSong(int id, string path)
    {
        string extension = IO.Path.GetExtension(path);
        bool   isAudio   = BeatmapLoader.SupportedAudioFormats.Contains <string>(extension);
        bool   isBeatmap = (extension == BeatmapLoader.BeatmapFileFormat);

        if (isAudio || isBeatmap)
        {
            string audioFile;
            string sourceFile;
            if (isAudio)
            {
                BeatmapContainer = BeatmapLoader.CreateBeatmapFromAudio(path);
                audioFile        = sourceFile = path;
            }
            else
            {
                BeatmapContainer = BeatmapLoader.LoadBeatmapFile(path);
                audioFile        = IO.Path.Combine(BeatmapContainer.directory, BeatmapContainer.bm.AudioFile);
                sourceFile       = BeatmapContainer.sourceFile;
            }

            this.id          = id;
            Thumbnail.sprite = null;
            TagLib.File tfile = TagLib.File.Create(audioFile);
            SongName            = tfile.Tag.Title != null ? tfile.Tag.Title : IO.Path.GetFileNameWithoutExtension(sourceFile);
            ArtistName          = tfile.Tag.FirstPerformer;
            DifficultyText.text = "N/A";
            //Difficulty.text = Math.Round(BeatmapContainer.bm.Metadata.Difficulty, 1).ToString();
            //Difficulty.color = Color.Lerp(Color.green, Color.red, BeatmapContainer.bm.Metadata.Difficulty / 5f);
            DurationText.text = tfile.Properties.Duration.ToString(@"mm\:ss");
        }
    }
Example #3
0
        private void Load(QsorConfigManager configManager)
        {
            var beatmapStorage = Storage.GetStorageForDirectory($"./Songs/{configManager.Get<int>(QsorSetting.BeatmapSetId)}");

            _beatmapContainer = BeatmapManager.LoadBeatmap(beatmapStorage, configManager.Get <string>(QsorSetting.BeatmapFile)); // TODO: Remove

            AddInternal(_beatmapContainer);
        }
    private void LoadBeatmap()
    {
        string path = BeatmapLoader.SelectBeatmapFile();

        if (path != null)
        {
            BeatmapContainer bmc = BeatmapLoader.LoadBeatmapFile(path);
            AudioClipData    cd  = BeatmapLoader.LoadBeatmapAudio(bmc);
            audioPlayer.clip = BeatmapLoader.CreateAudioClipFromData(cd);
            bm = bmc.bm;
        }
    }
Example #5
0
    public static AudioClipData LoadBeatmapAudio(BeatmapContainer bmc)
    {
        if (bmc == null)
        {
            throw new ArgumentNullException(nameof(bmc));
        }

        if (bmc.directory == null)
        {
            throw new NullReferenceException();
        }

        if (bmc.bm.AudioFile == null)
        {
            throw new NullReferenceException();
        }

        return(LoadAudioFile(Path.Combine(bmc.directory, bmc.bm.AudioFile)));
    }