#!/usr/bin/awk -f
#
# AWK-script: genfm -- generate sine with triangular freq. mod.
#
# usage: echo fc fd fm t0 td | genfm | augen -s 32000 -g - | plax -
#
# parameter units: fc [Hz], fd [Hz], fm [Hz], t0 [s], td [s]
#
# signal:                x(t0+t) = 0.5*sin(2*pi*int(0,t,f(tau),dtau))
# duration:              t = [0,td]
# instantaneous freq.:   f(t) = fc+fd/2*tri(fm*t)
# triangular modulation: tri(x) = 1-2*abs(frac(x)-.5)
#
# GNU-(c) Heiko Purnhagen <purnhage@tnt.uni-hannover.de>
# $Id: genfm,v 1.4 2002/04/18 01:34:01 purnhage Exp $
#
# HP 990129 20020320 20020417
#

{
  t = 0;
  td = .5/$3;
  f1 = $1-$2/2.;
  f2 = $1+$2/2.;
  dp = (f1+f2)/2*td;
  dp -= int(dp);	
  p = 0;
  while (t+td <= $5) {
    printf "s %f %f %f %f %f .5 .5\n",t+$4,td,f1,f2,p*360;
    p += dp;
    t += td;
    printf "s %f %f %f %f %f .5 .5\n",t+$4,td,f2,f1,p*360;
    p += dp;
    p -= int(p);
    t += td;
  }
}
