package zero1hd.rhythmbullet.audio.visualizer;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.utils.Disposable;

import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
import zero1hd.rhythmbullet.audio.MusicDataPack;

public class VisualizerCore implements Disposable {
	protected MusicDataPack cmi;
	private FloatFFT_1D fft;
	float[] audioPCM;
	protected int width, height;
	protected int xPos, yPos;
	protected int barCount;
	
	public VisualizerCore(int width, int height, int x, int y) {
		this.height = height;
		this.width = width;
		this.xPos = x;
		this.yPos = y;
	}
	
	public void update() {
		if (cmi != null) {
			if (cmi.getPlaybackIndexPosition() > cmi.getCurrentReadWindowIndex()) {
				cmi.readSamples(audioPCM);
				fft.realForward(audioPCM);
//				Gdx.app.debug("Visualizer", "Proper read");
			} else {
//				System.out.println(audioPCM[16]);
//				Gdx.app.debug("Visualizer", "Not reading so music can catch up.");
			}
		}
	}
	
	public void setMDP(MusicDataPack cmi) {
		this.cmi = cmi;
		fft = new FloatFFT_1D(cmi.getReadWindowSize());
		audioPCM = new float[cmi.getReadWindowSize()];
	}
	
	public void render(Batch batch, float parentAlpha) {
	}

	@Override
	public void dispose() {
	}
	
}
