00001 #ifndef INCLUDE_OSCILLATOR_H 00002 #define INCLUDE_OSCILLATOR_H 00003 /* 00004 * This is the Loris C++ Class Library, implementing analysis, 00005 * manipulation, and synthesis of digitized sounds using the Reassigned 00006 * Bandwidth-Enhanced Additive Sound Model. 00007 * 00008 * Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY, without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 * 00024 * 00025 * Oscillator.h 00026 * 00027 * Definition of class Loris::Oscillator, a Bandwidth-Enhanced Oscillator. 00028 * 00029 * Kelly Fitz, 31 Aug 1999 00030 * loris@cerlsoundgroup.org 00031 * 00032 * http://www.cerlsoundgroup.org/Loris/ 00033 * 00034 */ 00035 00036 #include "NoiseGenerator.h" 00037 #include <vector> 00038 00039 // begin namespace 00040 namespace Loris { 00041 00042 class Breakpoint; 00043 00044 // --------------------------------------------------------------------------- 00045 // class Oscillator 00046 // 00047 // Class Oscillator represents the state of a single bandwidth-enhanced 00048 // sinusoidal oscillator used for synthesizing sounds from Reassigned 00049 // Bandwidth-Enhanced analysis data. Oscillator encapsulates the oscillator 00050 // state, including the instantaneous radian frequency (radians per 00051 // sample), amplitude, bandwidth coefficient, and phase, and a 00052 // bandlimited stochastic modulator. 00053 // 00054 // Class Synthesizer uses an instance of Oscillator to synthesize 00055 // bandwidth-enhanced Partials. 00056 // 00057 class Oscillator 00058 { 00059 // --- implementation _-- 00060 00061 // stochastic modulators: 00062 NoiseGenerator bwModulator; 00063 00064 // instantaneous oscillator state: 00065 double i_frequency; // radians per sample 00066 double i_amplitude; // absolute 00067 double i_bandwidth; // bandwidth coefficient (noise energy / total energy) 00068 00069 // accumulating phase state: 00070 double determ_phase; // deterministic phase in radians 00071 00072 // --- interface --- 00073 public: 00074 // --- construction --_ 00075 Oscillator( void ); 00076 /* Construct a new Oscillator with all state parameters initialized 00077 to 0. 00078 */ 00079 00080 00081 // Copy, assignment, and destruction are free. 00082 // 00083 // Copied and assigned Oscillators have the duplicate state 00084 // variables and the filters have the same coefficients, 00085 // but the state of the filter delay lines is not copied. 00086 00087 // -- the new way -- 00088 00089 void resetEnvelopes( const Breakpoint & bp, double srate ); 00090 /* Reset the instantaneous envelope parameters 00091 (frequency, amplitude, bandwidth, and phase). 00092 The sample rate is needed to convert the 00093 Breakpoint frequency (Hz) to radians per sample. 00094 */ 00095 00096 void resetPhase( double ph ); 00097 /* Reset the phase of the Oscillator to the specified 00098 value, and clear the accumulated phase modulation. (?) 00099 Or not. 00100 This is done when the amplitude of a Partial goes to 00101 zero, so that onsets are preserved in distilled 00102 and collated Partials. 00103 */ 00104 00105 void oscillate( double * begin, double * end, 00106 const Breakpoint & bp, double srate ); 00107 /* Accumulate bandwidth-enhanced sinusoidal samples modulating the 00108 oscillator state from its current values of radian frequency, amplitude, 00109 and bandwidth to the specified target values. Accumulate samples into 00110 the half-open (STL-style) range of doubles, starting at begin, and 00111 ending before end (no sample is accumulated at end). The caller must 00112 insure that the indices are valid. Target frequency and bandwidth are 00113 checked to prevent aliasing and bogus bandwidth enhancement. 00114 */ 00115 00116 /* Access parameters of the Oscillator 00117 (why were these removed?) 00118 */ 00119 double amplitude( void ) const { return i_amplitude; } 00120 double bandwidth( void ) const { return i_bandwidth; } 00121 double phase( void ) const { return determ_phase; } 00122 double radianFreq( void ) const { return i_frequency; } 00123 00124 /* Used to allow state mutation too, why not anymore? */ 00125 00126 }; // end of class Oscillator 00127 00128 } // end of namespace Loris 00129 00130 #endif /* ndef INCLUDE_OSCILLATOR_H */
1.3.4