void ksynth_free(struct KSynth* ksynth_instance) {
if(ksynth_instance != NULL) {
+ if(ksynth_instance->samples != NULL) {
+ for(int i = 0; i < 128; i++) {
+ if(ksynth_instance->samples[i] != NULL) {
+ free(ksynth_instance->samples[i]->sample);
+ free(ksynth_instance->samples[i]);
+ }
+ }
+ free(ksynth_instance->samples);
+ ksynth_instance->samples = NULL;
+ }
+
+ if(ksynth_instance->voices != NULL) {
+ for(unsigned long i = 0; i < ksynth_instance->max_polyphony; i++) {
+ if(ksynth_instance->voices[i] != NULL) {
+ free(ksynth_instance->voices[i]);
+ }
+ }
+ free(ksynth_instance->voices);
+ ksynth_instance->voices = NULL;
+ }
+
free(ksynth_instance);
}
}