commit 381578e0ded33a6404accc6004b90268f3cfc8ff
parent e06ef51dbdc7c641031859d911127f963175f810
Author: rpa <rpa@laika>
Date: Sun, 15 Jan 2023 21:04:34 +0000
wave: wfedit takes form
Diffstat:
3 files changed, 115 insertions(+), 11 deletions(-)
diff --git a/src/wave/inst.c b/src/wave/inst.c
@@ -223,8 +223,8 @@ threadsynth(void *)
synth.mod.wtsel = 0;
synth.mod.freq = freq;
synth.mod.phase = 0;
- synth.mod.mod = inter.mod[1];
- synth.mod.vol = inter.mod[0];
+ synth.mod.mod = inter.mod[0];
+ synth.mod.vol = inter.mod[1];
synth.mod.pan = 0;
int i;
diff --git a/src/wave/prog.c b/src/wave/prog.c
@@ -79,6 +79,8 @@ interinstr(Inter *inter, Instruction *I)
case 2:
case 3:
case 4:
+ case 5:
+ case 6:
m = I->m - 1;
break;
}
diff --git a/src/wave/wfedit.c b/src/wave/wfedit.c
@@ -43,9 +43,12 @@ CMD(cmdload);
CMD(cmdsave);
CMD(cmdnoise);
CMD(cmdcos);
+CMD(cmdhex);
CMD(cmdmove);
+CMD(cmdmap);
CMD(cmdampmod);
CMD(cmdphasemod);
+CMD(cmdadd);
struct Dict{
const char *name;
@@ -62,6 +65,12 @@ struct Dict dict[] = {
{"save", cmdsave},
{"noise", cmdnoise},
{"cos", cmdcos},
+ {"hex", cmdhex},
+ {"move", cmdmove},
+ {"map", cmdmap},
+ {"amp", cmdampmod},
+ {"phase", cmdphasemod},
+ {"add", cmdadd},
{nil, nil},
};
@@ -204,12 +213,12 @@ CMD(cmdnoise)
int i;
ulong targ = 0;
if (argc > 1) {
- fprint(2, "usage: noise [id]\n");
+ fprint(2, "usage: noise [targ]\n");
return 1;
}
if (argc == 1) targ = atoi(argv[0]);
if (targ > BufMax) {
- fprint(2, "invalid id\n");
+ fprint(2, "invalid targ\n");
return 1;
}
for (i = 0; i < WFSize; i++) {
@@ -224,12 +233,12 @@ CMD(cmdcos)
int i;
ulong targ = 0;
if (argc > 1) {
- fprint(2, "usage: noise [id]\n");
+ fprint(2, "usage: noise [targ]\n");
return 1;
}
if (argc == 1) targ = atoi(argv[0]);
if (targ > BufMax) {
- fprint(2, "invalid id\n");
+ fprint(2, "invalid targ\n");
return 1;
}
for (i = 0; i < WFSize; i++) {
@@ -239,24 +248,117 @@ CMD(cmdcos)
return 0;
}
+CMD(cmdhex)
+{
+ if (argc > 2) {
+ fprint(2, "usage: hex val [targ]\n");
+ return 1;
+ }
+ s16int val = strtol(argv[0], nil, 16);
+ int targ = 0;
+ if (argc == 2) targ = atoi(argv[1]);
+ int i;
+ for (i = 0; i < WFSize; i++) buf[targ][i] = val;
+ if (cmd->updatec != nil) nbsendul(cmd->updatec, targ);
+ return 0;
+}
+
+
CMD(cmdmove)
{
- if (cmd->updatec != nil) nbsendul(cmd->updatec, 0);
+ if (argc != 2) {
+ fprint(2, "usage: move src targ\n");
+ return 1;
+ }
+ int src = atoi(argv[0]);
+ int targ = atoi(argv[1]);
+ memcpy(buf[targ], buf[src], WFSize * sizeof(s16int));
+ if (cmd->updatec != nil) nbsendul(cmd->updatec, targ);
+ return 0;
+}
+
+CMD(cmdmap)
+{
+ if ((argc < 2) && (argc > 3)) {
+ fprint(2, "usage: map mod src [targ]\n");
+ return 1;
+ }
+ int mod = atoi(argv[0]);
+ int src = atoi(argv[1]);
+ int targ = 0;
+ if (argc == 3) targ = atoi(argv[2]);
+ int i;
+ for (i = 0; i < WFSize; i++) {
+ int d = (buf[mod][i] + 0x8000) * WFSize / 0xffff;
+ buf[targ][i] = buf[src][d];
+ }
+ if (cmd->updatec != nil) nbsendul(cmd->updatec, targ);
return 0;
}
CMD(cmdampmod)
{
- if (cmd->updatec != nil) nbsendul(cmd->updatec, 0);
+ if ((argc < 2) && (argc > 3)) {
+ fprint(2, "usage: amp mod src [targ]\n");
+ return 1;
+ }
+ int mod = atoi(argv[0]);
+ int src = atoi(argv[1]);
+ int targ = 0;
+ if (argc == 3) targ = atoi(argv[2]);
+ int i;
+ for (i = 0; i < WFSize; i++) {
+ int d = buf[mod][i] * buf[src][i] / 0x8000;
+ if (d > 0x7fff) d = 0x7fff;
+ if (d < -0x8000) d = -0x8000;
+ buf[targ][i] = d;
+ }
+ if (cmd->updatec != nil) nbsendul(cmd->updatec, targ);
return 0;
}
CMD(cmdphasemod)
{
- if (cmd->updatec != nil) nbsendul(cmd->updatec, 0);
+ if ((argc < 3) && (argc > 4)) {
+ fprint(2, "usage: phase amp mod src [targ]\n");
+ return 1;
+ }
+ double amp = strtod(argv[0], nil);
+ int mod = atoi(argv[1]);
+ int src = atoi(argv[2]);
+ int targ = 0;
+ if (argc == 4) targ = atoi(argv[3]);
+ int i;
+ for (i = 0; i < WFSize; i++) {
+ int d = i + (buf[mod][i] + 0x8000) * amp * WFSize / 0xffff;
+ d = d % WFSize;
+ buf[targ][i] = buf[src][d];
+ }
+ if (cmd->updatec != nil) nbsendul(cmd->updatec, targ);
return 0;
}
+CMD(cmdadd)
+{
+ int n = 0;
+ if ((argc < 2) && (argc > 3)) {
+ fprint(2, "usage: add mod src [targ]\n");
+ return 1;
+ }
+ int mod = atoi(argv[n++]);
+ int src = atoi(argv[n++]);
+ int targ = 0;
+ if (argc == 3) targ = atoi(argv[n++]);
+ int i;
+ for (i = 0; i < WFSize; i++) {
+ s16int d = buf[mod][i] + buf[src][i];
+
+ buf[targ][i] = d;
+ }
+ if (cmd->updatec != nil) nbsendul(cmd->updatec, targ);
+ return 0;
+
+}
Uictl *
@@ -348,11 +450,11 @@ drawwaveform(Image *screen, Rectangle r, s16int *wf, Image *bg, Image *hi, Image
m1 = wf[s] * mid / 0x7fff;
m2 = wf[e] * mid / 0x7fff;
if (m1 == m2) m1 += (m1 > 0) ? -1 : +1;
- bar = Rpt(Pt(i, mid), Pt(i + 1, mid + m1));
+ bar = Rpt(Pt(i, mid), Pt(i + 1, mid - m1));
bar = canonrect(bar);
bar = rectaddpt(bar, r.min);
draw(screen, bar, lo, nil, ZP);
- bar = Rpt(Pt(i, mid + m2), Pt(i + 1, mid + m1));
+ bar = Rpt(Pt(i, mid - m2), Pt(i + 1, mid - m1));
bar = canonrect(bar);
bar = rectaddpt(bar, r.min);
draw(screen, bar, hi, nil, ZP);