/* Spectroscopic Toolkit version 1.93, july 12, 2008. Copyright (c) 2000-2008 - 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 /* Standard headers. */ #include #include #include "ST_wavelets.h" /* Prototype for addWAVELET(). */ #include "c00.h" /* To check prototypes. */ /*----------------------------------------------------------------------------*/ /* Instead of addWAVELET() one may use this STAW() macro. Make sure though that arguments 'E' and 'msg' have the correct names, and don't put semicolons (;) after STAW() calls. */ #define STAW(f,a,p,t,d,e,s) {if(addWAVELET(E,msg,(0),(f),(a),(p),(t),(d),(e),(s)))\ return 1;} /*----------------------------------------------------------------------------*/ /* A small test, not using the database. Simply puts 4 wavelets in the linked list. Last argument (PHA=1) yields zero-phase cosines (instead of sines) at TOP. */ short c00_gaussTest(ENGINEp E, FILE* msg) { /* Freq: Lin-amp: Panning: Top: Dur: Envelope: Phase: */ /* Hertz -1..+1 -1..+1 s s */ STAW( 120.0, -1.00, -1.00, 4.00, 0.40, kENV_Gaussian, 1) /* Using +1.00 here, would causes overflow (see c00_clipTest()). */ STAW( 130.0, -1.00, +1.00, 8.00, 0.40, kENV_Gaussian, 1) STAW( 440.0, 0.10, -0.75, 12.00, 2.00, kENV_Gaussian, 1) STAW( 8800.0, 0.20, +0.25, 14.00, 2.00, kENV_Gaussian, 1) /* 0=sine. */ STAW( 220.0, 0.50, -1.00, 18.00, 1.00, kENV_Gaussian, 0) return 0; } /*----------------------------------------------------------------------------*/ /* Clip test, not using the database. Last argument (PHA=1) yields zero-phase cosined (instead of sines) at TOP. Should fail. */ short c00_clipTest(ENGINEp E, FILE* msg) { /* Freq: Lin-amp: Panning: Top: Dur: Envelope: Phase: */ /* Hertz -1..+1 -1..+1 s s */ STAW( 120.0, +1.00, -1.00, 4.00, 0.40, kENV_Gaussian, 1) /* AMP=+1.00, is designed to cause overflow. At 24 and 16-bit */ /* output-sizes, -1.0 for such a short period (0.4 s) will NOT */ /* cause underflow, because -1 is allowed, but +1 is not. */ return 0; } /*----------------------------------------------------------------------------*/ /* Another test/example, again not using the database. Puts some overtone- wavelets in the linked list. */ short c00_overtoneTest(ENGINEp E, FILE* msg) { short n, m; long double d, s; for (m=1; m<=8; m++) for (n=m; n<=64; n++) /* n is harmonics-number, fund=60Hz. */ { d = 1.0 / (long double)n; /* Higher harmonics are shorter. */ s = 5.6 + /* Start-inflection-point. */ (2.0*(long double)m) + 0.1 * (long double)(n-6*m); if (addWAVELET(E, msg, 0, /* rgb=0 for black. */ (long double)n * 60.0, /* 60 Hertz as fundamental. */ 0.4 * d, /* amplitude decreasing with time. */ -0.5 + (long double)(n-1)/71.0, /* pan from left to right. */ s + 0.5 * d, /* top (@ start-infl + half dur). */ 3.0 * d, /* duration in seconds. */ kENV_Gaussian, -1)) /* -1 means in sync with other oscillators. */ { if (msg != NULL) /* Optional diagnostics. */ fprintf(msg, "'c00_example1()' stopped!\n"); return 1; } } return 0; } /*----------------------------------------------------------------------------*/ short c00_phaseTest(ENGINEp E, /* Connecting overlapping in-phase wavelets */ FILE* msg) /* with exactly the same frequency. */ { /* Freq: Lin-amp: Panning: Top: Dur: Envelope: Phase: */ /* Hertz -1..+1 -1..+1 s s -1|0|1 */ /*------- Connecting at inflection points @ 0.6065: QUITE SMOOTH */ STAW( 880.0, 0.50, +1.00, 4.00, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 4.20, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 4.40, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 4.60, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 4.80, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 5.00, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 5.20, 0.20, kENV_Gaussian, -1) STAW( 880.0, 0.50, +1.00, 5.40, 0.20, kENV_Gaussian, -1) /*----------------- Connecting beyond inflection points @ 0.5: BUBBLES */ /* -6 dB points at TOP-0.588705011*DUR and TOP+0.588705011*DUR. */ STAW( 866.0, 0.50, -1.00, 8.00, 0.40, kENV_Gaussian, -1) STAW( 866.0, 0.50, -1.00, 8.470964, 0.40, kENV_Gaussian, -1) STAW( 866.0, 0.50, -1.00, 8.941928, 0.40, kENV_Gaussian, -1) STAW( 866.0, 0.50, -1.00, 9.412892, 0.40, kENV_Gaussian, -1) /*-------------------- Connecting at inflection points @ 0.6065: A GONG */ STAW( 800.0, 0.50, +1.00, 12.00, 0.10, kENV_Gaussian, -1) /* 12.05 */ STAW( 800.0, 0.40, +1.00, 12.15, 0.20, kENV_Gaussian, -1) /* 12.25 */ STAW( 800.0, 0.30, +1.00, 12.45, 0.40, kENV_Gaussian, -1) /* 12.65 */ STAW( 800.0, 0.20, +1.00, 13.05, 0.80, kENV_Gaussian, -1) /* 13.45 */ STAW( 800.0, 0.10, +1.00, 14.25, 1.60, kENV_Gaussian, -1) /* 15.05 */ return 0; } /*----------------------------------------------------------------------------*/ /* Exponential rise and decay. Make sure rises end with a zero-phase sine, and decays start with a zero-phase sine. */ short c00_expTest(ENGINEp E, FILE* msg) /* Exponential rise and decay. */ { /* Freq: Lin-amp: Panning: Top: Dur: Envelope: Phase: */ /* Hertz -1..+1 -1..+1 s s -1|0|1 */ STAW( 440.0, 0.50, +1.00, 16.33, 1.00, kENV_ExpRise, 0) STAW( 880.0, -1.00, -1.00, 20.21, 0.30, kENV_ExpRise, 0) STAW( 500.0, 0.50, +1.00, 31.18, 1.98, kENV_ExpRise, 0) STAW( 940.0, 0.50, -1.00, 39.73, 0.033, kENV_ExpRise, 0) STAW( 1080.0, -1.00, +1.00, 41.16, 0.01, kENV_ExpRise, 0) STAW( 150.0, 0.75, -1.00, 50.582, 2.70, kENV_ExpRise, 0) STAW( 150.0, 0.75, -1.00, 50.582, 2.70, kENV_ExpDecay, 0) return 0; }