public void CreateTracker() { if (string.IsNullOrEmpty(songDataJsonString) || !audioSource.clip) { UIEventManager.FireAlert("NOT ALL FILES PRESENT", "ERROR"); return; } trackView.SetActive(true); beatSynchroniser.bpm = (float)songDataFromJson.bpm; beatSynchroniser.startDelay = 1; beatCounter.beatValue = SynchronizerData.BeatValue.SixteenthBeat; sixteenNoteToSecondsSize = (60f / (float)songDataFromJson.bpm) / 4f; onePixelToSeconds = sixteenNoteToSecondsSize / sixteenNoteToPixelSize; Debug.Log("sixteenNoteToSecondsSize " + sixteenNoteToSecondsSize); Debug.Log("onePixelToSeconds " + onePixelToSeconds); //populate words //float pozX; //int numOfwords = songDataFromJson.words.Length; //for(int i = 0; i< numOfwords; i++) //{ // pozX = float.Parse(songDataFromJson.timestamps[i]) / onePixelToSeconds; // Debug.Log(pozX); // Instantiate(wordPrefab, wordsHolder.transform, false); // wordPrefab.text = songDataFromJson.words[i].ToString(); // wordPrefab.rectTransform.anchoredPosition= new Vector3(pozX, 0, 0); //} beatCounter.StartCountingBeats(); beatSynchroniser.StartSynchronisedMusic(); rawImg.texture = AudioWaveForm(audioSource.clip, (int)Mathf.Floor(rawImg.rectTransform.rect.width), (int)Mathf.Floor(rawImg.rectTransform.rect.height), new Color(210, 210, 210)); debugString = string.Empty; //float samplesPerQuarterNote = ((float)songDataFromJson.bpm / 60) * 44100; float samplesPerQuarterNote = Mathf.CeilToInt(44100 / ((float)songDataFromJson.bpm / 60)); float samplesPerBar = samplesPerQuarterNote * 4; float barInSong = Mathf.Ceil((float)audioSource.clip.samples / (float)samplesPerBar); debugString = string.Format("Song name: {0} \nSong BPM: {1} \nTotal Samples: {2} \nSamlpes per 1/4 note: {3} \nSamples per bar: {4} \nTotal Bar Count: {5} \nSong Time: {6} sec", songDataFromJson.songname, songDataFromJson.bpm, audioSource.clip.samples, samplesPerQuarterNote, samplesPerBar, barInSong, audioSource.clip.length); debugText.text = debugString; }