/* Spectroscopic Toolkit version 1.92 by Pieter Suurmond, september 7, 2006. Copyright (c) 2000-2006 - 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. More Hydrogen studies (based on earlier ST.c03_H). */ #include /* Standard headers. */ #include #include #include "ST_wavelets.h" /* Prototype addWAVELET(). */ #include "ST_pconv.h" #include "c06_JEBASE.h" /* Small database in mem for easier line-access. */ /* Object c06_HBASE.o must be linked for Hsplit. */ #include "c00.h" /*---------------------------------------------------------------------------------------------*/ short c06_Hsplit(ENGINEp E, FILE* msg) { JDIF_SERIES* hseries; pieterPacked *hline; derivedData more; /* See ST.gfall.pbin.c. */ unsigned long ampSkipped = 0, frqSkipped = 0; short e = 0; double top, audioHertz, a; /*------------------------------------------------------------ Frequency & time transpositions: */ 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; /*-----------------------------------------------------------------------------------------------*/ int dj = 0, /* We only regard 1 J difference for now. */ lj, le, de; /* We vary these. */ hseries = init_JEBASE(msg); /* Some sorted hydrogen-lines. */ if (!hseries) { if (msg) fprintf(msg, "init_JEBASE() failed!\n"); return 1; } top = 0.0; for (lj=0; lj<8; /* hseries->JLOWseries[dj].numJLOW; */ lj++) { /* 9, 10, 11, etc are too low in frequency. */ for (le=0; leJLOWseries[dj].ELOWseries[lj].numELOW; le++) { for (de=hseries->JLOWseries[dj].ELOWseries[lj].EDIFseries[le].numEDIF-1; de>=0; de--) { if (msg) fprintf(msg, "Hydrogen dj=%d lj=%d le=%d de=%d:\n", dj, lj, le, de); hline = ask_JEBASE(hseries, dj, lj, le, de); /* Obtain line data. */ moreLineData(hline, &more); /* Derive some more. */ printLineEssential(hline, msg); /* printLineDerived(&more, msg); */ audioHertz = more.frequency * transpositionRatio; /* Transpose. */ if ((audioHertz >= lowestFreq) && (audioHertz <= nyquist)) { /*-------------------------------------------- Less brickwall: ---*/ 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; /* ----------------- Amplitude: ------------------------------------*/ /* Compress amplitude-range (per section) by 4th-power-root. */ a *= 5.0 * pow(1.0e-12 * more.Avalue, 0.25); /*-------------------- Amplitude treshold (23 bit) -----------------*/ if (a >= 1.192093E-7) { if (addWAVELET (E, msg, 0, /* frq */ audioHertz, /* amp */ a, /* pan */ 0.0, /* Center. */ /* top */ 20.0 + top, /* Almost fully apart. */ /* dur */ 0.1, /* 1 second per line. */ /* env */ kENV_ExpDecay, /* syn */ 0)) /* 0 = sync with envelope. */ { if (msg) fprintf(msg, "Illegal wavelet!\n"); e = 55; goto err; } top += 1.0; } else { if (msg) fprintf(msg, "Skipping line dj=%d lj=%d le=%d de=%d (AMP too low).\n", dj, lj, le, de); ampSkipped++; } } else { if (msg) fprintf(msg, "Skipping line dj=%d lj=%d le=%d de=%d (FRQ=%.2f).\n", dj, lj, le, de, audioHertz); frqSkipped++; } } } } if (msg) { fprintf(msg, "Skipped %ld lines (AMP).\n", ampSkipped); fprintf(msg, "Skipped %ld lines (FRQ).\n", frqSkipped); } err: free_JEBASE(&hseries); /* Also clears referring variable. */ return e; } /*---------------------------------------------------------------------------------------------*/ short c06_H_LymanBalmerPaschen(ENGINEp E, FILE* msg) { JDIF_SERIES* hseries; pieterPacked *hline; derivedData more; /* See ST.gfall.pbin.c. */ unsigned long ampSkipped = 0, frqSkipped = 0; short e = 0; double top, audioHertz, a; /*------------------------------------------------------------ Frequency & time transpositions: */ 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; /*-----------------------------------------------------------------------------------------------*/ int dj = 0, /* We only regard 1 J difference for now. */ lj, le, de; /* We vary these. */ char* name; hseries = init_JEBASE(msg); /* Some sorted hydrogen-lines. */ if (!hseries) { if (msg) fprintf(msg, "init_JEBASE() failed!\n"); return 1; } top = 0.0; for (lj=0; ljJLOWseries[dj].numJLOW; lj++) { /* lj 9, 10, 11 are too low in frequency. */ switch (lj) { case 0: name = "Lyman"; break; case 1: name = "Balmer"; break; case 2: name = "Paschen"; break; default: name = "(H-series)"; } if (msg) fprintf(msg, "\n---------------- %s: ----------------\n", name); for (le=0; leJLOWseries[dj].ELOWseries[lj].numELOW; le++) { for (de=hseries->JLOWseries[dj].ELOWseries[lj].EDIFseries[le].numEDIF-1; de>=0; de--) { if (msg) fprintf(msg, "Hydrogen dj=%d lj=%d le=%d de=%d:\n", dj, lj, le, de); hline = ask_JEBASE(hseries, dj, lj, le, de); /* Obtain line data. */ moreLineData(hline, &more); /* Derive some more. */ printLineEssential(hline, msg); printLineDerived(&more, msg); audioHertz = more.frequency * transpositionRatio; /* Transpose. */ if ((audioHertz >= lowestFreq) && (audioHertz <= nyquist)) { /*-------------------------------------------- Less brickwall: ---*/ 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; /* ----------------- Amplitude: ------------------------------------*/ /* Compress amplitude-range (per section) by 4th-power-root. */ a *= 5.0 * pow(1.0e-12 * more.Avalue, 0.25); /*-------------------- Amplitude treshold (23 bit) -----------------*/ if (a >= 1.192093E-7) { if (addWAVELET (E, msg, 0, /* frq */ audioHertz, /* amp */ a, /* pan */ 0.0, /* Center. */ /* top */ top, /* Almost fully apart. */ /* dur */ 0.1, /* 1 second per line. */ /* env */ kENV_ExpDecay, /* syn */ 0)) /* 0 = sync with envelope. */ { if (msg) fprintf(msg, "Illegal wavelet!\n"); e = 55; goto err; } top += 1.0; } else { if (msg) fprintf(msg, "Skipping line dj=%d lj=%d le=%d de=%d (AMP too low).\n", dj, lj, le, de); ampSkipped++; } } else { if (msg) fprintf(msg, "Skipping line dj=%d lj=%d le=%d de=%d (FRQ=%.2f).\n", dj, lj, le, de, audioHertz); frqSkipped++; } } } } if (msg) { fprintf(msg, "Skipped %ld lines (AMP).\n", ampSkipped); fprintf(msg, "Skipped %ld lines (FRQ).\n", frqSkipped); } err: free_JEBASE(&hseries); /* Also clears referring variable. */ return e; }