- af = 0;
- OSStatus err = noErr;
-
- _name = idstr;
-
- if ((pos = idstr.find_last_of (':')) == string::npos) {
- channel = 0;
- file = idstr;
- } else {
- channel = atoi (idstr.substr (pos+1).c_str());
- file = idstr.substr (0, pos);
- }
-
- /* note that we temporarily truncated _id at the colon */
- FSRef fsr;
- err = FSPathMakeRef ((UInt8*)file.c_str(), &fsr, 0);
- if (err != noErr) {
- error << string_compose (_("Could not make reference to file: %1"), name()) << endmsg;
- throw failed_constructor();
- }
-
- err = ExtAudioFileOpen (&fsr, &af);
- if (err != noErr) {
- error << string_compose (_("Could not open file: %1"), name()) << endmsg;
- ExtAudioFileDispose (af);
- throw failed_constructor();
- }
-
- AudioStreamBasicDescription file_asbd;
- memset(&file_asbd, 0, sizeof(AudioStreamBasicDescription));
- size_t asbd_size = sizeof(AudioStreamBasicDescription);
- err = ExtAudioFileGetProperty(af,
- kExtAudioFileProperty_FileDataFormat, &asbd_size, &file_asbd);
- if (err != noErr) {
- error << string_compose (_("Could not get file data format for file: %1"), name()) << endmsg;
- ExtAudioFileDispose (af);
- throw failed_constructor();
- }
- n_channels = file_asbd.mChannelsPerFrame;