/* Copyright (c) 2021 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #include "audiosynth/SynthPropertyController_sine.h" #include "utilities/lookup3.h" #include #define stemobject_implementation SynthPropertyController_sine stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(copy); stemobject_vtable_entry(isEqual); stemobject_vtable_entry(hash); stemobject_vtable_entry(setInitialValue); stemobject_vtable_entry(remapRange); stemobject_vtable_entry(sample); stemobject_vtable_end(); SynthPropertyController_sine * SynthPropertyController_sine_create(SynthPropertyIdentifier propertyIdentifier, float centerValue, float amplitude, float cycleCount, float startPhase) { stemobject_create_implementation(init, propertyIdentifier, centerValue, amplitude, cycleCount, startPhase) } bool SynthPropertyController_sine_init(SynthPropertyController_sine * self, SynthPropertyIdentifier propertyIdentifier, float centerValue, float amplitude, float cycleCount, float startPhase) { call_super(init, self, propertyIdentifier); self->centerValue = centerValue; self->amplitude = amplitude; self->cycleCount = cycleCount; self->startPhase = startPhase; return true; } void SynthPropertyController_sine_dispose(SynthPropertyController_sine * self) { call_super_virtual(dispose, self); } SynthPropertyController_sine * SynthPropertyController_sine_copy(SynthPropertyController_sine * self) { stemobject_copy_implementation(initCopy) } void SynthPropertyController_sine_initCopy(SynthPropertyController_sine * self, SynthPropertyController_sine * original) { call_super(initCopy, self, (SynthPropertyController *) original); self->centerValue = original->centerValue; self->amplitude = original->amplitude; self->cycleCount = original->cycleCount; self->startPhase = original->startPhase; } bool SynthPropertyController_sine_isEqual(SynthPropertyController_sine * self, compat_type(SynthPropertyController_sine *) compareUntyped) { SynthPropertyController_sine * compare = compareUntyped; if (!call_super_virtual(isEqual, self, compare)) { return false; } return self->centerValue == compare->centerValue && self->amplitude == compare->amplitude && self->cycleCount == compare->cycleCount && self->startPhase == compare->startPhase; } uint32_t SynthPropertyController_sine_hash(SynthPropertyController_sine * self, uint32_t initval) { initval = hashlittle(&self->centerValue, sizeof(self->centerValue), initval); initval = hashlittle(&self->amplitude, sizeof(self->amplitude), initval); initval = hashlittle(&self->cycleCount, sizeof(self->cycleCount), initval); initval = hashlittle(&self->startPhase, sizeof(self->startPhase), initval); return initval; } void SynthPropertyController_sine_setInitialValue(SynthPropertyController_sine * self, float value) { self->centerValue = value; self->amplitude = 0.0f; } void SynthPropertyController_sine_remapRange(SynthPropertyController_sine * self, float fromMin, float fromMax, float toMin, float toMax) { self->centerValue = (self->centerValue - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin; self->amplitude = self->amplitude / (fromMax - fromMin) * (toMax - toMin); } float SynthPropertyController_sine_sample(SynthPropertyController_sine * self, SamplerObject_state * state, float phase, float phaseDelta, float time, float timeDelta) { return self->centerValue + sinf((phase * self->cycleCount + self->startPhase) * (float) M_PI * 2.0f) * self->amplitude; }