public BeatMap(bga_settings bga_settings, song_info_struct song_info, song_meta_struct song_meta, string songFilePath) { this.song_meta = song_meta; this.bga_settings = bga_settings; this.song_info = song_info; this.state = STATE.SAMPLES_LOADED; //this.name = name; this.fileName = song_meta.title + "~" + song_meta.artist + "~" + song_meta.album + ";" + bga_settings.rng_seed.ToString() + ".dat"; this.songFilePath = songFilePath; this.timesPlayed = 0; laneObjectStore = new List <LaneObject>(); scoreboard = new List <WinDataClass>(); }
private IEnumerator getAudioClipFromPath(string path) { //see https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestMultimedia.GetAudioClip.html // AudioType audioType; // #if UNITY_ANDROID // audioType = AudioType.MPEG; //for android use MPEG (.mp3) // #else // audioType = AudioType.OGGVORBIS; //for testing on windows use OGGVORBIS (.ogg) since windows does not have mpeg codec native // #endif //Debug.Log(audioType); using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + path, BGACommon.AUDIO_TYPE)) { yield return(www.Send()); if (www.isNetworkError) { Debug.Log("err"); Debug.Log(www.error); //state = STATE.AUDIO_CLIP_ERROR; } else { AudioClip inputAudioClip = DownloadHandlerAudioClip.GetContent(www); //Replace song info with new song info that is created from inputAudioClip, and set samples (normally we do not keep samples when saving (because they are 70+mb)) song_info_struct song_i = new song_info_struct(inputAudioClip); song_i.samples = new float[song_i.sampleCount * song_i.channels]; song_i.sampleLength = song_info.length / (float)song_i.sampleCount; inputAudioClip.GetData(song_i.samples, 0); this.song_info = song_i; Debug.Log("Loaded"); state = STATE.SAMPLES_LOADED; //state = STATE.AUDIO_CLIP_LOADED; //callBGA(ref audioClip); //bga.StartBGA(ref audioClip); } } }
public void StartBGA(ref AudioClip audioClip, ref WebInfo webInfo, bga_settings settings, song_meta_struct song, string songFilePath) { this.songFilePath = songFilePath; this.song_meta = song; if (this.state != STATE.READY) { throw new Exception("Cannot start the beat generating algorithim if it is already being run! State: " + this.state); } this.state = STATE.ACTIVE; Debug.Log("Threshold, multiplier:"); Debug.Log(settings.threshold_time); Debug.Log(settings.threshold_multiplier); this.settings = settings; if (settings.rng_seed == 0) { this.settings.rng_seed = generateNewRandomSeed(); Debug.Log(this.settings.rng_seed); } bga_random = new System.Random(settings.rng_seed); song_info = new song_info_struct(audioClip); song_info.samples = new float[song_info.sampleCount * song_info.channels]; song_info.sampleLength = song_info.length / (float)song_info.sampleCount; //GetData returns samples for both the L(eft) and R(ight) channels //audioClip.GetData(song_info.samples, 0); song_info.samples = webInfo.samples; output = new output_struct(); persistentDataPath = Application.persistentDataPath; //We can't use unity specific calls in the bga thread, and we need this variable for later //Create the background thread and run the BGA algorithim //The algorthim will have access to all the public structs Debug.Log("make thread"); //Thread BGAThread = new Thread(new ThreadStart(algorithimWrapper)); //BGAThread.Start(); // crash the ui thread #yolo algorithimWrapper(); }