Mercurial > hg > aim92
comparison saitools/trigger.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 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 | |
3 =========================================================================== | |
4 | |
5 Permission to use, copy, modify, and distribute this software without fee | |
6 is hereby granted for research purposes, provided that this copyright | |
7 notice appears in all copies and in all supporting documentation, and that | |
8 the software is not redistributed for any fee (except for a nominal | |
9 shipping charge). Anyone wanting to incorporate all or part of this | |
10 software in a commercial product must obtain a license from the Medical | |
11 Research Council. | |
12 | |
13 The MRC makes no representations about the suitability of this | |
14 software for any purpose. It is provided "as is" without express or | |
15 implied warranty. | |
16 | |
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES | |
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
23 SOFTWARE. | |
24 */ | |
25 | |
26 /* trigger.c | |
27 * | |
28 * Part of the temporal regularity programs | |
29 * | |
30 * M.Akeroyd. Summer 1993. Revised Winter 1994. | |
31 */ | |
32 | |
33 | |
34 | |
35 #include <stdio.h> | |
36 #include <string.h> | |
37 #include <stdlib.h> | |
38 | |
39 #include "tip.h" | |
40 | |
41 | |
42 | |
43 | |
44 extern struct Peak peak[MAX_PEAKS]; /* all channels */ | |
45 | |
46 extern int framewidth_samples; /* pwidth + nwidth * samplerate */ | |
47 extern int pwidth; /* in msecs */ | |
48 extern int nwidth; /* in msecs: NEGATIVE */ | |
49 extern int samplerate; /* samples per sec */ | |
50 | |
51 | |
52 extern char progname[MAX_STRING_LENGTH]; | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 int find_trigger(int frame, int channel, int total_peaks) | |
60 { | |
61 | |
62 /* What this code does: | |
63 * | |
64 * it looks for trigger peaks, at or near ImageTime = 0. | |
65 * First, it looks for a peak reasonably | |
66 * close to where the trigger-peak SHOULD be. If there isn't one there, then it reports | |
67 * a failure, and crashes. | |
68 * (No it doesn't: in fact it takes the fisrt peak to the right of the pre-defined trigger point). | |
69 * | |
70 * The peaknumber of the trigger_peak is RETURNed. | |
71 * | |
72 * Version of 1st June 1993. | |
73 */ | |
74 | |
75 | |
76 int n_1; | |
77 int channel_1; | |
78 int trigger_sample; /* where the trigger of channel_1 is */ | |
79 double trigger_double; | |
80 int trigger_found = OFF; | |
81 int trigger_peak; /* THIS IS RETURNED */ | |
82 | |
83 | |
84 /* hack ... */ | |
85 if (total_peaks == 0) | |
86 return 0; | |
87 | |
88 /* First, find out where the trigger-point is : | |
89 * pwidth is in msecs, so divide that by 1000, multiply by sample, and you get pwidth in | |
90 * samples. | |
91 * So, trigger = that - 1 (-1 because the indexing is 0 to (framewidth_samples -1)) | |
92 * Hope this integer arithemetic works */ | |
93 | |
94 trigger_double = (double) ((double) pwidth * (double) samplerate) / 1000.0 - 1; | |
95 trigger_sample = (int) trigger_double; | |
96 n_1 = total_peaks + 1; | |
97 | |
98 /* find first peak to RIGHT of trigger (reverse, remember) */ | |
99 while ((peak[--n_1].sample < trigger_sample)) | |
100 ; | |
101 | |
102 /* the next peak will be the trigger, at least on today's definition */ | |
103 trigger_found = ON; | |
104 trigger_sample = peak[n_1].sample; | |
105 trigger_peak = n_1; | |
106 | |
107 if (trigger_found == OFF ) { | |
108 fprintf(stderr, "%s: unable to find trigger point: frame %i channel %i\n", progname, frame, channel_1); | |
109 exit(-1);} | |
110 | |
111 return trigger_peak; | |
112 } | |
113 | |
114 | |
115 | |
116 /* The End .........................................................................*/ | |
117 /*..................................................................................*/ | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 |