*/
-#include "config.h"
+#include "aubio_priv.h"
#ifdef HAVE_SOURCE_APPLE_AUDIO
-#include "aubio_priv.h"
#include "fvec.h"
#include "fmat.h"
#include "io/source_apple_audio.h"
return s;
beach:
- AUBIO_FREE(s);
+ del_aubio_source_apple_audio(s);
return NULL;
}
UInt32 propSize;
if (s->path) AUBIO_FREE(s->path);
- s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX));
- strncpy(s->path, path, strnlen(path, PATH_MAX));
+ s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
+ strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
// open the resource url
CFURLRef fileURL = createURLFromPath(s->path);
uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s)
{
OSStatus err = noErr;
- if (!s->audioFile) { return AUBIO_FAIL; }
+ if (!s->audioFile) { return AUBIO_OK; }
err = ExtAudioFileDispose(s->audioFile);
s->audioFile = NULL;
if (err) {
goto beach;
}
// check if we are not seeking out of the file
- SInt64 fileLengthFrames = 0;
- UInt32 propSize = sizeof(fileLengthFrames);
- ExtAudioFileGetProperty(s->audioFile,
- kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
+ uint_t fileLengthFrames = aubio_source_apple_audio_get_duration(s);
// compute position in the source file, before resampling
smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
SInt64 resampled_pos = (SInt64)ROUND( pos * ratio );
return s->channels;
}
+uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s) {
+ SInt64 fileLengthFrames = 0;
+ UInt32 propSize = sizeof(fileLengthFrames);
+ OSStatus err = ExtAudioFileGetProperty(s->audioFile,
+ kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: Failed getting %s duration, "
+ "error in ExtAudioFileGetProperty (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ return err;
+ }
+ return (uint_t)fileLengthFrames;
+}
+
#endif /* HAVE_SOURCE_APPLE_AUDIO */