/* Spectroscopic Toolkit version 1.96 by Pieter Suurmond, november 8, 2011. Copyright (c) 2000-2011 - Pieter Suurmond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Internal structure definitions of WAVELET and ENGINE. Forward declarations are in header ST_wavelets.h, which must be included prior to this file. Headerfile ST_integers is also necessary, before this file can be included. Private definitions here are included in internal sourcefiles ST_wavelets.c and in ST_score.c, this file needs not to be visible to the end-user. */ /*-------------------------------- LINKED LIST STRUCTURE FOR WAVELETS: ---------------*/ struct WAVELET /* WAVELET structuress are sorted on starttime, so */ { /* playing to AIFF files can be done efficiently. */ WAVELETp nxt; /* Pointer to next WAVELET object or NULL (the end). */ UNSIGNED32 startFrame; /* Absolute sampleframe time calculated from sample- */ UNSIGNED32 numFrames; /* rate, TOP and DUR by the addWAVELET() routine. */ SIGNED32 amplitudeLeft; /* 24 bit linear from -8388608 to +8388608 incl., */ SIGNED32 amplitudeRight; /* calculated from PAN and AMP by addWAVELET(). */ SIGNED16 envelopeShape; /* Choosen envelope shape. One of the constants */ /* kENV_Gaussian, kENV_ExpDecay, or kENV_ExpRise. */ UNSIGNED64 envelopeTime; /* 64 bit fixed-point: 18 integer + 46 fractional. */ UNSIGNED64 envelopeStep; /* Calculated from DUR, ENV and samplerate. */ UNSIGNED64 oscillatorTime; /* 64 bit fixed-point: 18 integer + 46 fractional. */ /* Initialiased by addWAVELET(), in sync or to zero. */ /* Unsigned to prevent sign-extension at shift-right. */ UNSIGNED64 oscillatorStep; /* For extreme frequency resolution: Kurucz's files */ /* contain 10 wavelength-digits so we need 33.22 */ /* (thus 34) bits. Calculated from FRQ and sample- */ /* rate by addWAVELET(). */ UNSIGNED32 rgb; /* Added in 2011/v1.96 to add colours to the scores. */ }; /*------------------------------------ DSP ENGINE: ---------------------------------------*/ struct ENGINE /* An engine is larger than a wavelet. */ { long samplerate; /* Set by newENGINE(). */ long double two_raise_64; long double oneOverSamplerate64; /* 2^64 / samplerate. */ UNSIGNED32 framesPerBlock; /* Amount of frames per block, for rende- */ /* ring and block-transfer to AIFF file. */ SIGNED32 *sineTable; /* Audio and subaudio wavetables, initia- */ SIGNED16 *envTables[kNumEnvelopeShapes]; /* lised by newENGINE(), read out by */ /* playWAVELETS(). */ /* Function newENGINE() gives an empty list, addWAVELET() adds wavelets, playWAVELETS() removes them again. */ WAVELETp firstWAVELET; /* Pointer to first WAVELET in linked list, or NULL. */ WAVELETp lastWAVELET; /* Pointer to last WAVELET in linked list, or NULL. */ /* Statistics kept up to date by addWAVELET(): */ UNSIGNED32 WSTAT_number; /* Number of wavelets in list, just for fun. */ UNSIGNED32 WSTAT_lastFrame; /* Not necessarily belonging to LAST wavelet */ UNSIGNED64 WSTAT_loOscillStep, /* in the list (ENDtime)! First frame, on the */ WSTAT_hiOscillStep; /* contrary, equals starttime first wavelet. */ }; /*------------------------------- SOME CONSTANTS: ----------------------------------------*/ /*------------------------------- 256 K samples for audio sinewave. With 17 bit signed data steepest slope is 0.7854 bit. Requires 18 addressing bits (2^18=262144). 64 bits are used for frequency so 46 bits remain for the fractional part. Constant kSineTableSize must be a power of 2. Minimum = -32768: 11111111 11111111 10000000 00000000. Maximum = +32768: 00000000 00000000 10000000 00000000. */ #define kSineTableSize (262144) #define kSineTableFractBits (46) #define kSineTableHalfOffset ((UNSIGNED64)1 << (kSineTableFractBits - 1)) /*------------------------------- 256 K samples for envelopes. With 16 bit gaussian content steepest slope is 0.75814 bit. Data always positive, data- type is however signed, stored negatively to fit top- value -32768 within 16 bits. All envelope tables require 18 bit addressing (like the sine-table above). In case of exponential envelope, steepest slope is 1.3 bit. Maximum = 0: 00000000 00000000. Minimum = -32768: 10000000 00000000. */ #define kEnvTableSize (262144) #define kEnvTableFractBits (46)