no-read-past-end for destructive crossfade as well; cleanup xfade coefficient arrays in destructor

git-svn-id: svn://localhost/trunk/ardour2@338 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2006-02-17 16:19:17 +00:00
parent 463b5daed0
commit 069d54a008

View file

@ -96,6 +96,8 @@ DestructiveFileSource::DestructiveFileSource (const XMLNode& node, jack_nframes_
DestructiveFileSource::~DestructiveFileSource()
{
delete [] out_coefficient;
delete [] in_coefficient;
delete xfade_buf;
}
@ -148,8 +150,9 @@ DestructiveFileSource::crossfade (Sample* data, jack_nframes_t cnt, int fade_in,
jack_nframes_t xfade = min (xfade_frames, cnt);
jack_nframes_t nofade = cnt - xfade;
Sample* fade_data = 0;
off_t fade_position = 0; // in frames
jack_nframes_t fade_position = 0; // in frames
ssize_t retval;
jack_nframes_t file_cnt;
if (fade_in) {
fade_position = file_pos;
@ -159,6 +162,26 @@ DestructiveFileSource::crossfade (Sample* data, jack_nframes_t cnt, int fade_in,
fade_data = data + nofade;
}
if (fade_position > _length) {
/* read starts beyond end of data, just memset to zero */
file_cnt = 0;
} else if (fade_position + xfade > _length) {
/* read ends beyond end of data, read some, memset the rest */
file_cnt = _length - fade_position;
} else {
/* read is entirely within data */
file_cnt = xfade;
}
if (file_cnt) {
if ((retval = file_read (xfade_buf, fade_position, xfade, workbuf)) != (ssize_t) xfade) {
if (retval >= 0 && errno == EAGAIN) {
/* XXX - can we really trust that errno is meaningful here? yes POSIX, i'm talking to you.
@ -169,6 +192,12 @@ DestructiveFileSource::crossfade (Sample* data, jack_nframes_t cnt, int fade_in,
return 0;
}
}
}
if (file_cnt != xfade) {
jack_nframes_t delta = xfade - file_cnt;
memset (xfade_buf+file_cnt, 0, sizeof (Sample) * delta);
}
if (nofade && !fade_in) {
cerr << "write " << nofade << " frames of prefade OUT data to " << file_pos << " .. " << file_pos + nofade << endl;