~ft/neindaw

f1652d3fffe4457db7bf025bdb4ab1201065d923 — Sigrid Haflínudóttir a month ago 57f49b5
put rate into common.h, one for every program
4 files changed, 20 insertions(+), 17 deletions(-)

M ay/ay.c
M common.h
M dsp/main.c
M piper/piper.c
M ay/ay.c => ay/ay.c +1 -1
@@ 39,7 39,7 @@ struct Auxdsp {
};

static int tickhz = 1773400;
static int rate = 44100;
static int rate = RATE;

static void
regw(ay38910_t *ay, int reg, int v)

M common.h => common.h +4 -0
@@ 13,3 13,7 @@ typedef enum {
}UItype;

extern char *uitypenames[UInum];

enum {
	RATE = 44100,
};

M dsp/main.c => dsp/main.c +1 -1
@@ 23,7 23,7 @@ struct Auxdsp {
	int inmax, outmax;
};

static int rate = 44100;
static int rate = RATE;
static DSPf *dspf;

static Auxdsp *

M piper/piper.c => piper/piper.c +14 -15
@@ 2,6 2,7 @@
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include "common.h"
#include "piper.h"
#include "util.h"



@@ 31,6 32,7 @@ static Group *groups;
static int numgroups;
static int audio;
static int record = -1;
static int rate = RATE;

static Synth *synths[] = {
	&ay_3_8910,


@@ 200,45 202,42 @@ nextnote:
	return e;
}

enum {
	Bufframes = 44100/100,
};

static void
mixer(void *)
{
	int i, j, n;
	int i, j, n, bufframes;
	s16int *pcm;
	float *out, *x, f;
	Inst *inst;
	Group *g;

	pcm = malloc(2*Bufframes*sizeof(*pcm)); /* stereo */
	out = malloc(2*Bufframes*sizeof(*out));
	x = malloc(2*Bufframes*sizeof(*x));
	bufframes = rate/100;
	pcm = malloc(2*bufframes*sizeof(*pcm)); /* stereo */
	out = malloc(2*bufframes*sizeof(*out));
	x = malloc(2*bufframes*sizeof(*x));

	for (;;) {
		memset(out, 0, 2*Bufframes*sizeof(*out));
		memset(out, 0, 2*bufframes*sizeof(*out));
		qlock(&grouplock);
		for (i = 0; i < numgroups; i++) {
			g = &groups[i];
			for (j = 0; j < g->numinst; j++) {
				inst = &g->inst[j];
				if (readn(inst->data, x, inst->numout*Bufframes*sizeof(*x)) < 1)
				if (readn(inst->data, x, inst->numout*bufframes*sizeof(*x)) < 1)
					break;
				if (inst->numout == 1) {
					for (n = 0; n < Bufframes; n++) {
					for (n = 0; n < bufframes; n++) {
						out[n*2+0] += x[n];
						out[n*2+1] += x[n];
					}
				} else {
					for (n = 0; n < 2*Bufframes; n++)
					for (n = 0; n < 2*bufframes; n++)
						out[n] += x[n];
				}
			}
		}
		qunlock(&grouplock);
		for (n = 0; n < 2*Bufframes; n++) {
		for (n = 0; n < 2*bufframes; n++) {
			f = out[n] * 8192.0 * vol;
			if (f > 32767.0)
				f = 32767.0;


@@ 246,11 245,11 @@ mixer(void *)
				f = -32767.0;
			pcm[n] = f;
		}
		if (write(audio, pcm, 2*Bufframes*sizeof(*pcm)) < 0) {
		if (write(audio, pcm, 2*bufframes*sizeof(*pcm)) < 0) {
			fprint(2, "audio: %r\n");
			break;
		}
		if (record >= 0 && write(record, pcm, 2*Bufframes*sizeof(*pcm)) < 0) {
		if (record >= 0 && write(record, pcm, 2*bufframes*sizeof(*pcm)) < 0) {
			fprint(2, "record: %r\n");
			break;
		}