Files
SeeSynth/utils.c
e1lama 7eb6a1755d fix: refactor code structure into files (#8)
closes #7

Co-authored-by: HiveBeats <e1lama@protonmail.com>
Reviewed-on: #8
2023-06-18 14:46:20 +03:00

30 lines
760 B
C

#include "utils.h"
#include "stdlib.h"
#include "string.h"
// frees the original sounds
SynthSound concat_sounds(SynthSound* sounds, size_t count) {
size_t total_count = 0;
for (size_t i = 0; i < count; i++) {
total_count += sounds[i].sample_count;
}
// array to hold the result
float* total = malloc(total_count * sizeof(float));
size_t current_count = 0;
for (size_t i = 0; i < count; i++) {
memcpy(total + current_count,
sounds[i].samples,
sounds[i].sample_count * sizeof(float));
current_count += sounds[i].sample_count;
free(sounds[i].samples);
}
SynthSound result = {
.samples = total,
.sample_count = total_count
};
return result;
}