mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-23 15:16:25 +01:00
coreaudio_source.cc compiles. (finally)
git-svn-id: svn://localhost/trunk/ardour2@355 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
874ba08fb4
commit
c3defb425a
3 changed files with 50 additions and 45 deletions
|
|
@ -164,7 +164,7 @@ if conf.CheckCHeader('/System/Library/Frameworks/CoreMIDI.framework/Headers/Core
|
||||||
|
|
||||||
if conf.CheckCHeader('/System/Library/Frameworks/AudioToolbox.framework/Headers/ExtendedAudioFile.h'):
|
if conf.CheckCHeader('/System/Library/Frameworks/AudioToolbox.framework/Headers/ExtendedAudioFile.h'):
|
||||||
ardour.Append(LINKFLAGS="-framework AudioToolbox")
|
ardour.Append(LINKFLAGS="-framework AudioToolbox")
|
||||||
#extra_sources += coreaudio_files
|
extra_sources += coreaudio_files
|
||||||
|
|
||||||
ardour = conf.Finish ()
|
ardour = conf.Finish ()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,13 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __coreaudio_source_h__
|
#ifndef __coreaudio_source_h__
|
||||||
#define __coreaudio_source_h__
|
#define __coreaudio_source_h__
|
||||||
|
|
||||||
#include <ardour/source.h>
|
#include <ardour/source.h>
|
||||||
|
#include <AudioToolbox/ExtendedAudioFile.h>
|
||||||
#include <AudioToolbox/AudioFile.h>
|
|
||||||
|
|
||||||
namespace ARDOUR {
|
namespace ARDOUR {
|
||||||
|
|
||||||
|
|
@ -34,7 +32,7 @@ class CoreAudioSource : public Source {
|
||||||
~CoreAudioSource ();
|
~CoreAudioSource ();
|
||||||
|
|
||||||
jack_nframes_t length() const { return _length; }
|
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
|
void mark_for_remove() {} // we never remove external sndfiles
|
||||||
string peak_path(string audio_path);
|
string peak_path(string audio_path);
|
||||||
string old_peak_path(string audio_path);
|
string old_peak_path(string audio_path);
|
||||||
|
|
@ -45,17 +43,16 @@ class CoreAudioSource : public Source {
|
||||||
private:
|
private:
|
||||||
static string peak_dir;
|
static string peak_dir;
|
||||||
|
|
||||||
AudioFileID af;
|
ExtAudioFileRef af;
|
||||||
AudioStreamBasicDescription _info;
|
|
||||||
|
|
||||||
uint16_t channel;
|
uint16_t channel;
|
||||||
|
uint16_t n_channels;
|
||||||
mutable float *tmpbuf;
|
mutable float *tmpbuf;
|
||||||
mutable jack_nframes_t tmpbufsize;
|
mutable jack_nframes_t tmpbufsize;
|
||||||
mutable PBD::Lock _tmpbuf_lock;
|
mutable PBD::Lock _tmpbuf_lock;
|
||||||
string _path;
|
string _path;
|
||||||
|
|
||||||
void init (const string &str, bool build_peak);
|
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 */
|
}; /* namespace ARDOUR */
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -15,7 +16,6 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -61,7 +61,8 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
|
||||||
|
|
||||||
tmpbuf = 0;
|
tmpbuf = 0;
|
||||||
tmpbufsize = 0;
|
tmpbufsize = 0;
|
||||||
af_ref = 0;
|
af = 0;
|
||||||
|
OSStatus err = noErr;
|
||||||
|
|
||||||
_name = idstr;
|
_name = idstr;
|
||||||
|
|
||||||
|
|
@ -73,32 +74,33 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
|
||||||
file = idstr.substr (0, pos);
|
file = idstr.substr (0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* note that we temporarily truncated _id at the colon */
|
/* note that we temporarily truncated _id at the colon */
|
||||||
FSRef* ref;
|
FSRef* ref;
|
||||||
OSStatus err = FSPathMakeRef ((UInt8*)file.c_str(), ref, 0);
|
err = FSPathMakeRef ((UInt8*)file.c_str(), ref, 0);
|
||||||
if (err) {
|
if (err != noErr) {
|
||||||
throw failed_constructor();
|
|
||||||
}
|
|
||||||
err = AudioFileOpen (ref, 0, fsRdPerm, &af);
|
|
||||||
if (err) {
|
|
||||||
throw failed_constructor();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX get value for n_channels */
|
err = ExtAudioFileOpen (ref, &af);
|
||||||
UInt32 size = sizeof(AudioStreamBasicDescription);
|
if (err != noErr) {
|
||||||
memset (_info, 0, size);
|
throw failed_constructor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO get channels */
|
||||||
|
n_channels = 0;
|
||||||
|
|
||||||
if (channel >= n_channels) {
|
if (channel >= n_channels) {
|
||||||
error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg;
|
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();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t ca_frames;
|
int64_t ca_frames;
|
||||||
size_t prop_size = sizeof(ca_frames);
|
size_t prop_size = sizeof(ca_frames);
|
||||||
|
|
||||||
err = ExtAudioFileGetProperty(*af_ref, kExtAudioFileProperty_FileLengthFrames, &prop_size, &ca_frames);
|
err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &prop_size, &ca_frames);
|
||||||
if (err) {
|
if (err != noErr) {
|
||||||
throw failed_constructor();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
_length = ca_frames;
|
_length = ca_frames;
|
||||||
|
|
@ -107,7 +109,7 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
|
||||||
|
|
||||||
if (build_peak) {
|
if (build_peak) {
|
||||||
if (initialize_peakfile (false, file)) {
|
if (initialize_peakfile (false, file)) {
|
||||||
AudioFileClose(af);
|
ExtAudioFileDispose (af);
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,8 +120,8 @@ CoreAudioSource::~CoreAudioSource ()
|
||||||
{
|
{
|
||||||
GoingAway (this); /* EMIT SIGNAL */
|
GoingAway (this); /* EMIT SIGNAL */
|
||||||
|
|
||||||
if (af_ref) {
|
if (af) {
|
||||||
ExtAudioFileDispose(*af_ref);
|
ExtAudioFileDispose (af);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmpbuf) {
|
if (tmpbuf) {
|
||||||
|
|
@ -128,35 +130,38 @@ CoreAudioSource::~CoreAudioSource ()
|
||||||
}
|
}
|
||||||
|
|
||||||
jack_nframes_t
|
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
|
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;
|
float *ptr;
|
||||||
uint32_t real_cnt;
|
uint32_t real_cnt;
|
||||||
|
OSStatus err = noErr;
|
||||||
|
|
||||||
OSStatus err = ExtAudioFileSeek(*af_ref, start);
|
err = ExtAudioFileSeek(af, start);
|
||||||
if (err) {
|
if (err != noErr) {
|
||||||
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), err) << endmsg;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioBuffer ab;
|
||||||
|
ab.mNumberChannels = n_channels;
|
||||||
|
ab.mDataByteSize = cnt;
|
||||||
|
ab.mData = dst;
|
||||||
|
|
||||||
AudioBufferList abl;
|
AudioBufferList abl;
|
||||||
abl.mNumberBuffers = 1;
|
abl.mNumberBuffers = 1;
|
||||||
abl.mBuffers[0].mNumberChannels = n_channels;
|
abl.mBuffers[1] = ab;
|
||||||
|
|
||||||
if (n_channels == 1) {
|
if (n_channels == 1) {
|
||||||
abl.mBuffers[0].mDataByteSize = cnt * sizeof(float);
|
err = ExtAudioFileRead(af, (UInt32*) &cnt, &abl);
|
||||||
abl.mBuffers[0].mData = dst;
|
|
||||||
nread = cnt;
|
|
||||||
err = ExtAudioFileRead(*af_ref, (UInt32*)&nread, &abl);
|
|
||||||
_read_data_count = cnt * sizeof(float);
|
_read_data_count = cnt * sizeof(float);
|
||||||
return nread;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_cnt = cnt * n_channels;
|
real_cnt = cnt * n_channels;
|
||||||
|
|
@ -172,15 +177,17 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co
|
||||||
tmpbufsize = real_cnt;
|
tmpbufsize = real_cnt;
|
||||||
tmpbuf = new float[tmpbufsize];
|
tmpbuf = new float[tmpbufsize];
|
||||||
}
|
}
|
||||||
|
ab.mDataByteSize = real_cnt;
|
||||||
|
ab.mData = tmpbuf;
|
||||||
|
|
||||||
nread = real_cnt;
|
err = ExtAudioFileRead(af, (UInt32*) &real_cnt, &abl);
|
||||||
err = ExtAudioFileRead(*af_ref, (UInt32*)&nread, tmpbuf);
|
// nread = sf_read_float (af, tmpbuf, real_cnt);
|
||||||
ptr = tmpbuf + channel;
|
ptr = tmpbuf + channel;
|
||||||
nread /= n_channels;
|
nread /= n_channels;
|
||||||
|
|
||||||
/* stride through the interleaved data */
|
/* stride through the interleaved data */
|
||||||
|
|
||||||
for (uint32_t n = 0; n < nread; ++n) {
|
for (int32_t n = 0; n < nread; ++n) {
|
||||||
dst[n] = *ptr;
|
dst[n] = *ptr;
|
||||||
ptr += n_channels;
|
ptr += n_channels;
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +195,7 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) co
|
||||||
|
|
||||||
_read_data_count = cnt * sizeof(float);
|
_read_data_count = cnt * sizeof(float);
|
||||||
|
|
||||||
return nread;
|
return real_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
|
|
@ -218,3 +225,4 @@ CoreAudioSource::old_peak_path (string audio_path)
|
||||||
{
|
{
|
||||||
return peak_path (audio_path);
|
return peak_path (audio_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue