package com.danitheskunk.skunkworks.audio.nodes;

import com.danitheskunk.skunkworks.audio.AudioBuffer;
import com.danitheskunk.skunkworks.audio.AudioEngine;

public class Sine extends Node {
	private final double freq;
	private int tick;

	public Sine(AudioEngine engine, double freq) {
		super(engine, 0, 1);
		tick = 0;
		this.freq = freq;
	}

	@Override
	public AudioBuffer getBuffer(int slot) {
		var bufsize = getEngine().getBufferSize();
		var buf = new AudioBuffer(bufsize);
		for(int i = 0; i < bufsize; ++i) {
			var time = (double) tick / (double) getEngine().getSampleRate();
			var s = Math.sin(Math.PI * 2 * freq * time);
			buf.setSample(i, s, s);
			++tick;
		}
		return buf;
	}
}
