void patch_free(Patch* p) { int i; if (!p) return; debug("********************************\n"); debug("freeing patch:'%s'\n", p->name); debug("********************************\n"); sample_free(p->sample); for (i = 0; i < PATCH_VOICE_COUNT; ++i) patch_voice_free(p->voices[i]); for (i = 0; i < PATCH_MAX_LFOS; ++i) { free(p->glfo_table[i]); lfo_free(p->glfo[i]); } pthread_mutex_destroy(&p->mutex); free(p); }
int sample_default(Sample* sample, int rate) { int frames = rate / 8; float* tmp; LFO* lfo; LFOParams lfopar; int i; double v; float const* lfo_out; debug("Creating default sample\n"); if (!(tmp = malloc(frames * 2 * sizeof(*tmp)))) { pf_error(PF_ERR_SAMPLE_DEFAULT_ALLOC); return -1; } sample->frames = frames; sample->sp = tmp; lfo = lfo_new(); lfo_init(lfo); lfo_params_init(&lfopar, 523.251, LFO_SHAPE_SAW); lfo_trigger(lfo, &lfopar); lfo_out = lfo_output(lfo); for (i = 0; i < frames; ++i) { lfo_tick(lfo); v = *lfo_out * 0.9; *tmp++ = v; *tmp++ = v; } lfo_free(lfo); sample->filename = strdup("Default"); sample->default_sample = true; return 0; }