BWF offset changes from Ben Loftis, hacked by hand into current svn

git-svn-id: svn://localhost/ardour2/trunk@674 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2006-07-10 20:12:48 +00:00
parent 26843b34fd
commit c3b4df9867
9 changed files with 45 additions and 67 deletions

View file

@ -95,7 +95,7 @@ class AudioFileSource : public AudioSource {
static void set_bwf_serial_number (int); static void set_bwf_serial_number (int);
static void set_search_path (string); static void set_search_path (string);
static void set_header_position_offset (jack_nframes_t offset, bool negative); static void set_header_position_offset (jack_nframes_t offset );
static sigc::signal<void> HeaderPositionOffsetChanged; static sigc::signal<void> HeaderPositionOffsetChanged;
@ -107,7 +107,7 @@ class AudioFileSource : public AudioSource {
to cause issues. to cause issues.
*/ */
void handle_header_position_change (); virtual void handle_header_position_change () {}
protected: protected:
@ -141,7 +141,6 @@ class AudioFileSource : public AudioSource {
static char bwf_serial_number[13]; static char bwf_serial_number[13];
static uint64_t header_position_offset; static uint64_t header_position_offset;
static bool header_position_negative;
virtual void set_timeline_position (jack_nframes_t pos); virtual void set_timeline_position (jack_nframes_t pos);
virtual void set_header_timeline_position () = 0; virtual void set_header_timeline_position () = 0;

View file

@ -49,6 +49,8 @@ class DestructiveFileSource : public SndFileSource {
protected: protected:
jack_nframes_t write_unlocked (Sample *src, jack_nframes_t cnt, char * workbuf); jack_nframes_t write_unlocked (Sample *src, jack_nframes_t cnt, char * workbuf);
virtual void handle_header_position_change ();
private: private:
static jack_nframes_t xfade_frames; static jack_nframes_t xfade_frames;
static gain_t* out_coefficient; static gain_t* out_coefficient;

View file

@ -51,8 +51,6 @@ class SndFileSource : public AudioFileSource {
int update_header (jack_nframes_t when, struct tm&, time_t); int update_header (jack_nframes_t when, struct tm&, time_t);
int flush_header (); int flush_header ();
void handle_smpte_offset_change (jack_nframes_t offset, bool negative);
protected: protected:
void set_header_timeline_position (); void set_header_timeline_position ();

View file

@ -56,8 +56,7 @@ string AudioFileSource::peak_dir = "";
string AudioFileSource::search_path; string AudioFileSource::search_path;
sigc::signal<void> AudioFileSource::HeaderPositionOffsetChanged; sigc::signal<void> AudioFileSource::HeaderPositionOffsetChanged;
bool AudioFileSource::header_position_negative; uint64_t AudioFileSource::header_position_offset = 0;
uint64_t AudioFileSource::header_position_offset;
char AudioFileSource::bwf_country_code[3] = "US"; char AudioFileSource::bwf_country_code[3] = "US";
char AudioFileSource::bwf_organization_code[4] = "LAS"; char AudioFileSource::bwf_organization_code[4] = "LAS";
@ -592,25 +591,13 @@ AudioFileSource::set_search_path (string p)
} }
void void
AudioFileSource::set_header_position_offset (jack_nframes_t offset, bool negative) AudioFileSource::set_header_position_offset (jack_nframes_t offset)
{ {
header_position_offset = offset; header_position_offset = offset;
header_position_negative = negative;
HeaderPositionOffsetChanged (); HeaderPositionOffsetChanged ();
} }
void
AudioFileSource::handle_header_position_change ()
{
cerr << _path << " handling header position change " << writable() << endl;
if (writable()) {
set_header_timeline_position ();
flush_header ();
}
}
void void
AudioFileSource::set_timeline_position (jack_nframes_t pos) AudioFileSource::set_timeline_position (jack_nframes_t pos)
{ {

View file

@ -75,6 +75,9 @@ DestructiveFileSource::DestructiveFileSource (string path, SampleFormat samp_for
_capture_start = false; _capture_start = false;
_capture_end = false; _capture_end = false;
file_pos = 0; file_pos = 0;
timeline_position = header_position_offset;
AudioFileSource::HeaderPositionOffsetChanged.connect (mem_fun (*this, &DestructiveFileSource::handle_header_position_change));
} }
DestructiveFileSource::DestructiveFileSource (const XMLNode& node) DestructiveFileSource::DestructiveFileSource (const XMLNode& node)
@ -85,6 +88,9 @@ DestructiveFileSource::DestructiveFileSource (const XMLNode& node)
_capture_start = false; _capture_start = false;
_capture_end = false; _capture_end = false;
file_pos = 0; file_pos = 0;
timeline_position = header_position_offset;
AudioFileSource::HeaderPositionOffsetChanged.connect (mem_fun (*this, &DestructiveFileSource::handle_header_position_change));
} }
DestructiveFileSource::~DestructiveFileSource() DestructiveFileSource::~DestructiveFileSource()
@ -365,9 +371,20 @@ DestructiveFileSource::get_state ()
return node; return node;
} }
void
DestructiveFileSource::handle_header_position_change ()
{
if ( _length != 0 ) {
error << string_compose(_("Filesource: start time is already set for existing file (%1): Cannot change start time."), _path ) << endmsg;
//in the future, pop up a dialog here that allows user to regenerate file with new start offset
} else if (writable()) {
timeline_position = header_position_offset;
set_header_timeline_position (); //this will get flushed if/when the file is recorded to
}
}
void void
DestructiveFileSource::set_timeline_position (jack_nframes_t pos) DestructiveFileSource::set_timeline_position (jack_nframes_t pos)
{ {
/* destructive tracks always start at where our reference frame zero is */ //destructive track timeline postion does not change except at instantion or when header_position_offset (session start) changes
timeline_position = 0;
} }

View file

@ -30,6 +30,7 @@
#include <pbd/xml++.h> #include <pbd/xml++.h>
#include <ardour/location.h> #include <ardour/location.h>
#include <ardour/audiofilesource.h>
#include "i18n.h" #include "i18n.h"
@ -71,6 +72,9 @@ Location::set_start (jack_nframes_t s)
_start = s; _start = s;
_end = s; _end = s;
start_changed(this); /* EMIT SIGNAL */ start_changed(this); /* EMIT SIGNAL */
if ( is_start() ) {
AudioFileSource::set_header_position_offset ( s );
}
} }
return 0; return 0;
} }

View file

@ -32,7 +32,6 @@
#include <ardour/audioengine.h> #include <ardour/audioengine.h>
#include <ardour/session.h> #include <ardour/session.h>
#include <ardour/tempo.h> #include <ardour/tempo.h>
#include <ardour/audiofilesource.h>
#include "i18n.h" #include "i18n.h"
@ -93,8 +92,6 @@ Session::set_smpte_offset (jack_nframes_t off)
_smpte_offset = off; _smpte_offset = off;
last_smpte_valid = false; last_smpte_valid = false;
AudioFileSource::set_header_position_offset (_smpte_offset, _smpte_offset_negative);
SMPTEOffsetChanged (); /* EMIT SIGNAL */ SMPTEOffsetChanged (); /* EMIT SIGNAL */
} }
@ -104,8 +101,6 @@ Session::set_smpte_offset_negative (bool neg)
_smpte_offset_negative = neg; _smpte_offset_negative = neg;
last_smpte_valid = false; last_smpte_valid = false;
AudioFileSource::set_header_position_offset (_smpte_offset, _smpte_offset_negative);
SMPTEOffsetChanged (); /* EMIT SIGNAL */ SMPTEOffsetChanged (); /* EMIT SIGNAL */
} }

View file

@ -156,6 +156,8 @@ SndFileSource::SndFileSource (string idstr, SampleFormat sfmt, HeaderFormat hf,
utsinfo.version); utsinfo.version);
_broadcast_info->version = 1; _broadcast_info->version = 1;
_broadcast_info->time_reference_low = 0;
_broadcast_info->time_reference_high = 0;
/* XXX do something about this field */ /* XXX do something about this field */
@ -183,6 +185,7 @@ SndFileSource::SndFileSource (string idstr, SampleFormat sfmt, HeaderFormat hf,
} }
AudioSourceCreated (this); /* EMIT SIGNAL */ AudioSourceCreated (this); /* EMIT SIGNAL */
} }
void void
@ -241,6 +244,7 @@ SndFileSource::open ()
/* if the file has data but no broadcast info, then clearly, there is no broadcast info */ /* if the file has data but no broadcast info, then clearly, there is no broadcast info */
if (_length) { if (_length) {
error << "SndFileSource: file has no broadcast info" << endmsg;
free (_broadcast_info); free (_broadcast_info);
_broadcast_info = 0; _broadcast_info = 0;
_flags = Flag (_flags & ~Broadcast); _flags = Flag (_flags & ~Broadcast);
@ -254,15 +258,11 @@ SndFileSource::open ()
of the time reference. of the time reference.
*/ */
set_timeline_position (_broadcast_info->time_reference_low); set_timeline_position ( _broadcast_info->time_reference_low );
} }
if (writable()) { if (writable()) {
sf_command (sf, SFC_SET_UPDATE_HEADER_AUTO, 0, SF_FALSE); sf_command (sf, SFC_SET_UPDATE_HEADER_AUTO, 0, SF_FALSE);
/* update header if header offset info changes */
AudioFileSource::HeaderPositionOffsetChanged.connect (mem_fun (*this, &AudioFileSource::handle_header_position_change));
} }
return 0; return 0;
@ -474,7 +474,7 @@ SndFileSource::setup_broadcast_info (jack_nframes_t when, struct tm& now, time_t
now.tm_mon, now.tm_mon,
now.tm_mday); now.tm_mday);
snprintf (_broadcast_info->origination_time, sizeof (_broadcast_info->origination_time), "%02d-%02d-%02d", snprintf (_broadcast_info->origination_time, sizeof (_broadcast_info->origination_time), "%02d:%02d:%02d",
now.tm_hour, now.tm_hour,
now.tm_min, now.tm_min,
now.tm_sec); now.tm_sec);
@ -497,37 +497,12 @@ SndFileSource::setup_broadcast_info (jack_nframes_t when, struct tm& now, time_t
void void
SndFileSource::set_header_timeline_position () SndFileSource::set_header_timeline_position ()
{ {
uint64_t pos;
if (!(_flags & Broadcast)) { if (!(_flags & Broadcast)) {
return; return;
} }
cerr << "timeline pos = " << timeline_position << " offset = " << header_position_offset << endl; _broadcast_info->time_reference_high = (timeline_position >> 32);
_broadcast_info->time_reference_low = (timeline_position & 0xffffffff);
_broadcast_info->time_reference_high = 0;
if (header_position_negative) {
if (ULONG_LONG_MAX - header_position_offset < timeline_position) {
pos = ULONG_LONG_MAX; // impossible
} else {
pos = timeline_position + header_position_offset;
}
} else {
if (timeline_position < header_position_offset) {
pos = 0;
} else {
pos = timeline_position - header_position_offset;
}
}
_broadcast_info->time_reference_high = (pos >> 32);
_broadcast_info->time_reference_low = (pos & 0xffffffff);
cerr << "set binfo pos to " << _broadcast_info->time_reference_high << " + " << _broadcast_info->time_reference_low << endl;
if (sf_command (sf, SFC_SET_BROADCAST_INFO, _broadcast_info, sizeof (*_broadcast_info)) != SF_TRUE) { if (sf_command (sf, SFC_SET_BROADCAST_INFO, _broadcast_info, sizeof (*_broadcast_info)) != SF_TRUE) {
error << string_compose (_("cannot set broadcast info for audio file %1; Dropping broadcast info for this file"), _path) << endmsg; error << string_compose (_("cannot set broadcast info for audio file %1; Dropping broadcast info for this file"), _path) << endmsg;

View file

@ -1065,20 +1065,19 @@ sf_command (SNDFILE *sndfile, int command, void *data, int datasize)
memcpy (data, psf->loop_info, sizeof (SF_LOOP_INFO)) ; memcpy (data, psf->loop_info, sizeof (SF_LOOP_INFO)) ;
return SF_TRUE ; return SF_TRUE ;
case SFC_SET_BROADCAST_INFO : case SFC_SET_BROADCAST_INFO : {
{ int format = psf->sf.format & SF_FORMAT_TYPEMASK ; int format = psf->sf.format & SF_FORMAT_TYPEMASK ;
/* Only WAV supports the BEXT (Broadcast) chunk. */ /* Only WAV supports the BEXT (Broadcast) chunk. */
if (format != SF_FORMAT_WAV && format != SF_FORMAT_WAVEX) if (format != SF_FORMAT_WAV && format != SF_FORMAT_WAVEX)
return SF_FALSE ; return SF_FALSE ;
} ;
/* Can only do this is in SFM_RDWR or SFM_WRITE modes. */ /* Can only do this is in SFM_RDWR or SFM_WRITE modes. */
if (psf->mode == SFM_READ) if (psf->mode == SFM_READ)
return SF_FALSE ; return SF_FALSE ;
/* If data has already been written this must fail. */ /* If data has already been written this must fail. */
if (psf->broadcast_info == NULL && psf->have_written) if (psf->broadcast_info == NULL && psf->have_written)
return SF_FALSE ; return SF_FALSE ;
if (psf->broadcast_info == NULL) if (psf->broadcast_info == NULL)
@ -1089,7 +1088,9 @@ sf_command (SNDFILE *sndfile, int command, void *data, int datasize)
if (psf->auto_header && psf->write_header) if (psf->auto_header && psf->write_header)
psf->write_header (psf, SF_TRUE) ; psf->write_header (psf, SF_TRUE) ;
return SF_TRUE ; return SF_TRUE ;
}
case SFC_GET_BROADCAST_INFO : case SFC_GET_BROADCAST_INFO :
if (datasize != sizeof (SF_BROADCAST_INFO) || data == NULL) if (datasize != sizeof (SF_BROADCAST_INFO) || data == NULL)