/* Spectroscopic Toolkit version 1.96, october 26, 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. */ #include /* For FILE. */ #include #include #include "ST_wavelets.h" /* For ENGINE. */ #include "ST_pconv.h" #include "c00.h" /* For c02_smear() and others. */ /*------------------------------------------------------------------------------------------------*/ /* Both exponential decay and Gaussian envelopes. Two wavelets per frequency. Playing around with energy-levels as top-times. */ static short fuckedCloud2011(unsigned short selected, /* 100 * Atomic number + ionisation level. */ double strength, /* Linear overall amplitude (0.18=OK for Fe). */ short phase, /* -1=oscill.sync; 0=sin at top; 1=cos at top. */ long double starttime, /* Starttime in seconds. */ long double duration, /* 'effective duration' in seconds. */ ENGINEp E, FILE* msg, long rgb) { FILE *pbinDatabaseFP; pieterPacked pbinBuff; derivedData more; /* See ST.gfall.pbin.c. */ unsigned long linesRead = 0, linesUsed = 0, linesSkipped = 0; short e = 0; double a, p, d; long double dur, audioHertz; double loFreq = 9.99E99, /* AUDIO-freq. */ hiFreq = -9.99E99, loAmp = 9.99E99, /* Hi-Hertz(!), not audio-amplitude yet. */ hiAmp = -9.99E99; double ELOWlowest = 0, ELOWhighest = 0, EUPPlowest = 0, EUPPhighest = 0; double durA, durB; /* Slope & offset. Lowest freq->1; highest freq->0.5. */ /*------------------------------------------------------------ Frequency transposition: */ long double transpositionRatio = pow(2.0, -40.0); /* 40 octaves down. */ /*------------------------------------------------------------ Smoother frequency windowing: */ double lowestFreq = 20.0; /* (trapeziod instead of brickwall) */ double aboveLowestFreq = 1.25 * lowestFreq; /* Rise to 1 within 1 major third. */ double aboveHertz = aboveLowestFreq - lowestFreq; double nyquist = 0.5 * (double)getSamplerateENGINE(E); double belowNyquist = nyquist / 1.2; /* Fall to 0 within 1 minor third. */ double belowHertz = nyquist - belowNyquist; /*------------------------------------------------------- Open binary version of Kurucz's file. */ pbinDatabaseFP = fopen(kST_bin_base, "rb"); if (pbinDatabaseFP) { /*------------------------------ CYCLE #1 (analysis) ------------------*/ while (fread(&pbinBuff, sizeof(pbinBuff), 1, pbinDatabaseFP)) { if (selected == pbinBuff.ELEM) { moreLineData(&pbinBuff, &more); /* Calc some more data. */ audioHertz = more.frequency * transpositionRatio; /* Exclude out-of-range-freqs from analysis. */ /* There may slip through some freqs that will be too weak in the second step! */ if ((audioHertz > lowestFreq) && (audioHertz < nyquist)) { if (audioHertz < loFreq) loFreq = audioHertz; if (audioHertz > hiFreq) hiFreq = audioHertz; if (more.Avalue < loAmp) loAmp = more.Avalue; if (more.Avalue > hiAmp) hiAmp = more.Avalue; if (pbinBuff.LOW.E < ELOWlowest) ELOWlowest = pbinBuff.LOW.E; if (pbinBuff.LOW.E > ELOWhighest) ELOWhighest = pbinBuff.LOW.E; if (pbinBuff.UPP.E < EUPPlowest) EUPPlowest = pbinBuff.UPP.E; if (pbinBuff.UPP.E > EUPPhighest) EUPPhighest = pbinBuff.UPP.E; } } } /*--------------------- Print statistics for the selected metals: ------------*/ if (msg) { fprintf(msg, "-------- c01_massiveCloud() element %d: --------\n\ loAmp = %.8f; hiAmp = %.8f; RATIO=%.2f.\nloFreq = %.6f; hiFreq = %.6f; RATIO=%.2f.\n", selected, loAmp, hiAmp, hiAmp / loAmp, loFreq, hiFreq, hiFreq / loFreq); fprintf(msg, " ELOWlowest = %.4f.\n", ELOWlowest); fprintf(msg, " ELOWhighest = %.4f.\n", ELOWhighest); fprintf(msg, " EUPPlowest = %.4f.\n", EUPPlowest); fprintf(msg, " EUPPhighest = %.4f.\n", EUPPhighest); } /*---------------- Linear duration compensation function: ------------------------------*/ /* d(loF) = 1 1 = a loF + b a = 0.5 / (loF - hiF) */ /* d(hiF) = 0.5 0.5 = a hiF + b - 0.5 = (0.5 / (loF - hiF)) hiF + b */ /* d(F) = a F + b ------------------- b = 0.5 - (0.5 hiF / (loF - hiF)) */ /* 0.5 = a (loF - hiF) */ d = loFreq - hiFreq; durA = 0.5 / d; /* A=slope and B=offset. */ durB = 0.5 - (0.5 * hiFreq / d); /*---------------- Linear bass-boost-filter-function (per element): --------------------*/ /* SAME "d" as with duration may be used: highest freq (per element) gets -6.021 dB. */ /*---------------------------- CYCLE #2: Post (audio-)wavelets into linked list. -------*/ rewind(pbinDatabaseFP); if (msg) { fprintf(msg, "1/transpositionRatio = %.1Lf.\n", 1.0 / transpositionRatio); fprintf(msg, "'effective duration' = %.6Lf s.\n", duration); fprintf(msg, "Using phase = %d.\n", (int)phase); } while (fread(&pbinBuff, sizeof(pbinBuff), 1, pbinDatabaseFP)) { /*----------------------------------------------- ELEMENT / ION - selector: */ if (selected == pbinBuff.ELEM) { moreLineData(&pbinBuff, &more); /* Calc some more data. */ /*----------------------------------------------------------------------*/ audioHertz = more.frequency * transpositionRatio; if ((audioHertz > lowestFreq) && (audioHertz < nyquist)) { /*------------------ Less brickwall-shaped filtering: --------------*/ if (audioHertz < aboveLowestFreq) a = (audioHertz - lowestFreq) / aboveHertz; /* Rise to 1 within 1 minor third. */ else if (audioHertz > belowNyquist) a = (nyquist - audioHertz) / belowHertz; /* Fall to 0 within 1 major third. */ else a = 1.0; /*---------------- Frequency-dependant Compensation per element: ---------------*/ /* Only lowest freq of selected element gets unit-duration and unit-amplit., */ /* all higher frequencies sound shorter. loFreq -> 1, hiFreq -> 0.5. */ d = (durA * audioHertz) + durB; /*------------------ Bass boost-filter (per element): --------------*/ a *= d; /* Highest frequency per element -6.021 dB. */ /* ----------------- Amplitude: ------------------------------------*/ /* Compress amplitude-range by approx 4th-power-root. */ a *= strength * pow(1.90e-13 * more.Avalue, 0.26); /*-------------------- Amplitude treshold (23 bit) -----------------*/ if (a >= 1.192093E-7) { /*------------------------ Panning: ---------------------------------------*/ if (pbinBuff.LOW.J == pbinBuff.UPP.J) p = 0.0; else if (pbinBuff.LOW.J > pbinBuff.UPP.J) /* Depend upon quantum-states. */ p = +0.5; else p = -0.5; if (linesUsed & 1L) /* Alternate between left and right channel. */ p += 0.118; else p -= 0.118; /*---------------- Duration & starttime: ---------------------------*/ dur = duration * d; /* Only lowest freq gets unit-duration. */ if (addWAVELET(E, msg, rgb, /* Hz */ audioHertz, /* amp */ a, /* pan */ 0.5 * p, /* Less extreme. */ /* top */ starttime + (dur * pbinBuff.LOW.E / ELOWhighest), /* dur */ dur, /* env */ kENV_ExpDecay, /* WAS: kENV_Gaussian. */ /* pha */ 0)) /* Must be 0! -1 = sync with other oscillators. */ { if (msg) fprintf(msg, "Illegal wavelet!\n"); e = 3; goto clFile; } if (addWAVELET(E, msg, rgb, /* Hz */ audioHertz, /* amp */ a, /* pan */ -p, /* Opposite channel. */ /* top */ starttime - (dur * pbinBuff.UPP.E / EUPPhighest), /* dur */ dur, /* Top at starttime + DUR/2. */ /* env */ kENV_Gaussian, /* pha */ -1)) /* -1 = sync with other oscillators. */ { if (msg) fprintf(msg, "Illegal wavelet!\n"); e = 3; goto clFile; } linesUsed++; } else { linesSkipped++; if (msg) fprintf(msg, "SKIPPED-AMP %d: Hz=%12.6Lf lggf=%5.2f.\n", pbinBuff.ELEM, audioHertz, pbinBuff.LOGGF); } } else { linesSkipped++; if (msg) fprintf(msg, "SKIPPED-FRQ %d: Hz=%12.6Lf lggf=%5.2f.\n", pbinBuff.ELEM, audioHertz, pbinBuff.LOGGF); } printLineEssential(&pbinBuff, msg); /* NULL, stdout or some FILE*. */ printLineDerived(&more, msg); } linesRead++; } if (msg) fprintf(msg, " linesUsed = %ld.\nlinesSkipped = %ld.\n", linesUsed, linesSkipped); if (linesRead != kKuruczLinesTotal) { if (msg) fprintf(msg, "Error reading binary database lines!\n"); e = 2; } clFile: fclose(pbinDatabaseFP); } else { if (msg) fprintf(msg, "Could not open binary database file '%s'!\n", kST_bin_base); e = 1; } return(e); } /*------------------------------------------------------------------------------------------------*/ /* Starting with Ni and H, ending with Cu. Andrea Rossi and his E-Cat. */ short c08_rossi2011(ENGINEp E, FILE* msg) { short e; if (msg != NULL) fprintf(msg, "Starting c08_rossi2011().\n"); /*---------------------------- Ni: ------------------------------------------*/ e = fuckedCloud2011(2800, /* 2800=Ni (100*Atomic num + ionisation lvl). */ 0.34, /* Linear overall amplitude (0.40 for Ni solo). */ -1, /* -1 = sync with other oscillators. */ 70.00, /* starttime in seconds. (TOP=starttime + dur/2) */ 20.00, /* 'effective duration' in seconds. */ E, msg, 0x00FF00); /* GREEN */ if (e) goto finish2011; /*---------------------------- H: ------------------------------------------*/ e = fuckedCloud2011(100, /* 100=H (100*Atomic num + ionisation lvl). */ 0.14, /* Linear overall amplitude (0.26 is bit too loud (sharp)). */ -1, /* -1 = sync with other oscillators. */ 85.00, /* starttime in seconds. */ 5.00, /* 'effective duration' in seconds. */ E, msg, 0xFF0000); /* RED */ if (e) goto finish2011; /*---------------------------- Cu: ------------------------------------------*/ e = fuckedCloud2011(2900, /* 2900=Cu (100*Atomic num + ionisation lvl). */ 0.80, /* Linear overall amplitude (.76=ok. 1.03 for Cu solo). */ -1, /* -1 = sync with other oscillators. */ 100.00, /* starttime in seconds. (TOP=starttime + dur/2) */ 20.00, /* 'effective duration' in seconds. */ E, msg, 0x0000FF); /* BLUE */ /*--------------------------------------------------------------------------------*/ finish2011: if (msg != NULL) fprintf(msg, "Finished, c08_rossi2011() = %d.\n", e); return e; }