summaryrefslogtreecommitdiff
path: root/libs/ardour/sndfile_helpers.cc
diff options
context:
space:
mode:
authorTaybin Rutkin <taybin@taybin.com>2006-03-07 23:41:52 +0000
committerTaybin Rutkin <taybin@taybin.com>2006-03-07 23:41:52 +0000
commitbe60137cfb31ef1266f5132a9fd465c01ce074a9 (patch)
tree1a36dad623d17a344d1d1192b218b2df55ce3ca6 /libs/ardour/sndfile_helpers.cc
parent00c9cc9ddef5ee26a8d6902b08387542bea10f15 (diff)
Wrapper around SF_INFO and AudioFileBasicDescription.
git-svn-id: svn://localhost/trunk/ardour2@357 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/sndfile_helpers.cc')
-rw-r--r--libs/ardour/sndfile_helpers.cc104
1 files changed, 104 insertions, 0 deletions
diff --git a/libs/ardour/sndfile_helpers.cc b/libs/ardour/sndfile_helpers.cc
index 21d8c72b2b..af9816c29c 100644
--- a/libs/ardour/sndfile_helpers.cc
+++ b/libs/ardour/sndfile_helpers.cc
@@ -4,6 +4,11 @@
#include <sndfile.h>
#include <ardour/sndfile_helpers.h>
+#ifdef HAVE_COREAUDIO
+#include <AudioToolbox/ExtendedAudioFile.h>
+#include <AudioToolbox/AudioFormat.h>
+#endif // HAVE_COREAUDIO
+
#include "i18n.h"
using std::map;
@@ -191,3 +196,102 @@ sndfile_minor_format(int format)
return "-Unknown-";
}
}
+
+#ifdef HAVE_COREAUDIO
+std::string
+CFStringRefToStdString(CFStringRef stringRef)
+{
+ CFIndex size =
+ CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) ,
+ kCFStringEncodingASCII);
+ char *buf = new char[size];
+
+ std::string result;
+
+ if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
+ result = buf;
+ }
+ delete [] buf;
+ return result;
+}
+#endif // HAVE_COREAUDIO
+
+bool
+get_soundfile_info (string path, SoundFileInfo& _info)
+{
+#ifdef HAVE_COREAUDIO
+ OSStatus err = noErr;
+ FSRef* ref;
+ ExtAudioFileRef af = 0;
+ size_t size;
+ CFStringRef name;
+
+ err = FSPathMakeRef ((UInt8*)path.c_str(), ref, 0);
+ if (err != noErr) {
+ ExtAudioFileDispose (af);
+ goto libsndfile;
+ }
+
+ err = ExtAudioFileOpen(ref, &af);
+ if (err != noErr) {
+ ExtAudioFileDispose (af);
+ goto libsndfile;
+ }
+
+ AudioStreamBasicDescription absd;
+ memset(&absd, 0, sizeof(absd));
+ size = sizeof(AudioStreamBasicDescription);
+ err = ExtAudioFileGetProperty(af,
+ kExtAudioFileProperty_FileDataFormat, &size, &absd);
+ if (err != noErr) {
+ ExtAudioFileDispose (af);
+ goto libsndfile;
+ }
+
+ _info.samplerate = absd.mSampleRate;
+ _info.channels = absd.mChannelsPerFrame;
+
+ size = sizeof(_info.length);
+ err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length);
+ if (err != noErr) {
+ ExtAudioFileDispose (af);
+ goto libsndfile;
+ }
+
+ size = sizeof(CFStringRef);
+ err = AudioFormatGetProperty(
+ kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name);
+ if (err != noErr) {
+ ExtAudioFileDispose (af);
+ goto libsndfile;
+ }
+
+ _info.format_name = CFStringRefToStdString(name);
+
+ ExtAudioFileDispose (af);
+ return true;
+
+libsndfile:
+#endif // HAVE_COREAUDIO
+
+ SNDFILE *sf;
+ SF_INFO sf_info;
+
+ sf_info.format = 0; // libsndfile says to clear this before sf_open().
+
+ if ((sf = sf_open ((char*) path.c_str(), SFM_READ, &sf_info)) < 0) {
+ return false;
+ }
+
+ sf_close (sf);
+
+ _info.samplerate = sf_info.samplerate;
+ _info.channels = sf_info.channels;
+ _info.length = sf_info.frames;
+ _info.format_name = string_compose("Format: %1, %2",
+ sndfile_major_format(sf_info.format),
+ sndfile_minor_format(sf_info.format));
+
+ return true;
+}
+