// -------------------------------------------------------------- // -------------------------------------------------------------- #ifndef _LFO_H_ #define _LFO_H_ #include "synth_defs.h" #include "noise.h" #define LFO_SH_ALPHA 0.002 // S&H smoothing #define LFO_KE ((synth_float_t)(1-exp(-1))) // -------------------------------------------------------------- // Types // -------------------------------------------------------------- enum { LFO_WAVEFORM_SINE, LFO_WAVEFORM_COSINE, LFO_WAVEFORM_SAW, LFO_WAVEFORM_SQUARE, LFO_WAVEFORM_TRIANGLE, LFO_WAVEFORM_SH_UNI, LFO_WAVEFORM_SH_GAUSS, LFO_WAVEFORM_SINE_REV, LFO_WAVEFORM_COSINE_REV, LFO_WAVEFORM_SAW_REV, LFO_WAVEFORM_SQUARE_REV, LFO_WAVEFORM_TRIANGLE_REV, LFO_NUM_WAVEFORMS }; enum { LFO_PARAM2_WAVEFORM, LFO_PARAM2_FREQ, LFO_PARAM2_SMOOTH, LFO_PARAM2_DELAY, LFO_PARAM2_ATTACK, LFO_PARAM2_SYMMETRY, LFO_NUM_PARAMS }; typedef void (*SyncOnProcess)(void *pFuncObj); typedef void (*SyncOnFreqUpdate)(void *pFuncObj, synth_float_t omega); typedef synth_float_t (*SyncOnGetPhase)(void *pFuncObj); typedef struct _ssync_t { void *pFuncObj; SyncOnProcess funcSyncOnProcess; SyncOnGetPhase funcSyncOnGetPhase; SyncOnFreqUpdate funcSyncOnFreqUpdate; synth_float_t phase; synth_float_t phase_ref; synth_float_t omega; synth_float_t klead; synth_float_t klag; synth_float_t accu; int phase_update; int freq_update; } sync_t; #if defined(__cplusplus) extern "C" { #endif // -------------------------------------------------------------- // Exported functions // -------------------------------------------------------------- void Sync_init(sync_t *pObj); void Sync_set_callback(sync_t *pObj, void *pFuncObj, SyncOnProcess funcSyncOnProcess, SyncOnGetPhase funcSyncOnGetPhase, SyncOnFreqUpdate funcSyncOnFreqUpdate); void Sync_phase_update(sync_t *pObj, synth_float_t phase_ref); void Sync_process(sync_t *pObj); #if defined(__cplusplus) } #endif // -------------------------------------------------------------- typedef struct _slfo_t { synth_float_t param[LFO_NUM_PARAMS]; synth_float_t fs; synth_float_t a, b, y[2], x, dx, out, sh_sample, tri; int freq_update_req, sqr; synth_float_t *pOut; UINT32 bufsize; noise_gen_t noise; synth_float_t smooth_a, smooth_b; UINT32 smooth_is_negative; synth_float_t delay_x, delay_dx, attack_y, attack_a; synth_float_t gain, offset; sync_t sync; } lfo_t; // -------------------------------------------------------------- #if defined(__cplusplus) extern "C" { #endif // -------------------------------------------------------------- // Exported functions // -------------------------------------------------------------- void LFO_Init(lfo_t *pObj, synth_float_t fs); void LFO_Free(lfo_t *pObj); void LFO_SetFS(lfo_t *pObj, synth_float_t fs); void LFO_SetBufsize(lfo_t *pObj, UINT32 bufsize); void LFO_Reset(lfo_t *pObj, synth_float_t initial_phase); void LFO_sync(lfo_t *pObj, synth_float_t phase); void LFO_Param2Set(lfo_t *pObj, UINT32 type, synth_float_t value); synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len); #if defined(__cplusplus) } #endif // -------------------------------------------------------------- #endif // _LFO_H_