2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <pbd/mountpoint.h>
27 #include <ardour/coreaudio_source.h>
31 using namespace ARDOUR;
33 string CoreAudioSource::peak_dir = "";
35 CoreAudioSource::CoreAudioSource (const XMLNode& node)
38 if (set_state (node)) {
39 throw failed_constructor();
43 SourceCreated (this); /* EMIT SIGNAL */
46 CoreAudioSource::CoreAudioSource (const string& idstr, bool build_peak)
49 init (idstr, build_peak);
52 SourceCreated (this); /* EMIT SIGNAL */
57 CoreAudioSource::init (const string& idstr, bool build_peak)
59 string::size_type pos;
68 if ((pos = idstr.find_last_of (':')) == string::npos) {
72 channel = atoi (idstr.substr (pos+1).c_str());
73 file = idstr.substr (0, pos);
76 /* note that we temporarily truncated _id at the colon */
78 OSStatus err = FSPathMakeRef (file.c_str(), ref, 0);
80 throw failed_constructor();
82 err = ExtAudioFileOpen (ref, af_ref);
84 throw failed_constructor();
87 if (channel >= n_channels) {
88 error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg;
89 ExtAudioFileDispose(af_ref);
90 throw failed_constructor();
94 size_t prop_size = sizeof(ca_frames);
96 err = ExtAudioFileGetProperty(af_ref, kExtAudioFileProperty_FileLengthFrames,
97 sizeof(ca_frames), &ca_frames);
99 throw failed_constructor();
106 if (initialize_peakfile (false, file)) {
107 ExtAudioFileDispose(af_ref);
108 throw failed_constructor ();
113 CoreAudioSource::~CoreAudioSource ()
116 GoingAway (this); /* EMIT SIGNAL */
119 ExtAudioFileDispose(af_ref);
128 CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
130 return read (dst, start, cnt);
134 CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
140 OSStatus err = ExtAudioFileSeek(af_ref, start);
142 error << string_compose(_("CoreAudioSource: could not seek to frame %1 within %2"), start, _name.substr (1)) << endmsg;
146 if (n_channels == 1) {
147 uint32_t ioNumber = cnt;
148 err = ExtAudioFileRead(af_ref, &ioNumber, dst);
149 _read_data_count = cnt * sizeof(float);
153 real_cnt = cnt * n_channels;
156 LockMonitor lm (_tmpbuf_lock, __LINE__, __FILE__);
158 if (tmpbufsize < real_cnt) {
163 tmpbufsize = real_cnt;
164 tmpbuf = new float[tmpbufsize];
168 err = ExtAudioFileRead(af_ext, &nread, tmpbuf);
169 ptr = tmpbuf + channel;
172 /* stride through the interleaved data */
174 for (int32_t n = 0; n < nread; ++n) {
180 _read_data_count = cnt * sizeof(float);
186 CoreAudioSource::peak_path (string audio_path)
188 /* XXX hardly bombproof! fix me */
190 struct stat stat_file;
191 struct stat stat_mount;
193 string mp = mountpoint (audio_path);
195 stat (audio_path.c_str(), &stat_file);
196 stat (mp.c_str(), &stat_mount);
199 snprintf (buf, sizeof (buf), "%ld-%ld-%d.peak", stat_mount.st_ino, stat_file.st_ino, channel);
201 string res = peak_dir;
208 CoreAudioSource::old_peak_path (string audio_path)
210 return peak_path (audio_path);