commit 22eb4e56d33c855f7b1ec28a6f7578ee5aac3e25
parent b2f9a43b178f574a9950b09b72b4ad8964df8411
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Thu, 12 Aug 2021 16:23:06 +0300
add params to usync, fix little-endiannes
Diffstat:
3 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/miditest.c b/miditest.c
@@ -15,7 +15,7 @@ main(void)
uint8_t msg[4];
char *mdev;
msg[0] = 0x90;
- msg[1] = 0x10;
+ msg[1] = 0x64;
msg[2] = 127;
mdev = "midithru/0";
struct mio_hdl *mh;
diff --git a/progsynth.c b/progsynth.c
@@ -21,7 +21,7 @@ s_init(char *sdev)
par.pchan = 2;
par.sig = 1;
par.bits = 16;
- par.le = 0;
+ par.le = 1;
par.rate = 44100;
par.xrun = SIO_SYNC;
par.appbufsz = 1024;
diff --git a/usynth.c b/usynth.c
@@ -6,12 +6,15 @@
#include <string.h>
#include <assert.h>
+#include "arg.h"
#include "util.h"
#include "midi.h"
#include "wavetable.h"
#include "machine.h"
#include "build.h"
+char *argv0;
+
struct sio_hdl *sh;
size_t bs;
int16_t *sbuf;
@@ -31,7 +34,7 @@ s_init(char *sdev)
par.pchan = 2;
par.sig = 1;
par.bits = 16;
- par.le = 0;
+ par.le = 1;
par.rate = 44100;
par.xrun = SIO_SYNC;
par.appbufsz = 1024;
@@ -42,23 +45,51 @@ s_init(char *sdev)
sio_start(sh);
}
+void
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-f rsnd/0] [-q rmidi/0] [-o record.pcm] program\n", argv0);
+ exit(0);
+}
+
int
-main(int argc, char **argv)
+main(int argc, char *argv[])
{
- FILE *fp;
+ FILE *fp, *op;
+ char *mdev, *sdev, *fout;
+
+ mdev = "midithru/0";
+ sdev = "default";
+ fout = NULL;
+ op = NULL;
+
+ ARGBEGIN {
+ case 'q':
+ mdev = EARGF(usage());
+ break;
+ case 'f':
+ sdev = EARGF(usage());
+ case 'o':
+ fout = EARGF(usage());
+ if (fout[0] == '-') op = stdout;
+ else op = fopen(fout, "w");
+ break;
+ default:
+ usage();
+ } ARGEND
fp = stdin;
- if (argc == 2) {
- fp = fopen(argv[1], "r");
+ if (argc == 1) {
+ fp = fopen(argv[0], "r");
if (fp == NULL) {
fprintf(stderr, "failed to open file %s\n", argv[1]);
exit(-1);
}
}
- s_init("default");
+ s_init(sdev);
wt_init();
- m_init("midithru/0");
+ m_init(mdev);
m_vector.note_on = note_on;
m_vector.note_off = note_off;
@@ -71,6 +102,9 @@ main(int argc, char **argv)
m_read();
fillbuf(sbuf, bs * 2);
n = sio_write(sh, sbuf, bs * 2 * sizeof(int16_t));
+ if (op != NULL)
+ fwrite(sbuf, bs * 2 * sizeof(int16_t), 1,
+ op);
}
}