diff options
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; + } +} |