summaryrefslogtreecommitdiff
path: root/libs/ardour/coreaudiosource.cc
diff options
context:
space:
mode:
authorTaybin Rutkin <taybin@taybin.com>2006-09-01 01:59:41 +0000
committerTaybin Rutkin <taybin@taybin.com>2006-09-01 01:59:41 +0000
commit78e13c37f482552881c3b68ce08a80793df15152 (patch)
treef0f042b1efb402924c65e62638562bde84dfea15 /libs/ardour/coreaudiosource.cc
parent9bc22f6f86deb4258faf298b45cb117f09af8f96 (diff)
Synced string array in sfdb_ui.cc with ImportMode enum.
Cleaned up CoreAudioSource by using CAAudioFile. git-svn-id: svn://localhost/ardour2/trunk@881 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/coreaudiosource.cc')
-rw-r--r--libs/ardour/coreaudiosource.cc149
1 files changed, 56 insertions, 93 deletions
diff --git a/libs/ardour/coreaudiosource.cc b/libs/ardour/coreaudiosource.cc
index 0d7e690a25..fa22dde347 100644
--- a/libs/ardour/coreaudiosource.cc
+++ b/libs/ardour/coreaudiosource.cc
@@ -20,6 +20,9 @@
#include <pbd/error.h>
#include <ardour/coreaudiosource.h>
+#include <appleutility/CAAudioFile.h>
+#include <appleutility/CAStreamBasicDescription.h>
+
#include "i18n.h"
#include <AudioToolbox/AudioFormat.h>
@@ -43,93 +46,48 @@ void
CoreAudioSource::init (const string& idstr)
{
string::size_type pos;
- string file;
tmpbuf = 0;
tmpbufsize = 0;
- af = 0;
- OSStatus err = noErr;
_name = idstr;
if ((pos = idstr.find_last_of (':')) == string::npos) {
channel = 0;
- file = idstr;
+ _path = 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();
+ _path = idstr.substr (0, pos);
}
- 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;
-
- cerr << "number of channels: " << n_channels << endl;
+ cerr << "CoreAudioSource::init() " << name() << endl;
- if (channel >= n_channels) {
- error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg;
- ExtAudioFileDispose (af);
- throw failed_constructor();
- }
+ /* note that we temporarily truncated _id at the colon */
+ try {
+ af.Open(_path.c_str());
- int64_t ca_frames;
- size_t prop_size = sizeof(int64_t);
+ CAStreamBasicDescription file_asbd (af.GetFileDataFormat());
+ n_channels = file_asbd.NumberChannels();
+ cerr << "number of channels: " << n_channels << endl;
+
+ if (channel >= n_channels) {
+ error << string_compose("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number (%3)", n_channels, channel, name()) << endmsg;
+ throw failed_constructor();
+ }
- err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &prop_size, &ca_frames);
- if (err != noErr) {
- error << string_compose (_("Could not get file length for file: %1"), name()) << endmsg;
- ExtAudioFileDispose (af);
- throw failed_constructor();
- }
+ _length = af.GetNumberFrames();
- _length = ca_frames;
- _path = file;
-
- AudioStreamBasicDescription client_asbd;
- memset(&client_asbd, 0, sizeof(AudioStreamBasicDescription));
- client_asbd.mSampleRate = file_asbd.mSampleRate;
- client_asbd.mFormatID = kAudioFormatLinearPCM;
- client_asbd.mFormatFlags = kLinearPCMFormatFlagIsFloat;
- client_asbd.mBytesPerPacket = file_asbd.mChannelsPerFrame * 4;
- client_asbd.mFramesPerPacket = 1;
- client_asbd.mBytesPerFrame = client_asbd.mBytesPerPacket;
- client_asbd.mChannelsPerFrame = file_asbd.mChannelsPerFrame;
- client_asbd.mBitsPerChannel = 32;
-
- err = ExtAudioFileSetProperty (af, kExtAudioFileProperty_ClientDataFormat, asbd_size, &client_asbd);
- if (err != noErr) {
- error << string_compose (_("Could not set client data format for file: %1"), name()) << endmsg;
- ExtAudioFileDispose (af);
+ CAStreamBasicDescription client_asbd(file_asbd);
+ client_asbd.SetCanonical(client_asbd.NumberChannels(), false);
+ af.SetClientFormat (client_asbd);
+ } catch (CAXException& cax) {
+ error << string_compose ("CoreAudioSource: %1 (%2)", cax.mOperation, name()) << endmsg;
throw failed_constructor ();
}
if (_build_peakfiles) {
- if (initialize_peakfile (false, file)) {
- error << string_compose(_("initialize peakfile failed for file %1"), name()) << endmsg;
- ExtAudioFileDispose (af);
+ if (initialize_peakfile (false, _path)) {
+ error << string_compose("CoreAudioSource: initialize peakfile failed (%1)", name()) << endmsg;
throw failed_constructor ();
}
}
@@ -137,41 +95,44 @@ CoreAudioSource::init (const string& idstr)
CoreAudioSource::~CoreAudioSource ()
{
+ cerr << "CoreAudioSource::~CoreAudioSource() " << name() << endl;
GoingAway (); /* EMIT SIGNAL */
- if (af) {
- ExtAudioFileDispose (af);
- }
-
if (tmpbuf) {
delete [] tmpbuf;
}
+
+ cerr << "deletion done" << endl;
}
jack_nframes_t
CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
{
- OSStatus err = noErr;
-
- err = ExtAudioFileSeek(af, start);
- if (err != noErr) {
- error << string_compose(_("CoreAudioSource: could not seek to frame %1 within %2 (%3)"), start, _name.substr (1), err) << endmsg;
+ try {
+ af.Seek (start);
+ } catch (CAXException& cax) {
+ error << string_compose("CoreAudioSource: %1 to %2 (%3)", cax.mOperation, start, _name.substr (1)) << endmsg;
return 0;
}
AudioBufferList abl;
abl.mNumberBuffers = 1;
abl.mBuffers[0].mNumberChannels = n_channels;
- abl.mBuffers[0].mDataByteSize = cnt * sizeof(Sample);
- abl.mBuffers[0].mData = dst;
+ UInt32 new_cnt = cnt;
if (n_channels == 1) {
- err = ExtAudioFileRead(af, (UInt32*) &cnt, &abl);
- _read_data_count = cnt * sizeof(float);
- return cnt;
+ abl.mBuffers[0].mDataByteSize = cnt * sizeof(Sample);
+ abl.mBuffers[0].mData = dst;
+ try {
+ af.Read (new_cnt, &abl);
+ } catch (CAXException& cax) {
+ error << string_compose("CoreAudioSource: %1 (%2)", cax.mOperation, _name);
+ }
+ _read_data_count = new_cnt * sizeof(float);
+ return new_cnt;
}
- uint32_t real_cnt = cnt * n_channels;
+ UInt32 real_cnt = cnt * n_channels;
{
Glib::Mutex::Lock lm (_tmpbuf_lock);
@@ -185,10 +146,16 @@ CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_
tmpbuf = new float[tmpbufsize];
}
- abl.mBuffers[0].mDataByteSize = real_cnt * sizeof(Sample);
+ abl.mBuffers[0].mDataByteSize = tmpbufsize * sizeof(Sample);
abl.mBuffers[0].mData = tmpbuf;
+
+ cerr << "channel: " << channel << endl;
- err = ExtAudioFileRead(af, (UInt32*) &real_cnt, &abl);
+ try {
+ af.Read (real_cnt, &abl);
+ } catch (CAXException& cax) {
+ error << string_compose("CoreAudioSource: %1 (%2)", cax.mOperation, _name);
+ }
float *ptr = tmpbuf + channel;
real_cnt /= n_channels;
@@ -208,15 +175,12 @@ CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_
float
CoreAudioSource::sample_rate() const
{
- AudioStreamBasicDescription client_asbd;
- memset(&client_asbd, 0, sizeof(AudioStreamBasicDescription));
+ CAStreamBasicDescription client_asbd;
- OSStatus err = noErr;
- size_t asbd_size = sizeof(AudioStreamBasicDescription);
-
- err = ExtAudioFileSetProperty (af, kExtAudioFileProperty_ClientDataFormat, asbd_size, &client_asbd);
- if (err != noErr) {
- error << string_compose(_("Could not detect samplerate for: %1"), name()) << endmsg;
+ try {
+ client_asbd = af.GetClientDataFormat ();
+ } catch (CAXException& cax) {
+ error << string_compose("CoreAudioSource: %1 (%2)", cax.mOperation, _name);
return 0.0;
}
@@ -228,4 +192,3 @@ CoreAudioSource::update_header (jack_nframes_t when, struct tm&, time_t)
{
return 0;
}
-