ref: 944c7e1e85e52cb1826716f8a0d58bca6f33d7d1
parent: f8ee337cdef087dcd206923438c2a17dcdfccf35
author: Paul Brossier <[email protected]>
date: Sat Feb 9 18:12:28 EST 2013
src/io/source_apple_audio.c: automagically set samplerate if 0 was requested, add _get_samplerate
--- a/src/io/source.c
+++ b/src/io/source.c
@@ -71,3 +71,13 @@
AUBIO_FREE(s);
}
+uint_t aubio_source_get_samplerate(aubio_source_t * s) {
+#ifdef __APPLE__
+ return aubio_source_apple_audio_get_samplerate((aubio_source_apple_audio_t *)s->source);
+#else /* __APPLE__ */
+#if HAVE_SNDFILE
+ return aubio_source_sndfile_get_samplerate((aubio_source_sndfile_t *)s->source);
+#endif /* HAVE_SNDFILE */
+#endif /* __APPLE__ */
+}
+
--- a/src/io/source.h
+++ b/src/io/source.h
@@ -36,6 +36,8 @@
void aubio_source_do(aubio_source_t * s, fvec_t * read_data, uint_t * read);
void del_aubio_source(aubio_source_t * s);
+uint_t aubio_source_get_samplerate(aubio_source_t * s);
+
#ifdef __cplusplus
}
#endif
--- a/src/io/source_apple_audio.c
+++ b/src/io/source_apple_audio.c
@@ -54,7 +54,6 @@
aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
s->path = path;
- s->samplerate = samplerate;
s->block_size = block_size;
s->channels = 1;
@@ -61,19 +60,6 @@
OSStatus err = noErr;
UInt32 propSize;
- AudioStreamBasicDescription clientFormat;
- propSize = sizeof(clientFormat);
- memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
- clientFormat.mFormatID = kAudioFormatLinearPCM;
- clientFormat.mSampleRate = (Float64)(s->samplerate);
- clientFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
- clientFormat.mChannelsPerFrame = s->channels;
- clientFormat.mBitsPerChannel = sizeof(short) * 8;
- clientFormat.mFramesPerPacket = 1;
- clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
- clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
- clientFormat.mReserved = 0;
-
// open the resource url
CFURLRef fileURL = getURLFromPath(path);
err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
@@ -89,6 +75,25 @@
kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);
if (err) { AUBIO_ERROR("error in ExtAudioFileGetProperty, %d\n", (int)err); goto beach;}
+ if (samplerate == 0) {
+ samplerate = fileFormat.mSampleRate;
+ AUBIO_WRN("sampling rate set to 0, automagically adjusting to %d", samplerate);
+ }
+ s->samplerate = samplerate;
+
+ AudioStreamBasicDescription clientFormat;
+ propSize = sizeof(clientFormat);
+ memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
+ clientFormat.mFormatID = kAudioFormatLinearPCM;
+ clientFormat.mSampleRate = (Float64)(s->samplerate);
+ clientFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
+ clientFormat.mChannelsPerFrame = s->channels;
+ clientFormat.mBitsPerChannel = sizeof(short) * 8;
+ clientFormat.mFramesPerPacket = 1;
+ clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
+ clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
+ clientFormat.mReserved = 0;
+
// set the client format description
err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
propSize, &clientFormat);
@@ -173,6 +178,10 @@
freeAudioBufferList(&s->bufferList);
AUBIO_FREE(s);
return;
+}
+
+uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
+ return s->samplerate;
}
#endif /* __APPLE__ */
--- a/src/io/source_apple_audio.h
+++ b/src/io/source_apple_audio.h
@@ -26,4 +26,6 @@
void aubio_source_apple_audio_do(aubio_source_apple_audio_t * s, fvec_t * read_to, uint_t * read);
void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s);
+uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s);
+
#endif /* _AUBIO_SOURCE_APPLE_AUDIO_H */