Commit Diff


commit - a7dafd6f194e81639c91e50d75f205343d02eef2
commit + 4ff4e76f99c53a244e00f23c1ab69fe22f00b5aa
blob - 15febf1d5c3a83facadd5d06242337b6b3d1546e
blob + 7cdda88f80b9eff9e1a5150217bcac1e230f04d2
--- NOTES
+++ NOTES
@@ -238,6 +238,7 @@ Helper programs:
   - CW_DECAY env. variable to set decay time in ms [=attack]
   - CW_ATTACK_SHAPE env. variable to set attack envelope [lin]
   - CW_DECAY_SHAPE env. variable to set decay envelope [lin]
+  - CW_AMPLITUDE env. variable to set output amplitude in percent [80]
 - morseteach.c - implements the Cunningham Morse Teacher
   - terminal interactive UI
   - sound output via external process: morse -s | morseplay
blob - 72f4382f3cc61e6e6751a586ae79ffa3cd60e431
blob + 32d3db82039f22d66de13c59bd13e50f1cb25cd7
--- cw.c
+++ cw.c
@@ -31,6 +31,7 @@ static rampfun_t *fallfun = ramp_exp;	/* shape of deca
 
 static int lowtime, hightime;		/* (in)audible time included in ramps */
 static int inbeep;			/* did we last beep()? */
+static double amp = 0.8;		/* sine wave amplitute [0.0, 1.0] */
 
 /* possible values for the envelope functions */
 struct shape { const char *name; rampfun_t *fun; } shapes[] = {
@@ -63,6 +64,16 @@ getenvnum(const char *name, const char *unit, int *p)
 	return *p;
 }
 
+double
+getenvpct(const char *name, double *p)
+{
+	int n = *p * 100;
+
+	*p = getenvnum(name, "%", &n) / 100.0;
+
+	return *p;
+}
+
 rampfun_t *
 getenvshape(const char *name, rampfun_t **p)
 {
@@ -130,7 +141,7 @@ sample_sin(int f, int x, int n)
 	int i, j;
 
 	for (i = 0; i < n; i++) {
-		y = sample_max * sin(2 * M_PI * f * (x + i) / par.rate);
+		y = sample_max * amp * sin(2 * M_PI * f * (x + i) / par.rate);
 
 		/* write to all channels */
 		for (j = 0; j < par.pchan; j++)
@@ -264,6 +275,7 @@ cwinit(void)
 void
 cwstart()
 {
+	getenvpct("CW_AMPLITUDE", &amp);
 	getenvnum("CW_ATTACK", "ms", &rise);
 	fall = rise;	/* default */
 	getenvnum("CW_DECAY", "ms", &fall);
blob - 2d3d791bba1a28abbb2bbd1057c0f377f037a8f0
blob + 75927a85de175288c360be5e27058fdec27214e9
--- cw.h
+++ cw.h
@@ -13,6 +13,7 @@ void silence(int);
 
 /* getenv helpers */
 int getenvnum(const char *, const char *, int *);
+double getenvpct(const char *, double *);
 rampfun_t *getenvshape(const char *, rampfun_t **);
 
 #endif /* CW_H_ */