diff options
author | sanine <sanine.not@pm.me> | 2022-08-28 11:25:44 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-28 11:25:44 -0500 |
commit | 0d6ece00397ebb9215ccf1af06cce22c3a94197e (patch) | |
tree | 022cc796822a998a59d8bf8896f02599ce6d3700 /src/sound.c | |
parent | a4dd0ad63c00f4dee3b86dfd3075d1d61b2b3180 (diff) |
begin plibsys refactor
Diffstat (limited to 'src/sound.c')
-rw-r--r-- | src/sound.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/sound.c b/src/sound.c new file mode 100644 index 0000000..36c1e5b --- /dev/null +++ b/src/sound.c @@ -0,0 +1,44 @@ +#include <stdlib.h> +#include <string.h> +#include <mossrose.h> +#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; + } +} |