along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#ifndef __coreaudio_source_h__
#define __coreaudio_source_h__
#include <ardour/source.h>
-
-#include <AudioToolbox/AudioFile.h>
+#include <AudioToolbox/ExtendedAudioFile.h>
namespace ARDOUR {
~CoreAudioSource ();
jack_nframes_t length() const { return _length; }
- jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const;
+ jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
void mark_for_remove() {} // we never remove external sndfiles
string peak_path(string audio_path);
string old_peak_path(string audio_path);
private:
static string peak_dir;
- AudioFileID af;
- AudioStreamBasicDescription _info;
-
+ ExtAudioFileRef af;
uint16_t channel;
+ uint16_t n_channels;
mutable float *tmpbuf;
mutable jack_nframes_t tmpbufsize;
mutable PBD::Lock _tmpbuf_lock;
string _path;
void init (const string &str, bool build_peak);
- jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const;
+ jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
};
}; /* namespace ARDOUR */
/*
- Copyright (C) 2000 Paul Davis
+ Copyright (C) 2006 Paul Davis
+ Written by Taybin Rutkin
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#include <string>
}
init (_name, true);
- SourceCreated (this); /* EMIT SIGNAL */
+ SourceCreated (this); /* EMIT SIGNAL */
}
CoreAudioSource::CoreAudioSource (const string& idstr, bool build_peak)
tmpbuf = 0;
tmpbufsize = 0;
- af_ref = 0;
+ af = 0;
+ OSStatus err = noErr;
_name = idstr;
file = idstr.substr (0, pos);
}
+
/* note that we temporarily truncated _id at the colon */
FSRef* ref;
- OSStatus err = FSPathMakeRef ((UInt8*)file.c_str(), ref, 0);
- if (err) {
+ err = FSPathMakeRef ((UInt8*)file.c_str(), ref, 0);
+ if (err != noErr) {
throw failed_constructor();
}
- err = AudioFileOpen (ref, 0, fsRdPerm, &af);
- if (err) {
+
+ err = ExtAudioFileOpen (ref, &af);
+ if (err != noErr) {
throw failed_constructor();
}
-
- /* XXX get value for n_channels */
- UInt32 size = sizeof(AudioStreamBasicDescription);
- memset (_info, 0, size);
-
+
+ /* TODO get channels */
+ n_channels = 0;
+
if (channel >= n_channels) {
error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg;
- AudioFileClose(af);
+ ExtAudioFileDispose (af);
throw failed_constructor();
}
int64_t ca_frames;
size_t prop_size = sizeof(ca_frames);
- err = ExtAudioFileGetProperty(*af_ref, kExtAudioFileProperty_FileLengthFrames, &prop_size, &ca_frames);
- if (err) {
+ err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &prop_size, &ca_frames);
+ if (err != noErr) {
throw failed_constructor();
}
_length = ca_frames;
if (build_peak) {
if (initialize_peakfile (false, file)) {
- AudioFileClose(af);
+ ExtAudioFileDispose (af);
throw failed_constructor ();
}
}
{
GoingAway (this); /* EMIT SIGNAL */
- if (af_ref) {
- ExtAudioFileDispose(*af_ref);
+ if (af) {
+ ExtAudioFileDispose (af);
}
if (tmpbuf) {
}
jack_nframes_t
-CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
+CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
- return read (dst, start, cnt);
+ return read (dst, start, cnt, workbuf);
}
jack_nframes_t
-CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
+CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
{
- uint32_t nread;
+ int32_t nread;
float *ptr;
uint32_t real_cnt;
+ OSStatus err = noErr;
- OSStatus err = ExtAudioFileSeek(*af_ref, start);
- if (err) {
- error << string_compose(_("CoreAudioSource: could not seek to frame %1 within %2"), start, _name.substr (1)) << endmsg;
+ 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;
return 0;
}
+ AudioBuffer ab;
+ ab.mNumberChannels = n_channels;
+ ab.mDataByteSize = cnt;
+ ab.mData = dst;
+
AudioBufferList abl;
abl.mNumberBuffers = 1;
- abl.mBuffers[0].mNumberChannels = n_channels;
+ abl.mBuffers[1] = ab;
if (n_channels == 1) {
- abl.mBuffers[0].mDataByteSize = cnt * sizeof(float);
- abl.mBuffers[0].mData = dst;
- nread = cnt;
- err = ExtAudioFileRead(*af_ref, (UInt32*)&nread, &abl);
+ err = ExtAudioFileRead(af, (UInt32*) &cnt, &abl);
_read_data_count = cnt * sizeof(float);
- return nread;
+ return cnt;
}
real_cnt = cnt * n_channels;
tmpbufsize = real_cnt;
tmpbuf = new float[tmpbufsize];
}
+ ab.mDataByteSize = real_cnt;
+ ab.mData = tmpbuf;
- nread = real_cnt;
- err = ExtAudioFileRead(*af_ref, (UInt32*)&nread, tmpbuf);
+ err = ExtAudioFileRead(af, (UInt32*) &real_cnt, &abl);
+// nread = sf_read_float (af, tmpbuf, real_cnt);
ptr = tmpbuf + channel;
nread /= n_channels;
/* stride through the interleaved data */
- for (uint32_t n = 0; n < nread; ++n) {
+ for (int32_t n = 0; n < nread; ++n) {
dst[n] = *ptr;
ptr += n_channels;
}
_read_data_count = cnt * sizeof(float);
- return nread;
+ return real_cnt;
}
string
{
return peak_path (audio_path);
}
+