summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-12-10 18:28:55 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2014-12-10 18:28:55 -0500
commit294b99aabf3eb96323a3159b7a5e1b4bfc1ff04a (patch)
treedbb6bfba564d2979c8cebbfebe162a9659dff5aa /libs/ardour
parent17707b9674958391949e59a724a264cdcc2d65ff (diff)
remove file manager LRU cache from code.
This was a very clever attempt to fix a non-problem. If the platform doesn't have enough file descriptors available then the platform is broken and we're not going to hack around trying to fix it.
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/audiosource.h2
-rw-r--r--libs/ardour/ardour/file_source.h2
-rw-r--r--libs/ardour/ardour/smf_source.h16
-rw-r--r--libs/ardour/ardour/sndfilesource.h6
-rw-r--r--libs/ardour/audiosource.cc80
-rw-r--r--libs/ardour/file_source.cc2
-rw-r--r--libs/ardour/smf_source.cc5
-rw-r--r--libs/ardour/sndfilesource.cc110
8 files changed, 90 insertions, 133 deletions
diff --git a/libs/ardour/ardour/audiosource.h b/libs/ardour/ardour/audiosource.h
index 910e03170d..7d1878f286 100644
--- a/libs/ardour/ardour/audiosource.h
+++ b/libs/ardour/ardour/audiosource.h
@@ -32,7 +32,6 @@
#include "ardour/source.h"
#include "ardour/ardour.h"
#include "ardour/readable.h"
-#include "pbd/file_manager.h"
#include "pbd/stateful.h"
#include "pbd/xml++.h"
@@ -160,7 +159,6 @@ class LIBARDOUR_API AudioSource : virtual public Source,
*/
mutable Glib::Threads::Mutex _peaks_ready_lock;
- PBD::FdFileDescriptor* _peakfile_descriptor;
int _peakfile_fd;
framecnt_t peak_leftover_cnt;
framecnt_t peak_leftover_size;
diff --git a/libs/ardour/ardour/file_source.h b/libs/ardour/ardour/file_source.h
index 8cbbfed0d9..ac073d934c 100644
--- a/libs/ardour/ardour/file_source.h
+++ b/libs/ardour/ardour/file_source.h
@@ -110,8 +110,6 @@ protected:
uint16_t _channel;
bool _within_session;
std::string _origin;
- bool _open;
-
};
} // namespace ARDOUR
diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h
index 1c1f2bbcba..56b70b15bd 100644
--- a/libs/ardour/ardour/smf_source.h
+++ b/libs/ardour/ardour/smf_source.h
@@ -77,8 +77,16 @@ public:
void set_path (const std::string& newpath);
private:
- int open_for_write ();
+ bool _open;
+ Evoral::MusicalTime _last_ev_time_beats;
+ framepos_t _last_ev_time_frames;
+ /** end time (start + duration) of last call to read_unlocked */
+ mutable framepos_t _smf_last_read_end;
+ /** time (in SMF ticks, 1 tick per _ppqn) of the last event read by read_unlocked */
+ mutable framepos_t _smf_last_read_time;
+ int open_for_write ();
+
framecnt_t read_unlocked (Evoral::EventSink<framepos_t>& dst,
framepos_t position,
framepos_t start,
@@ -89,12 +97,6 @@ public:
framepos_t position,
framecnt_t cnt);
- Evoral::MusicalTime _last_ev_time_beats;
- framepos_t _last_ev_time_frames;
- /** end time (start + duration) of last call to read_unlocked */
- mutable framepos_t _smf_last_read_end;
- /** time (in SMF ticks, 1 tick per _ppqn) of the last event read by read_unlocked */
- mutable framepos_t _smf_last_read_time;
};
}; /* namespace ARDOUR */
diff --git a/libs/ardour/ardour/sndfilesource.h b/libs/ardour/ardour/sndfilesource.h
index 7f5e538f4a..11ec6fe33c 100644
--- a/libs/ardour/ardour/sndfilesource.h
+++ b/libs/ardour/ardour/sndfilesource.h
@@ -24,7 +24,6 @@
#include "ardour/audiofilesource.h"
#include "ardour/broadcast_info.h"
-#include "pbd/sndfile_manager.h"
namespace ARDOUR {
@@ -75,8 +74,6 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
static int get_soundfile_info (const std::string& path, SoundFileInfo& _info, std::string& error_msg);
- void release_descriptor ();
-
protected:
void set_path (const std::string& p);
void set_header_timeline_position ();
@@ -86,7 +83,7 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
framecnt_t write_float (Sample* data, framepos_t pos, framecnt_t cnt);
private:
- PBD::SndFileDescriptor* _descriptor;
+ SNDFILE* _sndfile;
SF_INFO _info;
BroadcastInfo *_broadcast_info;
@@ -113,7 +110,6 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
framecnt_t nondestructive_write_unlocked (Sample *dst, framecnt_t cnt);
void handle_header_position_change ();
PBD::ScopedConnection header_position_connection;
- PBD::ScopedConnection file_manager_connection;
};
} // namespace ARDOUR
diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc
index fd20c3afdb..a032aa1f63 100644
--- a/libs/ardour/audiosource.cc
+++ b/libs/ardour/audiosource.cc
@@ -71,27 +71,25 @@ bool AudioSource::_build_peakfiles = false;
AudioSource::AudioSource (Session& s, string name)
: Source (s, DataType::AUDIO, name)
, _length (0)
+ , _peak_byte_max (0)
+ , _peaks_built (false)
+ , _peakfile_fd (-1)
+ , peak_leftover_cnt (0)
+ , peak_leftover_size (0)
+ , peak_leftovers (0)
{
- _peaks_built = false;
- _peak_byte_max = 0;
- _peakfile_descriptor = 0;
- peak_leftover_cnt = 0;
- peak_leftover_size = 0;
- peak_leftovers = 0;
}
AudioSource::AudioSource (Session& s, const XMLNode& node)
: Source (s, node)
, _length (0)
+ , _peak_byte_max (0)
+ , _peaks_built (false)
+ , _peakfile_fd (-1)
+ , peak_leftover_cnt (0)
+ , peak_leftover_size (0)
+ , peak_leftovers (0)
{
-
- _peaks_built = false;
- _peak_byte_max = 0;
- _peakfile_descriptor = 0;
- peak_leftover_cnt = 0;
- peak_leftover_size = 0;
- peak_leftovers = 0;
-
if (set_state (node, Stateful::loading_state_version)) {
throw failed_constructor();
}
@@ -105,7 +103,9 @@ AudioSource::~AudioSource ()
cerr << "AudioSource destroyed with leftover peak data pending" << endl;
}
- delete _peakfile_descriptor;
+ close (_peakfile_fd);
+ _peakfile_fd = -1;
+
delete [] peak_leftovers;
}
@@ -318,6 +318,13 @@ AudioSource::read_peaks (PeakData *peaks, framecnt_t npeaks, framepos_t start, f
* @param npeaks Number of peaks to write.
*/
+struct ScopedFileDescriptor {
+ ScopedFileDescriptor (int fd) : _fd (fd) {}
+ ~ScopedFileDescriptor() { close (_fd); }
+ operator int() { return _fd; }
+ int _fd;
+};
+
int
AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t start, framecnt_t cnt,
double samples_per_visual_peak, framecnt_t samples_per_file_peak) const
@@ -331,9 +338,13 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t
ssize_t nread;
framecnt_t zero_fill = 0;
- boost::scoped_ptr<FdFileDescriptor> peakfile_descriptor(new FdFileDescriptor (peakpath, false, 0664));
- int peakfile_fd = -1;
+ ScopedFileDescriptor sfd (::open (peakpath.c_str(), O_RDONLY));
+ if (sfd < 0) {
+ error << string_compose (_("Cannot open peakfile @ %1 for reading (%2)"), peakpath, strerror (errno)) << endmsg;
+ return -1;
+ }
+
expected_peaks = (cnt / (double) samples_per_file_peak);
scale = npeaks/expected_peaks;
@@ -382,21 +393,16 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t
ssize_t bytes_to_read = sizeof (PeakData)* npeaks;
/* open, read, close */
- if ((peakfile_fd = peakfile_descriptor->allocate ()) < 0) {
- error << string_compose(_("AudioSource: cannot open peakpath (a) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
- return -1;
- }
-
DEBUG_TRACE (DEBUG::Peaks, "DIRECT PEAKS\n");
- offset = lseek (peakfile_fd, first_peak_byte, SEEK_SET);
+ offset = lseek (sfd, first_peak_byte, SEEK_SET);
if (offset != first_peak_byte) {
error << string_compose(_("AudioSource: could not seek to correct location in peak file \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
return -1;
}
- nread = ::read (peakfile_fd, peaks, bytes_to_read);
+ nread = ::read (sfd, peaks, bytes_to_read);
if (nread != bytes_to_read) {
DEBUG_TRACE (DEBUG::Peaks, string_compose ("[%1]: Cannot read peaks from peakfile! (read only %2 not %3 at sample %4 = byte %5 )\n"
@@ -449,11 +455,6 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t
/* open ... close during out: handling */
- if ((peakfile_fd = peakfile_descriptor->allocate ()) < 0) {
- error << string_compose(_("AudioSource: cannot open peakpath (b) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
- return 0;
- }
-
while (nvisual_peaks < npeaks) {
if (i == stored_peaks_read) {
@@ -467,16 +468,16 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t
, bytes_to_read, start_byte));
- off_t offset = lseek (peakfile_fd, start_byte, SEEK_SET);
+ off_t offset = lseek (sfd, start_byte, SEEK_SET);
if (offset != start_byte) {
error << string_compose(_("AudioSource: could not seek to correct location in peak file \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
return -1;
}
- if ((nread = ::read (peakfile_fd, staging.get(), bytes_to_read)) != bytes_to_read) {
+ if ((nread = ::read (sfd, staging.get(), bytes_to_read)) != bytes_to_read) {
- off_t fend = lseek (peakfile_fd, 0, SEEK_END);
+ off_t fend = lseek (sfd, 0, SEEK_END);
DEBUG_TRACE (DEBUG::Peaks, string_compose ("[%1]: cannot read peak data from peakfile (%2 peaks instead of %3) (%4) at start_byte = %5 _length = %6 versus len = %7 expected maxpeaks = %8 npeaks was %9"
, _name, (nread / sizeof(PeakData)), to_read, g_strerror (errno), start_byte, _length, fend, ((_length - current_frame)/samples_per_file_peak), npeaks));
@@ -667,8 +668,7 @@ AudioSource::build_peaks_from_scratch ()
int
AudioSource::prepare_for_peakfile_writes ()
{
- _peakfile_descriptor = new FdFileDescriptor (peakpath, true, 0664);
- if ((_peakfile_fd = _peakfile_descriptor->allocate()) < 0) {
+ if ((_peakfile_fd = open (peakpath.c_str(), O_CREAT|O_RDWR, 0664)) < 0) {
error << string_compose(_("AudioSource: cannot open peakpath (c) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
return -1;
}
@@ -688,8 +688,8 @@ AudioSource::done_with_peakfile_writes (bool done)
PeaksReady (); /* EMIT SIGNAL */
}
- delete _peakfile_descriptor;
- _peakfile_descriptor = 0;
+ close (_peakfile_fd);
+ _peakfile_fd = -1;
}
/** @param first_frame Offset from the source start of the first frame to process */
@@ -712,8 +712,10 @@ AudioSource::compute_and_write_peaks (Sample* buf, framecnt_t first_frame, frame
off_t first_peak_byte;
boost::scoped_array<Sample> buf2;
- if (_peakfile_descriptor == 0) {
- prepare_for_peakfile_writes ();
+ if (_peakfile_fd < 0) {
+ if (prepare_for_peakfile_writes ()) {
+ return -1;
+ }
}
restart:
@@ -887,7 +889,7 @@ AudioSource::compute_and_write_peaks (Sample* buf, framecnt_t first_frame, frame
void
AudioSource::truncate_peakfile ()
{
- if (_peakfile_descriptor == 0) {
+ if (_peakfile_fd < 0) {
error << string_compose (_("programming error: %1"), "AudioSource::truncate_peakfile() called without open peakfile descriptor")
<< endmsg;
return;
diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc
index 06867e688e..0aec49e6bd 100644
--- a/libs/ardour/file_source.cc
+++ b/libs/ardour/file_source.cc
@@ -59,7 +59,6 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
, _file_is_new (!origin.empty()) // if origin is left unspecified (empty string) then file must exist
, _channel (0)
, _origin (origin)
- , _open (false)
{
set_within_session_from_path (path);
}
@@ -68,7 +67,6 @@ FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist
: Source (session, node)
, _file_is_new (false)
, _channel (0)
- , _open (false)
{
/* this setting of _path is temporary - we expect derived classes
to call ::init() which will actually locate the file
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc
index e4cfede179..b25977fe8d 100644
--- a/libs/ardour/smf_source.cc
+++ b/libs/ardour/smf_source.cc
@@ -59,6 +59,7 @@ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
, MidiSource(s, path, flags)
, FileSource(s, DataType::MIDI, path, string(), flags)
, Evoral::SMF()
+ , _open (false)
, _last_ev_time_beats(0.0)
, _last_ev_time_frames(0)
, _smf_last_read_end (0)
@@ -94,6 +95,7 @@ SMFSource::SMFSource (Session& s, const string& path)
, MidiSource(s, path, Source::Flag (0))
, FileSource(s, DataType::MIDI, path, string(), Source::Flag (0))
, Evoral::SMF()
+ , _open (false)
, _last_ev_time_beats(0.0)
, _last_ev_time_frames(0)
, _smf_last_read_end (0)
@@ -125,6 +127,7 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
: Source(s, node)
, MidiSource(s, node)
, FileSource(s, node, must_exist)
+ , _open (false)
, _last_ev_time_beats(0.0)
, _last_ev_time_frames(0)
, _smf_last_read_end (0)
@@ -174,7 +177,7 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
return;
}
- if (open(_path)) {
+ if (open (_path)) {
throw failed_constructor ();
}
diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc
index 9af2b56056..27c91c8c27 100644
--- a/libs/ardour/sndfilesource.cc
+++ b/libs/ardour/sndfilesource.cc
@@ -58,7 +58,7 @@ const Source::Flag SndFileSource::default_writable_flags = Source::Flag (
SndFileSource::SndFileSource (Session& s, const XMLNode& node)
: Source(s, node)
, AudioFileSource (s, node)
- , _descriptor (0)
+ , _sndfile (0)
, _broadcast_info (0)
, _capture_start (false)
, _capture_end (false)
@@ -82,7 +82,7 @@ SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flag
: Source(s, DataType::AUDIO, path, flags)
/* note that the origin of an external file is itself */
, AudioFileSource (s, path, Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
- , _descriptor (0)
+ , _sndfile (0)
, _broadcast_info (0)
, _capture_start (false)
, _capture_end (false)
@@ -108,7 +108,7 @@ SndFileSource::SndFileSource (Session& s, const string& path, const string& orig
SampleFormat sfmt, HeaderFormat hf, framecnt_t rate, Flag flags)
: Source(s, DataType::AUDIO, path, flags)
, AudioFileSource (s, path, origin, flags, sfmt, hf)
- , _descriptor (0)
+ , _sndfile (0)
, _broadcast_info (0)
, _capture_start (false)
, _capture_end (false)
@@ -194,7 +194,7 @@ SndFileSource::SndFileSource (Session& s, const string& path, int chn)
: Source (s, DataType::AUDIO, path, Flag (0))
/* the final boolean argument is not used, its value is irrelevant. see audiofilesource.h for explanation */
, AudioFileSource (s, path, Flag (0))
- , _descriptor (0)
+ , _sndfile (0)
, _broadcast_info (0)
, _capture_start (false)
, _capture_end (false)
@@ -235,17 +235,19 @@ SndFileSource::open ()
{
string path_to_open;
+ if (_sndfile) {
+ return 0;
+ }
+
#ifdef PLATFORM_WINDOWS
path_to_open = Glib::locale_from_utf8(_path);
#else
path_to_open = _path;
#endif
- _descriptor = new SndFileDescriptor (path_to_open.c_str(), writable(), &_info);
- _descriptor->Closed.connect_same_thread (file_manager_connection, boost::bind (&SndFileSource::file_closed, this));
- SNDFILE* sf = _descriptor->allocate ();
+ _sndfile = sf_open (path_to_open.c_str(), writable() ? SFM_RDWR : SFM_READ, &_info);
- if (sf == 0) {
+ if (_sndfile == 0) {
char errbuf[1024];
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
#ifndef HAVE_COREAUDIO
@@ -265,8 +267,8 @@ SndFileSource::open ()
#ifndef HAVE_COREAUDIO
error << string_compose(_("SndFileSource: file only contains %1 channels; %2 is invalid as a channel number"), _info.channels, _channel) << endmsg;
#endif
- delete _descriptor;
- _descriptor = 0;
+ sf_close (_sndfile);
+ _sndfile = 0;
return -1;
}
@@ -276,7 +278,7 @@ SndFileSource::open ()
_broadcast_info = new BroadcastInfo;
}
- bool bwf_info_exists = _broadcast_info->load_from_file (sf);
+ bool bwf_info_exists = _broadcast_info->load_from_file (_sndfile);
if (_file_is_new && _length == 0 && writable() && !bwf_info_exists) {
/* newly created files will not have a BWF header at this point in time.
@@ -305,7 +307,7 @@ SndFileSource::open ()
}
if (writable()) {
- sf_command (sf, SFC_SET_UPDATE_HEADER_AUTO, 0, SF_FALSE);
+ sf_command (_sndfile, SFC_SET_UPDATE_HEADER_AUTO, 0, SF_FALSE);
if (_flags & Broadcast) {
@@ -316,7 +318,7 @@ SndFileSource::open ()
_broadcast_info->set_from_session (_session, header_position_offset);
_broadcast_info->set_description (string_compose ("BWF %1", _name));
- if (!_broadcast_info->write_to_file (sf)) {
+ if (!_broadcast_info->write_to_file (_sndfile)) {
error << string_compose (_("cannot set broadcast info for audio file %1 (%2); dropping broadcast info for this file"),
path_to_open, _broadcast_info->get_error())
<< endmsg;
@@ -326,15 +328,16 @@ SndFileSource::open ()
}
}
}
-
- _descriptor->release ();
- _open = true;
+
return 0;
}
SndFileSource::~SndFileSource ()
{
- delete _descriptor;
+ if (_sndfile) {
+ sf_close (_sndfile);
+ _sndfile = 0;
+ }
delete _broadcast_info;
delete [] xfade_buf;
}
@@ -355,15 +358,13 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
uint32_t real_cnt;
framepos_t file_cnt;
- if (writable() && !_open) {
+ if (writable() && !_sndfile) {
/* file has not been opened yet - nothing written to it */
memset (dst, 0, sizeof (Sample) * cnt);
return cnt;
}
- SNDFILE* sf = _descriptor->allocate ();
-
- if (sf == 0) {
+ if (_sndfile == 0) {
error << string_compose (_("could not allocate file %1 for reading."), _path) << endmsg;
return 0;
}
@@ -396,22 +397,20 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
if (file_cnt) {
- if (sf_seek (sf, (sf_count_t) start, SEEK_SET|SFM_READ) != (sf_count_t) start) {
+ if (sf_seek (_sndfile, (sf_count_t) start, SEEK_SET|SFM_READ) != (sf_count_t) start) {
char errbuf[256];
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
error << string_compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.val().substr (1), errbuf) << endmsg;
- _descriptor->release ();
return 0;
}
if (_info.channels == 1) {
- framecnt_t ret = sf_read_float (sf, dst, file_cnt);
+ framecnt_t ret = sf_read_float (_sndfile, dst, file_cnt);
if (ret != file_cnt) {
char errbuf[256];
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
error << string_compose(_("SndFileSource: @ %1 could not read %2 within %3 (%4) (len = %5, ret was %6)"), start, file_cnt, _name.val().substr (1), errbuf, _length, ret) << endl;
}
- _descriptor->release ();
return ret;
}
}
@@ -420,7 +419,7 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
Sample* interleave_buf = get_interleave_buffer (real_cnt);
- nread = sf_read_float (sf, interleave_buf, real_cnt);
+ nread = sf_read_float (_sndfile, interleave_buf, real_cnt);
ptr = interleave_buf + _channel;
nread /= _info.channels;
@@ -431,14 +430,13 @@ SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) con
ptr += _info.channels;
}
- _descriptor->release ();
return nread;
}
framecnt_t
SndFileSource::write_unlocked (Sample *data, framecnt_t cnt)
{
- if (!_open && open()) {
+ if (open()) {
return 0; // failure
}
@@ -589,19 +587,12 @@ SndFileSource::flush_header ()
return -1;
}
- if (!_open) {
- warning << string_compose (_("attempt to flush an un-opened audio file source (%1)"), _path) << endmsg;
- return -1;
- }
-
- SNDFILE* sf = _descriptor->allocate ();
- if (sf == 0) {
+ if (_sndfile == 0) {
error << string_compose (_("could not allocate file %1 to write header"), _path) << endmsg;
return -1;
}
- int const r = sf_command (sf, SFC_UPDATE_HEADER_NOW, 0, 0) != SF_TRUE;
- _descriptor->release ();
+ int const r = sf_command (_sndfile, SFC_UPDATE_HEADER_NOW, 0, 0) != SF_TRUE;
return r;
}
@@ -609,25 +600,18 @@ SndFileSource::flush_header ()
void
SndFileSource::flush ()
{
- if (!_open) {
- warning << string_compose (_("attempt to flush an un-opened audio file source (%1)"), _path) << endmsg;
- return;
- }
-
if (!writable()) {
warning << string_compose (_("attempt to flush a non-writable audio file source (%1)"), _path) << endmsg;
return;
}
- SNDFILE* sf = _descriptor->allocate ();
- if (sf == 0) {
+ if (_sndfile == 0) {
error << string_compose (_("could not allocate file %1 to flush contents"), _path) << endmsg;
return;
}
// Hopefully everything OK
- sf_write_sync (sf);
- _descriptor->release ();
+ sf_write_sync (_sndfile);
}
int
@@ -638,7 +622,7 @@ SndFileSource::setup_broadcast_info (framepos_t /*when*/, struct tm& now, time_t
return -1;
}
- if (!_open) {
+ if (!_sndfile) {
warning << string_compose (_("attempt to set BWF info for an un-opened audio file source (%1)"), _path) << endmsg;
return -1;
}
@@ -654,9 +638,7 @@ SndFileSource::setup_broadcast_info (framepos_t /*when*/, struct tm& now, time_t
set_header_timeline_position ();
- SNDFILE* sf = _descriptor->allocate ();
-
- if (sf == 0 || !_broadcast_info->write_to_file (sf)) {
+ if (!_broadcast_info->write_to_file (_sndfile)) {
error << string_compose (_("cannot set broadcast info for audio file %1 (%2); dropping broadcast info for this file"),
_path, _broadcast_info->get_error())
<< endmsg;
@@ -665,7 +647,6 @@ SndFileSource::setup_broadcast_info (framepos_t /*when*/, struct tm& now, time_t
_broadcast_info = 0;
}
- _descriptor->release ();
return 0;
}
@@ -678,9 +659,7 @@ SndFileSource::set_header_timeline_position ()
_broadcast_info->set_time_reference (_timeline_position);
- SNDFILE* sf = _descriptor->allocate ();
-
- if (sf == 0 || !_broadcast_info->write_to_file (sf)) {
+ if (_sndfile == 0 || !_broadcast_info->write_to_file (_sndfile)) {
error << string_compose (_("cannot set broadcast info for audio file %1 (%2); dropping broadcast info for this file"),
_path, _broadcast_info->get_error())
<< endmsg;
@@ -688,29 +667,22 @@ SndFileSource::set_header_timeline_position ()
delete _broadcast_info;
_broadcast_info = 0;
}
-
- _descriptor->release ();
}
framecnt_t
SndFileSource::write_float (Sample* data, framepos_t frame_pos, framecnt_t cnt)
{
- SNDFILE* sf = _descriptor->allocate ();
-
- if (sf == 0 || sf_seek (sf, frame_pos, SEEK_SET|SFM_WRITE) < 0) {
+ if (_sndfile == 0 || sf_seek (_sndfile, frame_pos, SEEK_SET|SFM_WRITE) < 0) {
char errbuf[256];
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
error << string_compose (_("%1: cannot seek to %2 (libsndfile error: %3)"), _path, frame_pos, errbuf) << endmsg;
- _descriptor->release ();
return 0;
}
- if (sf_writef_float (sf, data, cnt) != (ssize_t) cnt) {
- _descriptor->release ();
+ if (sf_writef_float (_sndfile, data, cnt) != (ssize_t) cnt) {
return 0;
}
- _descriptor->release ();
return cnt;
}
@@ -1011,17 +983,5 @@ void
SndFileSource::set_path (const string& p)
{
FileSource::set_path (p);
-
- if (_descriptor) {
- _descriptor->set_path (_path);
- }
}
-void
-SndFileSource::release_descriptor ()
-{
- if (_descriptor) {
- _descriptor->release ();
- _descriptor = 0;
- }
-}