shithub: neindaw

ref: 92275f3b95309a13c8e1aa136bb62e7f6ea71458
dir: /piper/ay.c/

View raw version
#include <u.h>
#include <libc.h>
#include "piper.h"

typedef struct AY AY;

struct AY {
	struct {
		int freq;
		int enable;
		int noise;
		int env;
	}abc[3];
	struct {
		int period;
		int alter;
		int attack;
		int cont;
		int hold;
		int hit;
	}env;
	int noisefreq;
	int volume;
	char path[1];
};

static int
cmd(void *aux, Cmd *c)
{
	return 0;
}

static void *
alloc(char *path)
{
	AY *ay;
	int i;

	if ((ay = calloc(1, sizeof(*ay) + strlen(path) + 1)) != nil) {
		for (i = 0; i < 3; i++) {
			ay->abc[i].freq = pathopen(path, "%c/Tone/Frequency/ctl", 'A'+i);
			ay->abc[i].enable = pathopen(path, "%c/Tone/Enable/ctl", 'A'+i);
			ay->abc[i].enable = pathopen(path, "%c/Noise/ctl", 'A'+i);
			ay->abc[i].enable = pathopen(path, "%c/Envelope/ctl", 'A'+i);
		}

		ay->env.period = pathopen(path, "Envelope/Period/ctl");
		ay->env.alter = pathopen(path, "Envelope/Alternate/ctl");
		ay->env.attack = pathopen(path, "Envelope/Attack/ctl");
		ay->env.cont = pathopen(path, "Envelope/Continue/ctl");
		ay->env.hold = pathopen(path, "Envelope/Hold/ctl");
		ay->env.hit = pathopen(path, "Envelope/Hit/ctl");
		ay->noisefreq = pathopen(path, "Noise/ctl");
		ay->volume = pathopen(path, "Volume/ctl");

		strcpy(ay->path, path);
	}

	return ay;
}

Synth ay_3_8910 = {
	.name = "AY-3-8910",
	.cmd = cmd,
	.alloc = alloc,
};