Line data Source code
1 : #pragma once 2 : 3 : class Chirp { 4 : 5 : public: 6 : 7 : // constructor 8 : Chirp(); 9 : 10 : // initializes the chirp object 11 : void init(float time_record, float frequency_start_hz, float frequency_stop_hz, float time_fade_in, float time_fade_out, float time_const_freq); 12 : 13 : // determine chirp signal output at the specified time and amplitude 14 : float update(float time, float waveform_magnitude); 15 : 16 : // accessor for the current waveform frequency 17 1042608 : float get_frequency_rads() {return waveform_freq_rads; } 18 : 19 : // Return true if chirp is completed 20 0 : bool completed() const { return complete; } 21 : 22 : private: 23 : // Total chirp length in seconds 24 : float record; 25 : 26 : // Chirp oscillation amplitude 27 : float magnitude; 28 : 29 : // Chirp start frequency in rad/s 30 : float wMin; 31 : 32 : // Chirp end frequency in rad/s 33 : float wMax; 34 : 35 : // Amplitude fade in time in seconds 36 : float fade_in; 37 : 38 : // Amplitude fade out time in seconds 39 : float fade_out; 40 : 41 : // Time that chirp will remain at the min frequency before increasing to max frequency 42 : float const_freq; 43 : 44 : // frequency ratio 45 : float B; 46 : 47 : // current waveform frequency in rad/s 48 : float waveform_freq_rads; 49 : 50 : // current amplitude of chirp 51 : float window; 52 : 53 : // output of chirp signal at the requested time 54 : float output; 55 : 56 : // True if chirp is complete, reset to false on init 57 : bool complete; 58 : 59 : };