#include <pbd/error.h>
#include <ardour/destructive_filesource.h>
+#include <ardour/utils.h>
#include "i18n.h"
gain_t* DestructiveFileSource::in_coefficient = 0;
jack_nframes_t DestructiveFileSource::xfade_frames = 64;
-DestructiveFileSource::DestructiveFileSource (string path, SampleFormat samp_format, HeaderFormat hdr_format, jack_nframes_t rate, Flag flags)
- : SndFileSource (path, samp_format, hdr_format, rate, flags)
+DestructiveFileSource::DestructiveFileSource (Session& s, string path, SampleFormat samp_format, HeaderFormat hdr_format, jack_nframes_t rate, Flag flags)
+ : SndFileSource (s, path, samp_format, hdr_format, rate, flags)
{
init ();
}
-DestructiveFileSource::DestructiveFileSource (string path, Flag flags)
- : SndFileSource (path, flags)
+DestructiveFileSource::DestructiveFileSource (Session& s, string path, Flag flags)
+ : SndFileSource (s, path, flags)
{
init ();
}
-DestructiveFileSource::DestructiveFileSource (const XMLNode& node)
- : SndFileSource (node)
+DestructiveFileSource::DestructiveFileSource (Session& s, const XMLNode& node)
+ : SndFileSource (s, node)
{
init ();
}
out_coefficient = new gain_t[xfade_frames];
in_coefficient = new gain_t[xfade_frames];
- for (jack_nframes_t n = 0; n < xfade_frames; ++n) {
-
- /* XXXX THIS IS NOT THE RIGHT XFADE CURVE: USE A PROPER VOLUMETRIC EQUAL POWER CURVE */
-
- in_coefficient[n] = n/(gain_t) (xfade_frames-1); /* 0 .. 1 */
- out_coefficient[n] = 1.0 - in_coefficient[n]; /* 1 .. 0 */
- }
+ compute_equal_power_fades (xfade_frames, in_coefficient, out_coefficient);
}
void
}
if (file_cnt) {
- if ((retval = write_float (xfade_buf, fade_position, file_cnt)) != (ssize_t) file_cnt) {
+ if ((retval = read_unlocked (xfade_buf, fade_position, file_cnt)) != (ssize_t) file_cnt) {
if (retval >= 0 && errno == EAGAIN) {
/* XXX - can we really trust that errno is meaningful here? yes POSIX, i'm talking to you.
* short or no data there */
}
if (nofade && !fade_in) {
- if (write_float (data, file_pos, nofade) != nofade) {
+ if (write_float (data, file_pos - timeline_position, nofade) != nofade) {
error << string_compose(_("DestructiveFileSource: \"%1\" bad write (%2)"), _path, strerror (errno)) << endmsg;
return 0;
}
} else if (xfade) {
+ gain_t in[xfade];
+ gain_t out[xfade];
+
/* short xfade, compute custom curve */
- /* XXX COMPUTE THE CURVE, DAMMIT! */
+ compute_equal_power_fades (xfade, in, out);
for (jack_nframes_t n = 0; n < xfade; ++n) {
- xfade_buf[n] = (xfade_buf[n] * out_coefficient[n]) + (fade_data[n] * in_coefficient[n]);
+ xfade_buf[n] = (xfade_buf[n] * out[n]) + (fade_data[n] * in[n]);
}
}
if (xfade) {
- if (write_float (xfade_buf, fade_position, xfade) != xfade) {
+ if (write_float (xfade_buf, fade_position - timeline_position, xfade) != xfade) {
error << string_compose(_("DestructiveFileSource: \"%1\" bad write (%2)"), _path, strerror (errno)) << endmsg;
return 0;
}
}
if (fade_in && nofade) {
- if (write_float (data + xfade, file_pos + xfade, nofade) != nofade) {
+ if (write_float (data + xfade, file_pos + xfade - timeline_position, nofade) != nofade) {
error << string_compose(_("DestructiveFileSource: \"%1\" bad write (%2)"), _path, strerror (errno)) << endmsg;
return 0;
}
/* in the middle of recording */
- if (write_float (data, file_pos, cnt) != cnt) {
+ if (write_float (data, file_pos - timeline_position, cnt) != cnt) {
return 0;
}
}