Mercurial > hg > aim92
comparison tools/step.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5242703e91d3 |
---|---|
1 /* | |
2 step.c generate a step up or down. | |
3 ------ | |
4 | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <math.h> | |
9 #include "options.h" | |
10 #include "units.h" | |
11 #include "strmatch.h" | |
12 | |
13 char applic[] = "generate a step waveform. " ; | |
14 char usage[] = "step [options]" ; | |
15 | |
16 static char *helpstr, *debugstr, *sampstr, *astr, *dstr, *typestr ; | |
17 static char *shiftstr, *polstr ; | |
18 | |
19 static Options option[] = { | |
20 { "help" , "off" , &helpstr , "help" , DEBUG }, | |
21 { "debug" , "off" , &debugstr , "debugging switch" , DEBUG }, | |
22 { "samplerate", "20kHz" , &sampstr , "samplerate " , VAL }, | |
23 { "amplitude" , "1" , &astr , "step height" , VAL }, | |
24 { "shift" , "10ms" , &shiftstr , "position of step relative to start", VAL }, | |
25 { "polarity" , "up" , &polstr , "step up or down" , VAL }, | |
26 { "duration" , "500ms" , &dstr , "duration of waveform" , VAL }, | |
27 { "type" , "short" , &typestr , "output datatype" , VAL }, | |
28 ( char * ) 0 } ; | |
29 | |
30 | |
31 int samplerate ; | |
32 float amplitude ; | |
33 int duration ; | |
34 int shift ; | |
35 int type ; | |
36 | |
37 main(argc, argv) | |
38 int argc ; | |
39 char *argv[] ; | |
40 { | |
41 int i ; | |
42 float y0, y1 ; | |
43 | |
44 getopts( option,argc,argv ) ; | |
45 if ( !isoff( helpstr ) ) | |
46 helpopts3( helpstr, argv[0], applic, usage, option ) ; | |
47 | |
48 samplerate = to_Hz( sampstr, 0 ) ; | |
49 amplitude = atof( astr ) ; | |
50 shift = to_p( shiftstr, samplerate ) ; | |
51 duration = to_p( dstr, samplerate ) ; | |
52 | |
53 if ( ( type = typeindex( typestr ) ) < 0 ) { | |
54 fprintf(stderr,"step: unknown datatype [%s]\n", typestr) ; | |
55 exit( 1 ) ; | |
56 } | |
57 | |
58 if ( isstr( polstr, "up" ) ) { | |
59 y0 = 0 ; y1 = amplitude ; | |
60 } | |
61 else if ( isstr( polstr, "down" ) ) { | |
62 y0 = amplitude ; y1 = 0 ; | |
63 } | |
64 else { | |
65 fprintf(stderr,"step: unknown polarity [%s]\n", polstr) ; | |
66 exit( 1 ) ; | |
67 } | |
68 | |
69 for ( i = 0 ; i < shift ; i++ ) | |
70 writeitem( &y0, type, 1, stdout ) ; | |
71 for ( ; i < duration ; i++ ) | |
72 writeitem( &y1, type, 1, stdout ) ; | |
73 | |
74 } |