started implementing audio node system

This commit is contained in:
DaniTheSkunk 2022-10-13 06:05:01 +00:00
parent f96b2802f6
commit 6c9aa03341
1 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package com.danitheskunk.skunkworks.audio.nodes;
import com.danitheskunk.skunkworks.audio.AudioBuffer;
public abstract class Node {
private int inCount;
private int outCount;
private boolean[] isOutConnected;
private Node[] inConnections;
private int[] inConnectionSlots;
public Node(int inCount, int outCount) {
this.inCount = inCount;
this.outCount = outCount;
this.isOutConnected = new boolean[outCount];
this.inConnections = new Node[inCount];
this.inConnectionSlots = new int[inCount];
if(outCount > 1) {
throw new RuntimeException("more than one out connection not yet" +
" " +
"allowed, needs handling in getBuffer to only process once");
}
}
public static void connect(Node src, int srcSlot, Node dst, int dstSlot) {
if(srcSlot < 0 || srcSlot >= src.outCount) {
throw new RuntimeException("invalid srcSlot");
}
if(dstSlot < 0 || dstSlot >= dst.inCount) {
throw new RuntimeException("invalid dstSlot");
}
if(src.isOutConnected[srcSlot]) {
throw new RuntimeException("src node slot already connected");
}
if(dst.inConnections[dstSlot] != null) {
throw new RuntimeException("dst node slot already connected");
}
src.isOutConnected[srcSlot] = true;
dst.inConnections[dstSlot] = src;
dst.inConnectionSlots[dstSlot] = srcSlot;
}
public int getInCount() {
return inCount;
}
public int getOutCount() {
return outCount;
}
public abstract AudioBuffer getBuffer(int slot);
}