- Home /
 
 
               Question by 
               Gameart1235 · Jan 26, 2015 at 09:27 AM · 
                audiosoundmusic  
              
 
              audio change object size
Is there anyway to take a audio beat and use it to change the size of a object, I just want to know and if there is a way how would one do it.
PLZ HELP
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by PhoenixBlackReal · Jan 28, 2015 at 01:08 PM
It all depends on what certain part of the audio you want to base the scaling - you could for example check the dB value:
 audio.GetOutputData(samples, 0); // fill array with samples
 float sum = 0f;
 for (int i=0; i < qSamples; i++){
 sum += samples[i]*samples[i]; // sum squared samples
 }
 rmsValue = Mathf.Sqrt(sum/qSamples); // rms = square root of average
 dbValue = 20*Mathf.Log10(rmsValue/refValue); // calculate dB
 if (dbValue < -160) dbValue = -160; // clamp it to -160dB min
 Debug.Log(dbValue);
 
               Now, based on this, give a proper relation to the scale of an object.
Something like gameObject.transform.localScale = new Vector3(dbValue, dbValue, dbValue);
Your answer