#include #include #include #include "sound.h" int sound_copy(struct mossrose_sound_t *dest, struct mossrose_sound_t *src) { sound_free_audio(dest); dest->len = src->len; /* left channel */ if (src->left != NULL) { dest->left = malloc(src->len * sizeof(float)); if (dest->left == NULL) return 1; memcpy(dest->left, src->left, src->len * sizeof(float)); } else dest->left = NULL; /* right channel */ if (src->right != NULL) { dest->right = malloc(src->len * sizeof(float)); if (dest->right == NULL) return 1; memcpy(dest->right, src->right, src->len * sizeof(float)); } else dest->right = NULL; return 0; } void sound_free_audio(struct mossrose_sound_t *sound) { if (sound->left == NULL) { free(sound->left); sound->left = NULL; } if (sound->right == NULL) { free(sound->right); sound->right = NULL; } }