shithub: neindaw

Download patch

ref: 22f7e9038ca004a322d82d3ee543eb8ed42dbec9
parent: 6cd03fe7b962e5af589ced40bd655e12dd167445
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Mar 19 06:50:15 EDT 2020

ay: add tickhz as a command line argument

--- a/ay/ay.c
+++ b/ay/ay.c
@@ -24,8 +24,6 @@
 #define MAX(a,b) ((a)>=(b)?(a):(b))
 
 enum {
-	Tickhz = 1000000,
-
 	Levelenv = 1<<4,
 
 	Hold = 1<<0,
@@ -54,6 +52,8 @@
 	[Xclone] = {.type = Xclone},
 };
 
+static int tickhz = 1000000;
+
 extern Srv fs;
 
 static int rate = 44100;
@@ -104,19 +104,19 @@
 static int
 hz2tp(int hz)
 {
-	return MAX(1, MIN(4095, Tickhz / (MAX(1, hz) * 16)));
+	return MAX(1, MIN(4095, tickhz / (MAX(1, hz) * 16)));
 }
 
 static int
 hz2ep(int hz)
 {
-	return MAX(1, MIN(65535, Tickhz / (MAX(1, hz) * 256)));
+	return MAX(1, MIN(65535, tickhz / (MAX(1, hz) * 256)));
 }
 
 static int
 ms2ep(int ms)
 {
-	return MAX(1, MIN(65535, (Tickhz / 1000) * ms / 256));
+	return MAX(1, MIN(65535, (tickhz / 1000) * ms / 256));
 }
 
 static void
@@ -185,8 +185,8 @@
 	char s[32];
 	int i;
 
-	min = Tickhz/65520.0f;
-	max = Tickhz/16.0f;
+	min = tickhz/65520.0f;
+	max = tickhz/16.0f;
 	step = (max-min)/4094.0f;
 
 	ui->openVerticalBox(ui->f, "AY-3-8910");
@@ -216,8 +216,8 @@
 	}
 	ui->closeBox(ui->f);
 
-	min = Tickhz/496.0f;
-	max = Tickhz/16.0f;
+	min = tickhz/496.0f;
+	max = tickhz/16.0f;
 	step = (max-min)/30.0f;
 
 	ui->declare(ui->f, &dsp->noise, "noise", "");
@@ -248,7 +248,7 @@
 	int i;
 	ay38910_desc_t d = {
 		.type = AY38910_TYPE_8910,
-		.tick_hz = Tickhz,
+		.tick_hz = tickhz,
 		.sound_hz = rate,
 		.magnitude = 1.0,
 	};
@@ -404,7 +404,7 @@
 static void
 usage(void)
 {
-	print("usage: %s [-s srv] [-m mtpt] [-r rate]\n", argv0);
+	print("usage: %s [-s srv] [-m mtpt] [-r rate] [-t HZ]\n", argv0);
 	threadexitsall("usage");
 }
 
@@ -444,9 +444,15 @@
 	case 'r':
 		rate = atoi(EARGF(usage()));
 		break;
+	case 't':
+		tickhz = atoi(EARGF(usage()));
+		break;
 	default:
 		usage();
 	}ARGEND
+
+	if (rate < 1 || tickhz < 1)
+		usage();
 
 	if (srv == nil && mtpt == nil)
 		sysfatal("must specify -s or -m option");