#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/runtime_functions.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"
AudioSource::AudioSource (Session& s, ustring name)
: 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;
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 || ((nframes_t) statbuf.st_size < ((length() / _FPP) * sizeof (PeakData)))) {
+ if (statbuf.st_size == 0 || ((nframes_t) statbuf.st_size < ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) {
// empty
_peaks_built = false;
} else {
}
nframes_t
-AudioSource::read (Sample *dst, sframes_t start, nframes_t cnt, int channel) 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);
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, sframes_t start, nframes_t cnt,
double samples_per_visual_peak, nframes_t samples_per_file_peak) const
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
while (nvisual_peaks < npeaks) {
if (i == frames_read) {
-
+
to_read = min (chunksize, nframes_t(_length - current_frame));
if (to_read == 0) {
and fix it rather than do this band-aid move.
*/
zero_fill = npeaks - nvisual_peaks;
+ npeaks -= zero_fill;
break;
}
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;
}