From: Paul Brossier Date: Mon, 25 Apr 2016 14:26:39 +0000 (+0200) Subject: src/io/source_apple_audio.h: add _get_duration X-Git-Tag: 0.4.4~300^2~216 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=a41b1ef7244c43a11ede91e4ffccce358c94e580;p=aubio.git src/io/source_apple_audio.h: add _get_duration --- diff --git a/src/io/source_apple_audio.c b/src/io/source_apple_audio.c index 126058b8..a86d4a34 100644 --- a/src/io/source_apple_audio.c +++ b/src/io/source_apple_audio.c @@ -311,10 +311,7 @@ uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos 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 ); @@ -363,4 +360,19 @@ uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * 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 */ diff --git a/src/io/source_apple_audio.h b/src/io/source_apple_audio.h index bfd315c3..0ad55694 100644 --- a/src/io/source_apple_audio.h +++ b/src/io/source_apple_audio.h @@ -109,6 +109,16 @@ uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * /** + get the duration of source object, in frames + + \param s source object, created with ::new_aubio_source_apple_audio + \return number of frames in file + +*/ +uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s); + +/** + seek source object \param s source object, created with ::new_aubio_source