Voice* new_Voice(void) { Voice* voice = memory_alloc_item(Voice); if (voice == NULL) return NULL; voice->id = 0; voice->prio = VOICE_PRIO_INACTIVE; voice->gen = NULL; voice->state_size = 0; voice->state = NULL; voice->state_size = sizeof(Voice_state); voice->state = memory_alloc_item(Voice_state); voice->rand_p = new_Random(); voice->rand_s = new_Random(); if (voice->state == NULL || voice->rand_p == NULL || voice->rand_s == NULL) { del_Voice(voice); return NULL; } Random_set_context(voice->rand_p, "vp"); Random_set_context(voice->rand_s, "vs"); Voice_state_clear(voice->state); return voice; }
Voice_state* Voice_state_init(Voice_state* state, Random* rand_p, Random* rand_s) { rassert(state != NULL); rassert(rand_p != NULL); rassert(rand_s != NULL); Voice_state_clear(state); state->active = true; state->has_finished = false; state->note_on = true; state->rand_p = rand_p; state->rand_s = rand_s; state->wb = NULL; state->render_voice = NULL; state->has_release_data = false; state->release_stop = 0; state->is_pitch_state = false; state->is_force_state = false; state->is_stream_state = false; return state; }
void Voice_reset(Voice* voice) { assert(voice != NULL); voice->id = 0; voice->prio = VOICE_PRIO_INACTIVE; Voice_state_clear(voice->state); voice->gen = NULL; Random_reset(voice->rand_p); Random_reset(voice->rand_s); return; }