#include <set>
+#include <boost/scoped_array.hpp>
#include <glibmm/thread.h>
}
}
-ARDOUR::nframes_t
-AudioRegion::read_peaks (PeakData *buf, nframes_t npeaks, nframes_t offset, nframes_t cnt, uint32_t chan_n, double samples_per_unit) const
+ARDOUR::framecnt_t
+AudioRegion::read_peaks (PeakData *buf, framecnt_t npeaks, framecnt_t offset, framecnt_t cnt, uint32_t chan_n, double samples_per_unit) const
{
if (chan_n >= _sources.size()) {
return 0;
return 0;
} else {
if (_scale_amplitude != 1.0f) {
- for (nframes_t n = 0; n < npeaks; ++n) {
+ for (framecnt_t n = 0; n < npeaks; ++n) {
buf[n].max *= _scale_amplitude;
buf[n].min *= _scale_amplitude;
}
if (_fade_in_active && _session.config.get_use_region_fades()) {
- nframes_t fade_in_length = (nframes_t) _fade_in->back()->when;
+ framecnt_t fade_in_length = (framecnt_t) _fade_in->back()->when;
/* see if this read is within the fade in */
if (internal_offset < fade_in_length) {
- nframes_t fi_limit;
+ framecnt_t fi_limit;
fi_limit = min (to_read, fade_in_length - internal_offset);
-
_fade_in->curve().get_vector (internal_offset, internal_offset+fi_limit, gain_buffer, fi_limit);
- for (nframes_t n = 0; n < fi_limit; ++n) {
+ for (framecnt_t n = 0; n < fi_limit; ++n) {
mixdown_buffer[n] *= gain_buffer[n];
}
}
*/
- nframes_t fade_out_length = (nframes_t) _fade_out->back()->when;
- nframes_t fade_interval_start = max(internal_offset, limit-fade_out_length);
- nframes_t fade_interval_end = min(internal_offset + to_read, limit);
+ framecnt_t fade_out_length = (framecnt_t) _fade_out->back()->when;
+ framecnt_t fade_interval_start = max(internal_offset, limit-fade_out_length);
+ framecnt_t fade_interval_end = min(internal_offset + to_read, limit);
if (fade_interval_end > fade_interval_start) {
/* (part of the) the fade out is in this buffer */
- nframes_t fo_limit = fade_interval_end - fade_interval_start;
- nframes_t curve_offset = fade_interval_start - (limit-fade_out_length);
- nframes_t fade_offset = fade_interval_start - internal_offset;
+ framecnt_t fo_limit = fade_interval_end - fade_interval_start;
+ framecnt_t curve_offset = fade_interval_start - (limit-fade_out_length);
+ framecnt_t fade_offset = fade_interval_start - internal_offset;
_fade_out->curve().get_vector (curve_offset, curve_offset+fo_limit, gain_buffer, fo_limit);
- for (nframes_t n = 0, m = fade_offset; n < fo_limit; ++n, ++m) {
+ for (framecnt_t n = 0, m = fade_offset; n < fo_limit; ++n, ++m) {
mixdown_buffer[m] *= gain_buffer[n];
}
}
_envelope->curve().get_vector (internal_offset, internal_offset + to_read, gain_buffer, to_read);
if ((rops & ReadOpsOwnScaling) && _scale_amplitude != 1.0f) {
- for (nframes_t n = 0; n < to_read; ++n) {
+ for (framecnt_t n = 0; n < to_read; ++n) {
mixdown_buffer[n] *= gain_buffer[n] * _scale_amplitude;
}
} else {
- for (nframes_t n = 0; n < to_read; ++n) {
+ for (framecnt_t n = 0; n < to_read; ++n) {
mixdown_buffer[n] *= gain_buffer[n];
}
}
// XXX this should be using what in 2.0 would have been:
// Session::apply_gain_to_buffer (mixdown_buffer, to_read, _scale_amplitude);
- for (nframes_t n = 0; n < to_read; ++n) {
+ for (framecnt_t n = 0; n < to_read; ++n) {
mixdown_buffer[n] *= _scale_amplitude;
}
}
buf += buf_offset;
- for (nframes_t n = 0; n < to_read; ++n) {
+ for (framecnt_t n = 0; n < to_read; ++n) {
buf[n] += mixdown_buffer[n];
}
}
void
AudioRegion::set_fade_in_shape (FadeShape shape)
{
- set_fade_in (shape, (nframes_t) _fade_in->back()->when);
+ set_fade_in (shape, (framecnt_t) _fade_in->back()->when);
}
void
AudioRegion::set_fade_out_shape (FadeShape shape)
{
- set_fade_out (shape, (nframes_t) _fade_out->back()->when);
+ set_fade_out (shape, (framecnt_t) _fade_out->back()->when);
}
void
AudioRegion::exportme (Session& /*session*/, ARDOUR::ExportSpecification& /*spec*/)
{
// TODO EXPORT
-// const nframes_t blocksize = 4096;
-// nframes_t to_read;
+// const framecnt_t blocksize = 4096;
+// framecnt_t to_read;
// int status = -1;
//
// spec.channels = _sources.size();
// goto out;
// }
//
-// for (nframes_t x = 0; x < to_read; ++x) {
+// for (framecnt_t x = 0; x < to_read; ++x) {
// spec.dataF[chan+(x*spec.channels)] = buf[x];
// }
// }
send_change (PropertyChange (Properties::scale_amplitude));
}
-/** @return the maximum (linear) amplitude of the region */
+/** @return the maximum (linear) amplitude of the region, or a -ve
+ * number if the Progress object reports that the process was cancelled.
+ */
double
AudioRegion::maximum_amplitude (Progress* p) const
{
}
fpos += to_read;
- p->set_progress (float (fpos - _start) / _length);
+ if (p) {
+ p->set_progress (float (fpos - _start) / _length);
+ if (p->cancelled ()) {
+ return -1;
+ }
+ }
}
return maxamp;
*
* @param threshold Threshold below which signal is considered silence (as a sample value)
* @param min_length Minimum length of silent period to be reported.
- * @return Silent periods; first of pair is the offset within the region, second is the length of the period
+ * @return Silent intervals, measured relative to the region start in the source
*/
-std::list<std::pair<frameoffset_t, framecnt_t> >
+AudioIntervalResult
AudioRegion::find_silence (Sample threshold, framecnt_t min_length, InterThreadInfo& itt) const
{
framecnt_t const block_size = 64 * 1024;
- Sample loudest[block_size];
- Sample buf[block_size];
+ boost::scoped_array<Sample> loudest (new Sample[block_size]);
+ boost::scoped_array<Sample> buf (new Sample[block_size]);
framepos_t pos = _start;
framepos_t const end = _start + _length - 1;
-
- std::list<std::pair<frameoffset_t, framecnt_t> > silent_periods;
+
+ AudioIntervalResult silent_periods;
bool in_silence = false;
frameoffset_t silence_start = 0;
while (pos < end && !itt.cancel) {
/* fill `loudest' with the loudest absolute sample at each instant, across all channels */
- memset (loudest, 0, sizeof (Sample) * block_size);
+ memset (loudest.get(), 0, sizeof (Sample) * block_size);
for (uint32_t n = 0; n < n_channels(); ++n) {
- read_raw_internal (buf, pos, block_size, n);
+ read_raw_internal (buf.get(), pos, block_size, n);
for (framecnt_t i = 0; i < block_size; ++i) {
loudest[i] = max (loudest[i], abs (buf[i]));
}