tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal shipping tomwalters@0: charge). Anyone wanting to incorporate all or part of this software in a tomwalters@0: commercial product must obtain a license from the Medical Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or implied tomwalters@0: warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE tomwalters@0: A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY tomwalters@0: DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN tomwalters@0: AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF tomwalters@0: OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. tomwalters@0: */ tomwalters@0: tomwalters@0: /* tomwalters@0: scales.c tomwalters@0: ======== tomwalters@0: tomwalters@0: generates double arrays of numbers spaced on arbitrary frequency scales tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: #include tomwalters@0: tomwalters@0: #ifndef _STITCH_H_ tomwalters@0: #include "stitch.h" tomwalters@0: #endif tomwalters@0: #ifndef _SCALES_H_ tomwalters@0: #include "scales.h" tomwalters@0: #endif tomwalters@0: tomwalters@0: double *GenerateScale( min, max, density, base, inverse ) tomwalters@0: double min, max, density, base, (*inverse)() ; tomwalters@0: { tomwalters@0: unsigned n_scale = NumberOnScale( min, max, density, base ) ; tomwalters@0: double *scale = NewArray( double, n_scale+1, "for scale in scales.c" ) ; tomwalters@0: double scale_start ; tomwalters@0: int i ; tomwalters@0: tomwalters@0: if( min != max ) { tomwalters@0: tomwalters@0: scale_start = base - floor( ( base - min ) * density ) / density ; tomwalters@0: tomwalters@0: /* fill array scale points 1./density apart */ tomwalters@0: tomwalters@0: for( i=0 ; i < n_scale ; i++ ) tomwalters@0: scale[ i ] = scale_start + i / density ; tomwalters@0: tomwalters@0: scale[ i++ ] = 0. ; tomwalters@0: } tomwalters@0: else { tomwalters@0: scale[0] = min ; tomwalters@0: scale[1] = 0. ; tomwalters@0: } tomwalters@0: tomwalters@0: /* convert scale space back to units required */ tomwalters@0: tomwalters@0: if( inverse != (double ( * )()) 0 ) tomwalters@0: for( i=0 ; i < n_scale ; i++ ) tomwalters@0: scale[ i ] = inverse( scale[ i ] ) ; tomwalters@0: tomwalters@0: return ( scale ) ; tomwalters@0: } tomwalters@0: tomwalters@0: int NumberOnScale( min, max, density, base ) tomwalters@0: double min, max, density, base ; tomwalters@0: { tomwalters@0: if( min != max ) tomwalters@0: return ( ( int ) ( ( floor( ( base - min ) * density ) + 1. + ( floor( ( max - base ) * density ) ) ) ) ) ; tomwalters@0: else tomwalters@0: return ( 1 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: double *NumberedScale( min, max, channels, inverse ) tomwalters@0: double min, max ; tomwalters@0: int channels ; tomwalters@0: double (*inverse)() ; tomwalters@0: { tomwalters@0: DeclareNewArray( double, scale, channels+1, "for scale in scales.c" ) ; tomwalters@0: int chan ; tomwalters@0: tomwalters@0: scale[ 0 ] = min ; tomwalters@0: for( chan=1 ; chan < channels ; chan++ ) tomwalters@0: scale[ chan ] = min + chan * (max-min) / ( channels - 1 ) ; tomwalters@0: tomwalters@0: if( inverse != (double ( * )()) 0 ) tomwalters@0: for( chan=0 ; chan < channels ; chan++ ) tomwalters@0: scale[ chan ] = inverse( scale[ chan ] ) ; tomwalters@0: tomwalters@0: scale[ channels ] = 0. ; tomwalters@0: tomwalters@0: return ( scale ) ; tomwalters@0: }