#if defined(STFU_MAIN) && !defined(STFU_PHASER) #define STFU_PHASER #include #include "config.h" struct stfu_phaser stfu_pump_phaser(struct stfu_phaser phaser); struct stfu_phaser stfu_set_phaser_frequency(struct stfu_phaser phaser, float frequency); /* Useful for feeding into phase parameters of oscillators and such. * Repeats over [-PI, PI) */ struct stfu_phaser { float v, a; } stfu_init_phaser(float frequency) { struct stfu_phaser r = {0}; r = stfu_set_phaser_frequency(r, frequency); return r; } struct stfu_phaser stfu_pump_phaser(struct stfu_phaser phaser) { phaser.v += phaser.a; if (phaser.v >= (float)M_PI) phaser.v -= (float)M_PI * 2.0f; return phaser; } struct stfu_phaser stfu_set_phaser_frequency(struct stfu_phaser phaser, float frequency) { phaser.a = 2 * ((float)M_PI / (float)STFU_AUDIO_FRAME_RATE) * frequency; return phaser; } #endif