- Home /
Is it possible to have a spectrum analyzer display for each song in a playlist?
This is going to sound a little complicated but I am wondering if it is possible for me to have a spectrum analyzer display running for each song being played in a music player. I'm not very good with code. I think I have seen it done but I'm not sure how to go about making one or if it is even possible. This is an example of the type of thing I am trying to create, I'm wondering if I could have a spectrum analyzer display in the middle of the knight head logos or maybe even as a closable pop up window that could be called to display with a texture GUI button. Is this possible? And if so how would I go about doing this?
Answer by Graham-Dunnett · Nov 26, 2014 at 05:17 PM
You'll have to forgive me but I'm not really sure what that does. I'll try to see if I can show an example: Something like this that could be displayed in the middle or top of my interface when any given song is being played.
This is another good example of the look and feel I am trying to go with: 2nd YouTube Video sample
These are not bad but is there a descent tutorial out there anywhere on how to make one that will play for each song in a playlist.
using UnityEngine;
using System.Collections;
public class Spectrum : $$anonymous$$onoBehaviour {
public AudioSource asource;
public int channel;
float[] spectrum;
float[] volume;
public int numSamples;
public GameObject enem;
// Use this for initialization
void Start () {
volume = new float[numSamples];
spectrum = new float[numSamples];
for (int i=1; i<255; i++)
{
GameObject enemyClone = Instantiate(enem,new Vector3(i,0,0), transform.rotation) as GameObject ;
enemyClone.name = "sp"+i;
}
}
// Update is called once per frame
void Update () {
asource.GetOutputData(volume, channel);
asource.GetSpectrumData(spectrum, channel, FFTWindow.Rectangular);
for (int i=0; i<255; i++) {
string sp = "sp"+(i+1);
GameObject sp1 = GameObject.Find(sp);
sp1.transform.localScale= new Vector3(1,200*spectrum[i],1);
sp1.GetComponent<$$anonymous$$eshRenderer>().material.color= new Color(100*spectrum[i],1f/(20*spectrum[i]),1f/(20*spectrum[i]),1);
}
/*GameObject sp1 = GameObject.Find("sp1");
sp1.transform.localScale= new Vector3(1,100*spectrum[0],1);
GameObject sp2 = GameObject.Find("sp2");
sp2.transform.localScale= new Vector3(1,100*spectrum[1],1);
GameObject sp3 = GameObject.Find("sp3");
sp3.transform.localScale= new Vector3(1,100*spectrum[2],1);
GameObject sp4 = GameObject.Find("sp4");
sp4.transform.localScale= new Vector3(1,100*spectrum[3],1);
GameObject sp5 = GameObject.Find("sp5");
sp5.transform.localScale= new Vector3(1,100*spectrum[4],1);
GameObject sp6 = GameObject.Find("sp6");
sp6.transform.localScale= new Vector3(1,100*spectrum[5],1);
GameObject sp7 = GameObject.Find("sp7");
sp7.transform.localScale= new Vector3(1,100*spectrum[6],1);
GameObject sp8 = GameObject.Find("sp8");
sp8.transform.localScale= new Vector3(1,100*spectrum[7],1);
GameObject sp9 = GameObject.Find("sp9");
sp9.transform.localScale= new Vector3(1,100*spectrum[8],1);
GameObject sp10 = GameObject.Find("sp10");
sp10.transform.localScale= new Vector3(1,100*spectrum[9],1);
GameObject sp11 = GameObject.Find("sp11");
sp11.transform.localScale= new Vector3(1,100*spectrum[10],1);
GameObject sp12 = GameObject.Find("sp12");
sp12.transform.localScale= new Vector3(1,100*spectrum[11],1);
GameObject sp13 = GameObject.Find("sp13");
sp13.transform.localScale= new Vector3(1,100*spectrum[12],1);
GameObject sp14 = GameObject.Find("sp14");
sp14.transform.localScale= new Vector3(1,100*spectrum[13],1);
*/
}
}
Your answer
Follow this Question
Related Questions
What's a great way to make a custom information window pop up 1 Answer
problem with a pop-up window 1 Answer
GUI Window problem 2 Answers
Make a pop up window work on a key press 1 Answer
GUI Window on GameObject location? 1 Answer