From: David Schleef Date: Thu, 4 Oct 2001 23:33:14 +0000 (+0000) Subject: added function to convert multiple samples to/from phys units X-Git-Tag: r0_7_17~22 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2e5c484b245a43d5cf8546ae53d8b025fac2308d;p=comedilib.git added function to convert multiple samples to/from phys units --- diff --git a/lib/range.c b/lib/range.c index c0baf51..fdefa0c 100644 --- a/lib/range.c +++ b/lib/range.c @@ -134,3 +134,67 @@ int comedi_range_is_chan_specific(comedi_t *it,unsigned int subd) return (it->subdevices[subd].subd_flags&SDF_RANGETYPE)?1:0; } +int comedi_sampl_to_phys(double *dest, int dst_stride, sampl_t *src, + int src_stride, comedi_range *rng, lsampl_t maxdata, int n) +{ + int oor = 0; + int i; + double mult; + + if(!rng)return -1; + if(!maxdata)return -1; + + mult = (rng->max-rng->min)/maxdata; + if(comedi_oor_is_nan==COMEDI_OOR_NAN){ + for(i=0;imin + mult*(*src); + } + dest = ((void *)dest) + dst_stride; + src = ((void *)src) + src_stride; + } + }else{ + for(i=0;imin + mult*(*src); + dest = ((void *)dest) + dst_stride; + src = ((void *)src) + src_stride; + } + } + + return oor; +} + +int comedi_sampl_from_phys(sampl_t *dest,int dst_stride,double *src, + int src_stride, comedi_range *rng, lsampl_t maxdata, int n) +{ + int oor = 0; + double mult; + int i; + + if(!rng)return -1; + if(!maxdata)return -1; + + mult = (maxdata+1)/(rng->max-rng->min); + for(i=0;imin); + if(*srcmin){ + *dest=0; + oor++; + } + if(*src>rng->min){ + *dest=maxdata; + oor++; + } + dest = ((void *)dest) + dst_stride; + src = ((void *)src) + src_stride; + } + + return oor; +} +