#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
-#include <pbd/xml++.h>
-#include <pbd/pthread_utils.h>
+#include "pbd/xml++.h"
+#include "pbd/pthread_utils.h"
-#include <ardour/audiosource.h>
-#include <ardour/cycle_timer.h>
-#include <ardour/session.h>
-#include <ardour/transient_detector.h>
+#include "ardour/audiosource.h"
+#include "ardour/cycle_timer.h"
+#include "ardour/session.h"
+#include "ardour/transient_detector.h"
+#include "ardour/runtime_functions.h"
#include "i18n.h"
#define _FPP 256
AudioSource::AudioSource (Session& s, ustring name)
- : Source (s, name, DataType::AUDIO)
+ : Source (s, DataType::AUDIO, name)
+ , _length (0)
{
_peaks_built = false;
_peak_byte_max = 0;
AudioSource::AudioSource (Session& s, const XMLNode& node)
: Source (s, node)
+ , _length (0)
{
+
_peaks_built = false;
_peak_byte_max = 0;
peakfile = -1;
::close (peakfile);
}
- if (peak_leftovers) {
- delete [] peak_leftovers;
- }
+ delete [] peak_leftovers;
}
XMLNode&
{
const XMLProperty* prop;
- Source::set_state (node);
-
if ((prop = node.property ("captured-for")) != 0) {
_captured_for = prop->value();
}
return 0;
}
+sframes_t
+AudioSource::length (sframes_t /*pos*/) const
+{
+ return _length;
+}
+
+void
+AudioSource::update_length (sframes_t pos, sframes_t cnt)
+{
+ if (pos + cnt > _length) {
+ _length = pos + cnt;
+ }
+}
+
+
/***********************************************************************
PEAK FILE STUFF
***********************************************************************/
/* we found it in the peaks dir, so check it out */
- if (statbuf.st_size == 0) {
+ if (statbuf.st_size == 0 || ((nframes_t) statbuf.st_size < ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) {
// empty
_peaks_built = false;
} else {
struct stat stat_file;
int err = stat (audio_path.c_str(), &stat_file);
- if (!err && stat_file.st_mtime > statbuf.st_mtime){
+ if (err) {
_peaks_built = false;
_peak_byte_max = 0;
} else {
- _peaks_built = true;
- _peak_byte_max = statbuf.st_size;
+
+ /* allow 6 seconds slop on checking peak vs. file times because of various
+ disk action "races"
+ */
+
+ if (stat_file.st_mtime > statbuf.st_mtime && (stat_file.st_mtime - statbuf.st_mtime > 6)) {
+ _peaks_built = false;
+ _peak_byte_max = 0;
+ } else {
+ _peaks_built = true;
+ _peak_byte_max = statbuf.st_size;
+ }
}
}
}
}
nframes_t
-AudioSource::read (Sample *dst, nframes_t start, nframes_t cnt) const
+AudioSource::read (Sample *dst, sframes_t start, nframes_t cnt, int /*channel*/) const
{
Glib::Mutex::Lock lm (_lock);
return read_unlocked (dst, start, cnt);
}
int
-AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt, double samples_per_visual_peak) const
+AudioSource::read_peaks (PeakData *peaks, nframes_t npeaks, sframes_t start, nframes_t cnt, double samples_per_visual_peak) const
{
return read_peaks_with_fpp (peaks, npeaks, start, cnt, samples_per_visual_peak, _FPP);
}
+/** @param peaks Buffer to write peak data.
+ * @param npeaks Number of peaks to write.
+ */
+
int
-AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt,
+AudioSource::read_peaks_with_fpp (PeakData *peaks, nframes_t npeaks, sframes_t start, nframes_t cnt,
double samples_per_visual_peak, nframes_t samples_per_file_peak) const
{
Glib::Mutex::Lock lm (_lock);
npeaks = min ((nframes_t) floor (cnt / samples_per_visual_peak), npeaks);
zero_fill = old - npeaks;
}
-
- // cerr << "actual npeaks = " << npeaks << " zf = " << zero_fill << endl;
+ // cerr << "actual npeaks = " << npeaks << " zf = " << zero_fill << endl;
+
if (npeaks == cnt) {
#ifdef DEBUG_READ_PEAKS
if (i == stored_peaks_read) {
uint32_t start_byte = current_stored_peak * sizeof(PeakData);
- tnp = min ((_length/samples_per_file_peak - current_stored_peak), (nframes_t) expected_peaks);
+ tnp = min ((nframes_t)(_length/samples_per_file_peak - current_stored_peak), (nframes_t) expected_peaks);
to_read = min (chunksize, tnp);
#ifdef DEBUG_READ_PEAKS
while (nvisual_peaks < npeaks) {
if (i == frames_read) {
-
- to_read = min (chunksize, (_length - current_frame));
+
+ to_read = min (chunksize, nframes_t(_length - current_frame));
if (to_read == 0) {
/* XXX ARGH .. out by one error ... need to figure out why this happens
and fix it rather than do this band-aid move.
*/
zero_fill = npeaks - nvisual_peaks;
+ npeaks -= zero_fill;
break;
}
close (_peakfile);
}
- if (staging) {
- delete [] staging;
- }
-
- if (raw_staging) {
- delete [] raw_staging;
- }
+ delete [] staging;
+ delete [] raw_staging;
#ifdef DEBUG_READ_PEAKS
cerr << "RP DONE\n";
unlink (peakpath.c_str());
}
- if (buf) {
- delete [] buf;
- }
+ delete [] buf;
return ret;
}
}
int
-AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframes_t cnt, bool force, bool intermediate_peaks_ready)
+AudioSource::compute_and_write_peaks (Sample* buf, sframes_t first_frame, nframes_t cnt,
+ bool force, bool intermediate_peaks_ready)
{
return compute_and_write_peaks (buf, first_frame, cnt, force, intermediate_peaks_ready, _FPP);
}
int
-AudioSource::compute_and_write_peaks (Sample* buf, nframes_t first_frame, nframes_t cnt, bool force,
- bool intermediate_peaks_ready, nframes_t fpp)
+AudioSource::compute_and_write_peaks (Sample* buf, sframes_t first_frame, nframes_t cnt,
+ bool force, bool intermediate_peaks_ready, nframes_t fpp)
{
Sample* buf2 = 0;
nframes_t to_do;
out:
delete [] peakbuf;
- if (buf2) {
- delete [] buf2;
- }
+ delete [] buf2;
+
return ret;
}
nframes_t
AudioSource::available_peaks (double zoom_factor) const
{
- off_t end;
-
if (zoom_factor < _FPP) {
- return length(); // peak data will come from the audio file
+ return length(_timeline_position); // peak data will come from the audio file
}
/* peak data comes from peakfile, but the filesize might not represent
but _peak_byte_max only monotonically increases after initialization.
*/
- end = _peak_byte_max;
+ off_t end = _peak_byte_max;
return (end/sizeof(PeakData)) * _FPP;
}
-void
-AudioSource::update_length (nframes_t pos, nframes_t cnt)
-{
- if (pos + cnt > _length) {
- _length = pos+cnt;
- }
-}
-