#include "fvec.h"
#include "fmat.h"
#include "io/sink_apple_audio.h"
+#include "io/ioutils.h"
// CFURLRef, CFURLCreateWithFileSystemPath, ...
#include <CoreFoundation/CoreFoundation.h>
bool async;
};
-aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate) {
+aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) {
aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t);
- s->path = uri;
s->max_frames = MAX_SIZE;
s->async = false;
AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
goto beach;
}
+ if (s->path != NULL) AUBIO_FREE(s->path);
+ s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
+ strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
s->samplerate = 0;
s->channels = 0;
- // negative samplerate given, abort
- if ((sint_t)samplerate < 0) goto beach;
// zero samplerate given. do not open yet
- if ((sint_t)samplerate == 0) return s;
+ if ((sint_t)samplerate == 0) {
+ return s;
+ }
+ // invalid samplerate given, abort
+ if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
+ goto beach;
+ }
s->samplerate = samplerate;
s->channels = 1;
uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate)
{
- if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
+ if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
+ return AUBIO_FAIL;
+ }
s->samplerate = samplerate;
// automatically open when both samplerate and channels have been set
if (s->samplerate != 0 && s->channels != 0) {
uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels)
{
- if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
+ if (aubio_io_validate_channels("sink_apple_audio", s->path, channels)) {
+ return AUBIO_FAIL;
+ }
s->channels = channels;
// automatically open when both samplerate and channels have been set
if (s->samplerate != 0 && s->channels != 0) {
return AUBIO_OK;
}
-uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s)
+uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s)
{
return s->samplerate;
}
-uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s)
+uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s)
{
return s->channels;
}
void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
if (s->audioFile) aubio_sink_apple_audio_close (s);
+ if (s->path) AUBIO_FREE(s->path);
freeAudioBufferList(&s->bufferList);
AUBIO_FREE(s);
return;