Audio Data

I’m doing an experimentation with my platform game and I want to see if I can move my platforms based on music. I’ve tried getting the music frequency or channels but there seems to be no change in it.

using UnityEngine;
using System.Collections;

public class music : MonoBehaviour {
	
	private float music_vol_peak;
	private AudioSource audioHolder;


	// Use this for initialization
	void Start (){
		
		audioHolder = GameObject.FindGameObjectWithTag("Music").GetComponent<AudioSource>();

	}
	
	// Update is called once per frame
	void Update () {
		
		music_vol_peak = audioHolder.clip.frequency;
		//Debug.Log(music_vol_peak);

	}
}

Thats the code I’ve been using. Is there anyway to get something like the right and left peak volume channels?

This is where the only actual audio data is stored, values from -1.0 to 1.0.

frequency, channels, samples, etc are all static numbers that dont change.

Thanks for the info. The only problem I get now is this one.

Code?

using UnityEngine;
using System.Collections;

public class music : MonoBehaviour {
	
	private AudioClip music_data;
	private AudioSource audioHolder;


	// Use this for initialization
	void Start (){
		
		audioHolder = GameObject.FindGameObjectWithTag("Music").GetComponent<AudioSource>();
		
		music_data = audioHolder.clip;
		
		float[] samples = new float[audio.clip.samples * audio.clip.channels];
        audio.clip.GetData(samples, 0);
        int i = 0;
        while (i < samples.Length) {
            samples[i] = samples[i] * 0.5F;
            ++i;
        }
        audio.clip.SetData(samples, 0);
		
		Debug.Log(music_data);

	}
	
	// Update is called once per frame
	void Update () {
		
		
		

	}
}

audio.clip has no meaning in your script
you defined it as “music_data”, not audio.clip…

That was the original way I did it but it still came up with the error. I’ll try it again and upload the new version if it doesn’t work.

audioHolder = GameObject.FindGameObjectWithTag("Music").GetComponent<AudioSource>();
		
		music_data = audioHolder.clip;
		
		float[] samples = new float[music_data.samples * music_data.channels];
        music_data.GetData(samples, 0);
        int i = 0;
        while (i < samples.Length) {
            samples[i] = samples[i] * 0.5F;
            ++i;
        }
        music_data.SetData(samples, 0);
		
		//Debug.Log(music_data);

Same error.

Code is fine
Its probably your audio clip
change the import settings for Load Type (cant be compressed in memory) for the clip
or perhaps use a WAV

i try adjust volume of one sound with another one

so getdatamusic[ ]

for