Hello, I’ve been trying to draw waves for a while and had some problem with getoutputdata. It appeals that when the array size can’t go above 2^14, is it a limitation of the function or am I doing anything wrong?
if analyzing the audio data live can’t have that much accuracy, is there any work around or is possible to go over the audio track and save the data in a table some or something. And more importantly, do it with more details than evaluating live?
Lastly, what is a good way to draw wave that has great details and changes rapidly? Similar to an oscilloscope? I found a good video example done in unity.
And here is my codeplus a video demoing mine(it’s a very simple approach, but difinatly not a very good one)
using UnityEngine;
using System.Collections;
public class osciParticle : MonoBehaviour {
public Color particleColor;
public Color backGround;
public int resolution;
public int particleCount;
private float[] samplesX;
private float[] samplesY;
private ParticleSystem.Particle[] points;
void Start () {
samplesX = new float[particleCount];
samplesY = new float[particleCount];
Draw ();
}
// Update is called once per frame
private void Draw(){
AudioSource audio = GetComponent<AudioSource> ();
points = new ParticleSystem.Particle[resolution];
audio.GetOutputData (samplesX, 0);
audio.GetOutputData (samplesY, 1);
float increment = 1f/ ( resolution - 1);
for (int i = 0; i < resolution; i++) {
float x = i * increment;
points [i].position = new Vector3((int)(resolution * (samplesX [i] + 1f) / 2) * increment , (int)(resolution * (samplesY [i] + 1f) / 2) * increment, 0);
points [i].startColor =new Color (x, 0, 0);
points [i].startSize = .01f;
}
}
void Update () {
ParticleSystem particlesys = GetComponent<ParticleSystem> ();
Draw ();
particlesys.SetParticles (points, particleCount);
}
}