/* Spectroscopic Toolkit version 1.65 by Pieter Suurmond, july 22, 2003. Using the binary database-file 'gfall.pbin', produced by the 'pconv'-program that reads Robert Kurucz's latest data file. More Hydrogen studies (based on earlier ST.c03_H). */ #include /* Standard headers. */ #include #include #include "ST_wavelets.h" /* Prototype addWAVELET(). */ #include "gfall.pbin.h" /* Defines structure of the binary database-file, */ /* same header as included in the 'pconv'-program. */ #include "ST_more.pbin.h" /* To extract some more out of the database. */ /* But also path to the database. */ #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 addHTone(double TOP, double DUR, double AMP, double PAN, short ENV, int lj, int de_inv, /* de is inversed, low to hi now. */ JDIF_SERIES* HS, ENGINE E, FILE* msg) /* jd kept constant and le ...? */ { pieterPacked *hline; derivedData more; double 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 le = 0, de; /* dj */ de = HS->JLOWseries[0].ELOWseries[lj].EDIFseries[le].numEDIF - 1 - de_inv; /* INVERSE DE. */ /* dj le=1,2 not explored yet. */ hline = ask_JEBASE(HS, 0, lj, le, de); /* Try to obtain line data. */ if (!hline) { if (msg) fprintf(msg, "ask_JEBASE(lj=%d le=%d de=%d) = NULL !!!\n", lj, le, de); return 1; } moreLineData(hline, &more); /* Derive some more. */ 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 5th-power-root. */ a *= 0.008 * pow(1.0e-12 * more.Avalue, 0.2); /* Lower freqs (lower lj) louder: */ a *= (double)(2 + lj); /* Lower bells (lower bell = higher de) louder: */ a *= (double)(4 + de); /*-------------------- Amplitude treshold (23 bit) -----------------*/ if (a >= 1.192093E-7) { if (msg) fprintf(msg, "%2d,%2d: ",lj, de_inv); /* Inversed notation. */ if (addWAVELET (E, msg, /* frq */ audioHertz, /* amp */ a * AMP, /* pan */ PAN, /* Panning. */ /* top */ TOP, /* in seconds. */ /* dur */ DUR, /* 1 second per line. */ /* env */ ENV, /* syn */ 0)) /* 0 = sync with envelope. */ { if (msg) fprintf(msg, "Illegal wavelet!\n"); return 2; } } else { if (msg) fprintf(msg, "Skipping line lj=%d le=%d de=%d (AMP too low).\n", lj, le, de); return 3; } } else { if (msg) fprintf(msg, "Skipping line lj=%d le=%d de=%d (FRQ=%.2f).\n", lj, le, de, audioHertz); return 4; } return 0; } /*---------------------------------------------------------------------------------------------*/ short c06_Hmelody(ENGINE E, FILE* msg) { JDIF_SERIES* hseries; short e = 0; short n; hseries = init_JEBASE(msg); /* Some sorted hydrogen-lines. */ if (!hseries) { if (msg) fprintf(msg, "init_JEBASE() failed!\n"); return 1; } else if (msg) fprintf(msg, "Running c06_Hmelody...\n"); #if 0 for (n=0; n<1000; n++) { /* e |= addHTone((double)n * 0.127, 0.25/(double)(1+(n%23)), kENV_ExpDecay, 0, n%24, hseries, E, msg); */ e |= addHTone((double)n * 0.128, 0.50/(double)(1+(n%24)), kENV_ExpDecay, 1, n%24, hseries, E, msg); e |= addHTone((double)n * 0.129, 1.00/(double)(1+(n%25)), kENV_ExpDecay, 2, n%24, hseries, E, msg); } #endif #if 0 /*----------------------------------------------------------------------------------------*/ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone(20.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 0, hseries, E, msg); e |= addHTone(21.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 1, hseries, E, msg); e |= addHTone(22.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 2, hseries, E, msg); e |= addHTone(23.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 3, hseries, E, msg); e |= addHTone(24.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 4, hseries, E, msg); e |= addHTone(25.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 5, hseries, E, msg); e |= addHTone(26.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 6, hseries, E, msg); e |= addHTone(27.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 7, hseries, E, msg); e |= addHTone(28.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 8, hseries, E, msg); e |= addHTone(29.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 9, hseries, E, msg); e |= addHTone(30.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 0, hseries, E, msg); e |= addHTone(31.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 1, hseries, E, msg); e |= addHTone(32.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 2, hseries, E, msg); e |= addHTone(33.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 3, hseries, E, msg); e |= addHTone(34.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 4, hseries, E, msg); e |= addHTone(35.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 5, hseries, E, msg); e |= addHTone(36.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 6, hseries, E, msg); e |= addHTone(37.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 7, hseries, E, msg); e |= addHTone(38.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 8, hseries, E, msg); e |= addHTone(39.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 9, hseries, E, msg); #endif #if 1 /*----------------------------------------------------------------------------------------*/ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone( 0.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 0, hseries, E, msg); e |= addHTone( 1.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 1, hseries, E, msg); e |= addHTone( 2.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 2, hseries, E, msg); e |= addHTone( 3.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 3, hseries, E, msg); e |= addHTone( 5.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 4, hseries, E, msg); e |= addHTone( 6.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 5, hseries, E, msg); e |= addHTone( 8.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 1, 6, hseries, E, msg); e |= addHTone( 9.00, 1.50, 1.0, 0.0, kENV_ExpDecay, 1, 7, hseries, E, msg); /*----------------------------------------------------------------------------------------*/ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone( 0.0, 1.00, 1.0, 0.0, kENV_ExpDecay, 2, 11, hseries, E, msg); e |= addHTone( 2.0, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 7, hseries, E, msg); /* 7 little too low. 9=best? */ e |= addHTone( 3.0, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 3, hseries, E, msg); e |= addHTone( 4.0, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 4, hseries, E, msg); e |= addHTone( 5.0, 1.00, 1.0, 0.0, kENV_ExpDecay, 2, 1, hseries, E, msg); e |= addHTone( 7.0, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 5, hseries, E, msg); e |= addHTone( 8.0, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 6, hseries, E, msg); e |= addHTone( 9.0, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 7, hseries, E, msg); e |= addHTone(10.0, 1.00, 1.0, 0.0, kENV_ExpDecay, 2, 2, hseries, E, msg); e |= addHTone(12.0, 1.00, 1.0, 0.0, kENV_ExpDecay, 2, 0, hseries, E, msg); #endif #if 0 /*----------------------------------------------------------------------------------------*/ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone(40.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 12, hseries, E, msg); e |= addHTone(42.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 5, hseries, E, msg); e |= addHTone(44.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 6, hseries, E, msg); e |= addHTone(46.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 4, hseries, E, msg); e |= addHTone(48.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 5, hseries, E, msg); e |= addHTone(50.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 1, 3, hseries, E, msg); /*----------------------------------------------------------------------------------------*/ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone(41.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 2, hseries, E, msg); e |= addHTone(42.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 5, hseries, E, msg); e |= addHTone(43.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 1, hseries, E, msg); e |= addHTone(44.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 4, hseries, E, msg); e |= addHTone(45.00, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 5, hseries, E, msg); e |= addHTone(45.50, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 6, hseries, E, msg); e |= addHTone(46.00, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 4, hseries, E, msg); e |= addHTone(46.50, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 3, hseries, E, msg); e |= addHTone(47.00, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 2, hseries, E, msg); e |= addHTone(47.50, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 1, hseries, E, msg); e |= addHTone(48.00, 0.50, 1.0, 0.0, kENV_ExpDecay, 2, 0, hseries, E, msg); e |= addHTone(49.00, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 5, hseries, E, msg); e |= addHTone(49.50, 0.25, 1.0, 0.0, kENV_ExpDecay, 2, 7, hseries, E, msg); e |= addHTone(50.00, 1.00, 1.0, 0.0, kENV_ExpDecay, 2, 40, hseries, E, msg); #endif free_JEBASE(&hseries); /* Also clears referring variable. */ return e; } /*------------------------------------------------------------------------*/ /* Functions called by c07_composition2003_part1(): */ /*-------------------------------------------------------------*/ short c06_HcolorAu2003(double st, double d, ENGINE E, FILE* msg) { JDIF_SERIES* hseries; /* Play along with c02_smear(7900,..); */ short e = 0; hseries = init_JEBASE(msg); /* Sorted hydrogen-lines. */ if (!hseries) { if (msg) fprintf(msg, "init_JEBASE() failed!\n"); return 1; } else if (msg) fprintf(msg, "Running c06_HcolorAu2003...\n"); /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone(st + 0.0310 * d, 0.0620 * d, 0.009, 0.0, kENV_Gaussian, 1, 3, hseries, E, msg); /* 4th line = 664.554862 Hz. */ /* First Au tone is lowest tone: A FRQ=109.456653, TOP=9.3078, DUR=2.6156. Color as 6th 'harmonic', very subtle. */ free_JEBASE(&hseries); /* Also clears referring variable. */ return e; } /*-------------------------------------------------------------*/ short c06_HcolorAg2003(double st, double d, ENGINE E, FILE* msg) { JDIF_SERIES* hseries; short e = 0; int edif; double dur, inflectStart; hseries = init_JEBASE(msg); /* Some sorted hydrogen-lines. */ if (!hseries) { if (msg) fprintf(msg, "init_JEBASE() failed!\n"); return 1; } if (msg) fprintf(msg, "Running c06_HcolorAg2003...\n"); /* Ag plays cadens: B (1001.471801) ascends to E (1316.874668 plus 1322.420292 Hz). */ /* TOP=88.3835 TOP=91.1604 TOP=92.0480 */ /* DUR=1.7305 DUR=1.3151 DUR=1.3078 */ /* H counterpoint above it: F# descends to E (as respectively 3rd and 2nd 'harmonic'). */ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone(st + 0.905 * d, 0.0410 * d, 0.450, 0.10, kENV_Gaussian, 0, 87, hseries, E, msg); /* TOP=88.3672 DUR=1.7297 88th line = 2990.030072 Hz. */ /* TOP: DUR: AMP: PAN: ENV: lj: de_inv: JDIF_SERIES*: ENGINE*: FILE*: */ e |= addHTone(st + 0.982 * d, 0.0360 * d, 0.015, -0.25, kENV_Gaussian, 0, 2, hseries, E, msg); /* TOP=91.6156 DUR=1.5187 3rd line = 2658.221684 Hz. */ free_JEBASE(&hseries); /* Also clears referring variable. */ return e; }