More work on OSX native file reading.
git-svn-id: svn://localhost/trunk/ardour2@185 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
991a00f80a
commit
fa89a453a1
|
@ -87,6 +87,7 @@ mix.cc
|
||||||
arch_specific_objects = [ ]
|
arch_specific_objects = [ ]
|
||||||
|
|
||||||
vst_files = [ 'vst_plugin.cc', 'session_vst.cc' ]
|
vst_files = [ 'vst_plugin.cc', 'session_vst.cc' ]
|
||||||
|
coreaudio_files = [ 'coreaudio_source.cc' ]
|
||||||
extra_sources = [ ]
|
extra_sources = [ ]
|
||||||
|
|
||||||
if ardour['VST']:
|
if ardour['VST']:
|
||||||
|
@ -159,6 +160,10 @@ if conf.CheckCHeader('sys/vfs.h'):
|
||||||
if conf.CheckCHeader('/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h'):
|
if conf.CheckCHeader('/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h'):
|
||||||
ardour.Append(LINKFLAGS="-framework CoreMIDI")
|
ardour.Append(LINKFLAGS="-framework CoreMIDI")
|
||||||
|
|
||||||
|
if conf.CheckCHeader('/System/Library/Frameworks/AudioToolbox.framework/Headers/ExtendedAudioFile.h'):
|
||||||
|
ardour.Append(LINKFLAGS="-framework AudioToolbox")
|
||||||
|
#extra_sources += coreaudio_files
|
||||||
|
|
||||||
ardour = conf.Finish ()
|
ardour = conf.Finish ()
|
||||||
|
|
||||||
ardour.Merge ([
|
ardour.Merge ([
|
||||||
|
@ -201,9 +206,9 @@ else:
|
||||||
Default(libardour)
|
Default(libardour)
|
||||||
|
|
||||||
if env['NLS']:
|
if env['NLS']:
|
||||||
i18n (ardour, ardour_files + vst_files, env)
|
i18n (ardour, ardour_files + vst_files + coreaudio_files, env)
|
||||||
|
|
||||||
env.Alias('tarball', env.Distribute (env['DISTTREE'],
|
env.Alias('tarball', env.Distribute (env['DISTTREE'],
|
||||||
[ 'SConscript', 'i18n.h', 'gettext.h', 'sse_functions.s' ] +
|
[ 'SConscript', 'i18n.h', 'gettext.h', 'sse_functions.s' ] +
|
||||||
ardour_files + vst_files +
|
ardour_files + vst_files + coreaudio_files +
|
||||||
glob.glob('po/*.po') + glob.glob('ardour/*.h')))
|
glob.glob('po/*.po') + glob.glob('ardour/*.h')))
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#ifndef __coreaudio_source_h__
|
#ifndef __coreaudio_source_h__
|
||||||
#define __coreaudio_source_h__
|
#define __coreaudio_source_h__
|
||||||
|
|
||||||
#include <AudioToolbox/AudioFile.h>
|
#include <AudioToolbox/ExtendedAudioFile.h>
|
||||||
|
|
||||||
#include <ardour/source.h>
|
#include <ardour/source.h>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class CoreAudioSource : public Source {
|
||||||
CoreAudioSource (const XMLNode&);
|
CoreAudioSource (const XMLNode&);
|
||||||
~CoreAudioSource ();
|
~CoreAudioSource ();
|
||||||
|
|
||||||
jack_nframes_t length() const { return _info.frames; }
|
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) const;
|
||||||
void mark_for_remove() {} // we never remove external sndfiles
|
void mark_for_remove() {} // we never remove external sndfiles
|
||||||
string peak_path(string audio_path);
|
string peak_path(string audio_path);
|
||||||
|
@ -45,7 +45,9 @@ class CoreAudioSource : public Source {
|
||||||
private:
|
private:
|
||||||
static string peak_dir;
|
static string peak_dir;
|
||||||
|
|
||||||
AudioFileID sf;
|
ExtAudioFileRef* af_ref;
|
||||||
|
uint16_t n_channels;
|
||||||
|
|
||||||
uint16_t channel;
|
uint16_t channel;
|
||||||
mutable float *tmpbuf;
|
mutable float *tmpbuf;
|
||||||
mutable jack_nframes_t tmpbufsize;
|
mutable jack_nframes_t tmpbufsize;
|
||||||
|
|
|
@ -61,7 +61,7 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
|
||||||
|
|
||||||
tmpbuf = 0;
|
tmpbuf = 0;
|
||||||
tmpbufsize = 0;
|
tmpbufsize = 0;
|
||||||
sf = 0;
|
af_ref = 0;
|
||||||
|
|
||||||
_name = idstr;
|
_name = idstr;
|
||||||
|
|
||||||
|
@ -79,25 +79,32 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
|
||||||
if (err) {
|
if (err) {
|
||||||
throw failed_constructor();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
err = AudioFileOpen (ref, fsCurPerm, 0, sf);
|
err = ExtAudioFileOpen (ref, af_ref);
|
||||||
if (err) {
|
if (err) {
|
||||||
throw failed_constructor();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel >= _info.channels) {
|
if (channel >= n_channels) {
|
||||||
error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), _info.channels, channel) << endmsg;
|
error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg;
|
||||||
sf_close (sf);
|
ExtAudioFileDispose(af_ref);
|
||||||
sf = 0;
|
|
||||||
throw failed_constructor();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
_length = _info.frames;
|
int64_t ca_frames;
|
||||||
|
size_t prop_size = sizeof(ca_frames);
|
||||||
|
|
||||||
|
err = ExtAudioFileGetProperty(af_ref, kExtAudioFileProperty_FileLengthFrames,
|
||||||
|
sizeof(ca_frames), &ca_frames);
|
||||||
|
if (err) {
|
||||||
|
throw failed_constructor();
|
||||||
|
}
|
||||||
|
_length = ca_frames;
|
||||||
|
|
||||||
_path = file;
|
_path = file;
|
||||||
|
|
||||||
if (build_peak) {
|
if (build_peak) {
|
||||||
if (initialize_peakfile (false, file)) {
|
if (initialize_peakfile (false, file)) {
|
||||||
sf_close (sf);
|
ExtAudioFileDispose(af_ref);
|
||||||
sf = 0;
|
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,8 +115,8 @@ CoreAudioSource::~CoreAudioSource ()
|
||||||
{
|
{
|
||||||
GoingAway (this); /* EMIT SIGNAL */
|
GoingAway (this); /* EMIT SIGNAL */
|
||||||
|
|
||||||
if (sf) {
|
if (af_ref) {
|
||||||
sf_close (sf);
|
ExtAudioFileDispose(af_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmpbuf) {
|
if (tmpbuf) {
|
||||||
|
@ -130,20 +137,20 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co
|
||||||
float *ptr;
|
float *ptr;
|
||||||
uint32_t real_cnt;
|
uint32_t real_cnt;
|
||||||
|
|
||||||
if (sf_seek (sf, (off_t) start, SEEK_SET) < 0) {
|
OSStatus err = ExtAudioFileSeek(af_ref, start);
|
||||||
char errbuf[256];
|
if (err) {
|
||||||
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
|
error << string_compose(_("CoreAudioSource: could not seek to frame %1 within %2"), start, _name.substr (1)) << endmsg;
|
||||||
error << string_compose(_("CoreAudioSource: could not seek to frame %1 within %2 (%3)"), start, _name.substr (1), errbuf) << endmsg;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_info.channels == 1) {
|
if (n_channels == 1) {
|
||||||
jack_nframes_t ret = sf_read_float (sf, dst, cnt);
|
uint32_t ioNumber = cnt;
|
||||||
|
err = ExtAudioFileRead(af_ref, &ioNumber, dst);
|
||||||
_read_data_count = cnt * sizeof(float);
|
_read_data_count = cnt * sizeof(float);
|
||||||
return ret;
|
return ioNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_cnt = cnt * _info.channels;
|
real_cnt = cnt * n_channels;
|
||||||
|
|
||||||
{
|
{
|
||||||
LockMonitor lm (_tmpbuf_lock, __LINE__, __FILE__);
|
LockMonitor lm (_tmpbuf_lock, __LINE__, __FILE__);
|
||||||
|
@ -157,15 +164,16 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co
|
||||||
tmpbuf = new float[tmpbufsize];
|
tmpbuf = new float[tmpbufsize];
|
||||||
}
|
}
|
||||||
|
|
||||||
nread = sf_read_float (sf, tmpbuf, real_cnt);
|
nread = real_cnt;
|
||||||
|
err = ExtAudioFileRead(af_ext, &nread, tmpbuf);
|
||||||
ptr = tmpbuf + channel;
|
ptr = tmpbuf + channel;
|
||||||
nread /= _info.channels;
|
nread /= n_channels;
|
||||||
|
|
||||||
/* stride through the interleaved data */
|
/* stride through the interleaved data */
|
||||||
|
|
||||||
for (int32_t n = 0; n < nread; ++n) {
|
for (int32_t n = 0; n < nread; ++n) {
|
||||||
dst[n] = *ptr;
|
dst[n] = *ptr;
|
||||||
ptr += _info.channels;
|
ptr += n_channels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user