+int
+CoreAudioSource::get_soundfile_info (string path, SoundFileInfo& _info, string&)
+{
+#ifdef COREAUDIO105
+ FSRef ref;
+#endif
+ ExtAudioFileRef af = 0;
+ UInt32 size;
+ CFStringRef name;
+ int ret = -1;
+
+#ifdef COREAUDIO105
+ if (FSPathMakeRef ((UInt8*)path.c_str(), &ref, 0) != noErr) {
+ goto out;
+ }
+
+ if (ExtAudioFileOpen(&ref, &af) != noErr) {
+ goto out;
+ }
+#else
+ CFURLRef url = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const UInt8*)path.c_str (), strlen (path.c_str ()), false);
+ OSStatus res = ExtAudioFileOpenURL(url, &af);
+ if (url) CFRelease (url);
+
+ if (res != noErr) {
+ goto out;
+ }
+#endif
+
+ AudioStreamBasicDescription absd;
+ memset(&absd, 0, sizeof(absd));
+ size = sizeof(AudioStreamBasicDescription);
+ if (ExtAudioFileGetProperty (af, kExtAudioFileProperty_FileDataFormat, &size, &absd) != noErr) {
+ goto out;
+ }
+
+ _info.samplerate = absd.mSampleRate;
+ _info.channels = absd.mChannelsPerFrame;
+
+ size = sizeof(_info.length);
+ if (ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length) != noErr) {
+ goto out;
+ }
+
+ size = sizeof(CFStringRef);
+ if (AudioFormatGetProperty(kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name) != noErr) {
+ goto out;
+ }
+
+ _info.format_name = "";
+
+ if (absd.mFormatID == kAudioFormatLinearPCM) {
+ if (absd.mFormatFlags & kAudioFormatFlagIsBigEndian) {
+ _info.format_name += "big-endian";
+ } else {
+ _info.format_name += "little-endian";
+ }
+
+ char buf[32];
+ snprintf (buf, sizeof (buf), " %" PRIu32 " bit", absd.mBitsPerChannel);
+ _info.format_name += buf;
+ _info.format_name += '\n';
+
+ if (absd.mFormatFlags & kAudioFormatFlagIsFloat) {
+ _info.format_name += "float";
+ } else {
+ if (absd.mFormatFlags & kAudioFormatFlagIsSignedInteger) {
+ _info.format_name += "signed";
+ } else {
+ _info.format_name += "unsigned";
+ }
+ /* integer is typical, do not show it */
+ }
+
+ if (_info.channels > 1) {
+ if (absd.mFormatFlags & kAudioFormatFlagIsNonInterleaved) {
+ _info.format_name += " noninterleaved";
+ }
+ /* interleaved is the normal case, do not show it */
+ }
+
+ _info.format_name += ' ';
+ }
+
+ switch (absd.mFormatID) {
+ case kAudioFormatLinearPCM:
+ _info.format_name += "PCM";
+ break;
+
+ case kAudioFormatAC3:
+ _info.format_name += "AC3";
+ break;
+
+ case kAudioFormat60958AC3:
+ _info.format_name += "60958 AC3";
+ break;
+
+ case kAudioFormatMPEGLayer1:
+ _info.format_name += "MPEG-1";
+ break;
+
+ case kAudioFormatMPEGLayer2:
+ _info.format_name += "MPEG-2";
+ break;
+
+ case kAudioFormatMPEGLayer3:
+ _info.format_name += "MPEG-3";
+ break;
+
+ case kAudioFormatAppleIMA4:
+ _info.format_name += "IMA-4";
+ break;
+
+ case kAudioFormatMPEG4AAC:
+ _info.format_name += "AAC";
+ break;
+
+ case kAudioFormatMPEG4CELP:
+ _info.format_name += "CELP";
+ break;
+
+ case kAudioFormatMPEG4HVXC:
+ _info.format_name += "HVXC";
+ break;
+
+ case kAudioFormatMPEG4TwinVQ:
+ _info.format_name += "TwinVQ";
+ break;
+
+ /* these really shouldn't show up, but we should do something
+ somewhere else to make sure that doesn't happen. until
+ that is guaranteed, print something anyway.
+ */
+
+ case kAudioFormatTimeCode:
+ _info.format_name += "timecode";
+ break;
+
+ case kAudioFormatMIDIStream:
+ _info.format_name += "MIDI";
+ break;
+
+ case kAudioFormatParameterValueStream:
+ _info.format_name += "parameter values";
+ break;
+ }
+
+ // XXX it would be nice to find a way to get this information if it exists
+
+ _info.timecode = 0;
+ ret = 0;
+
+out:
+ ExtAudioFileDispose (af);
+ return ret;
+
+}
+
+void
+CoreAudioSource::set_path (const string& p)
+{
+ FileSource::set_path (p);
+}