#!/usr/bin/awk -f
#
# AWK-script: genam -- generate sine with triangular ampl. mod.
#
# usage: echo f ad fm t0 td | genam | augen -s 32000 -g - | plax -
#
# parameter units: f [Hz], ad [1], fm [Hz], t0 [s], td [s]
#
# signal:                x(t0+t) = 0.5*a(t)*sin(2*pi*f*t)
# duration:              t = [0,td]
# instantaneous ampl.:   a(t) = 1+ad/2*tri(fm*t)
# triangular modulation: tri(x) = 1-2*abs(frac(x)-.5)
#
# GNU-(c) Heiko Purnhagen <purnhage@tnt.uni-hannover.de>
# $Id: genam,v 1.2 2002/03/20 18:55:27 purnhage Exp $
#
# HP 990129 20020320
#

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