Showing posts with label 3DMusicVisualiser. Show all posts
Showing posts with label 3DMusicVisualiser. Show all posts

Saturday, 23 November 2013

Sorry for the delay!

Sorry for the delay, I've had quite a bit of stuff going on recently. I have still been working on the visualiser though I just haven't found time to blog about it. :)

I left off last time by saying I'll try and fill some arrays with data from the AudioSource.GetOutputData(); function and use them to transform some objects, so that's exactly what I did. I created an array of values and created a couple hundred cubes to transform with the values. Each frame I iterate through each value in the array, while iterating through each cube in the scene, I then transform the current cube's y scale by the value in the array.

Here's the code :

void Update()
{
audioSource.GetOutputData(outputData[],channel,window);
for(int i = 0; i <= outputData.Length; i++)
       {
cubes[i].transform.localScale = new Vector3(1,outputData[i] * modifer,1);
       }
}

Simple right? :D

This produced some strange, unexpected results. I expected to see a wave form constantly changing to the sound of the music. What I saw was that to some extent near the start of the wave however towards the end the cubes seemed to 'stick' or stop reacting for a while.

Here's a video and picture I took of my visualiser at this stage.



If you watched the video you can see what I mean. It doesn't look right.

I played around with some variables a bit because I was sure my code was working as expected, I mean look at the start of the wave. After playing around for a while I tried making the number of cubes and sample size the same. Instantly I noticed a difference, now every cube represented one value from the sample, constantly. What I could see was a perfect wave form as expected.

Unfortunately, I don't have any pictures of this I was so excited by how amazing the waveform looked I had to keep working on making it look more awesome! I had an idea from the start to make my waveform into a circle so I tried that. I used the standard Cartesian circle equation :

(x-a)^2 + (y-b)^2 = r^2

and wrote a method in my sampler script to place my cubes in a circle. The circle equation provides both a plus and minus value so I decided to place two cubes at a time after calculating each point on the circle.

void orderCubes(int radius, GameObject[] array)
{
      int totalLoopCount = 0;
      int xloopCount = -64;
      float yloopCount = 0;
      float Center = array.Length / 4;
      float r2 = radius * radius;
      while(xloopCount <= array.Length)
      {
               if (alterCube)
               {
                         yloopCount = (Mathf.Sqrt(r2 - xloopCount * xloopCount));
                         array[i] = Instantiate(cubeObj, new Vector3(Center + xloopCount, 0, Center + yloopCount), Quaternion.identity) as GameObject;
                         alterCube = !alterCube;
                }
                else
                {
                         array[i] = Instantiate(cubeObj, new Vector3(Center + xloopCount, 0, Center - yloopCount), Quaternion.identity) as GameObject;
alterCube = !alterCube;
xloopCount++;
                }
        }
}

I call orderCubes(); at the start of the program. I pass in a radius and an array of cubes, the method then iterates through each x co-ordinate on the virtual axis calculating its respect value for +y and -y while Instantiating cubes for each. The scene was now producing a awesome looking circular waveform. It wasn't what I wanted but I'll talk about that next time. I added lights, changed the song, and added some colour. That's all for now so until next time, enjoy the video.






Wednesday, 30 October 2013

Research Results!

So when I said research I basically meant I'll do some googling and see what comes up ;)

What did come up was some visualisers other people have made using unity. Some of these visualisers aren't exactly what I intend to create but they did point me in the direction of  two functions :

AudioSource.GetOutputData(Array[], Channel);

and

AudioSource.GetSpectrumData(Array[], Channel, Window);

The functions will fill an array from the channel specified with data related to the Amplitude or Frequency an Audio Source respectively.

This is great, the values that I get I can then use for transformations, colours etc...

Now I know what functions to play with I'll try and fill some arrays with the data from the functions and use them to transform some objects in my Unity3D scene! :)




Tuesday, 29 October 2013

I'm back!

Hi there, it's been a very long time since I posted anything on here, that's due to university work piling up and too much time spent playing games. After the university work pile was cleared I continued playing games and enjoying summer! I am back now though with a new idea and therefore a new project. I'm not at university right now I am actually on a year of industrial placement at an awesome company in cambridge! Even though I'm working full time there I can't get enough of it apparently so I'm going to start blogging about this new project idea I have; inspired by my newly aquired placement.

ANYWAY

My idea is fairly simple, it is a mobile 3d music visualiser made in unity.

If you don't know what a music visualiser is a quick google will provide you with some images you may be familiar with. In short I will be making a 3D scene that dynamically responds to the music I play into my application.

I have no idea if this is possible while writing this blogpost but I've come across some methods and techniques that I think will enable me to at least come up with a proof of concept. If it goes well I hope I can make it into something awesome :)

Here are some basic (mostly 2d visualisers)


So for now that's all I'm going to say, I'm going to go off and research this idea and get back to you!

See you soon!