Mercurial > hg > aim92
view 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 |
line wrap: on
line source
/* Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 =========================================================================== Permission to use, copy, modify, and distribute this software without fee is hereby granted for research purposes, provided that this copyright notice appears in all copies and in all supporting documentation, and that the software is not redistributed for any fee (except for a nominal shipping charge). Anyone wanting to incorporate all or part of this software in a commercial product must obtain a license from the Medical Research Council. The MRC makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* trigger.c * * Part of the temporal regularity programs * * M.Akeroyd. Summer 1993. Revised Winter 1994. */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "tip.h" extern struct Peak peak[MAX_PEAKS]; /* all channels */ extern int framewidth_samples; /* pwidth + nwidth * samplerate */ extern int pwidth; /* in msecs */ extern int nwidth; /* in msecs: NEGATIVE */ extern int samplerate; /* samples per sec */ extern char progname[MAX_STRING_LENGTH]; int find_trigger(int frame, int channel, int total_peaks) { /* What this code does: * * it looks for trigger peaks, at or near ImageTime = 0. * First, it looks for a peak reasonably * close to where the trigger-peak SHOULD be. If there isn't one there, then it reports * a failure, and crashes. * (No it doesn't: in fact it takes the fisrt peak to the right of the pre-defined trigger point). * * The peaknumber of the trigger_peak is RETURNed. * * Version of 1st June 1993. */ int n_1; int channel_1; int trigger_sample; /* where the trigger of channel_1 is */ double trigger_double; int trigger_found = OFF; int trigger_peak; /* THIS IS RETURNED */ /* hack ... */ if (total_peaks == 0) return 0; /* First, find out where the trigger-point is : * pwidth is in msecs, so divide that by 1000, multiply by sample, and you get pwidth in * samples. * So, trigger = that - 1 (-1 because the indexing is 0 to (framewidth_samples -1)) * Hope this integer arithemetic works */ trigger_double = (double) ((double) pwidth * (double) samplerate) / 1000.0 - 1; trigger_sample = (int) trigger_double; n_1 = total_peaks + 1; /* find first peak to RIGHT of trigger (reverse, remember) */ while ((peak[--n_1].sample < trigger_sample)) ; /* the next peak will be the trigger, at least on today's definition */ trigger_found = ON; trigger_sample = peak[n_1].sample; trigger_peak = n_1; if (trigger_found == OFF ) { fprintf(stderr, "%s: unable to find trigger point: frame %i channel %i\n", progname, frame, channel_1); exit(-1);} return trigger_peak; } /* The End .........................................................................*/ /*..................................................................................*/