LTC encoder: fix signal polarity

git-svn-id: svn://localhost/ardour2/branches/3.0@13403 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Robin Gareus 2012-11-09 07:48:04 +00:00
parent 9d4974ede9
commit 838a8a0137
2 changed files with 27 additions and 8 deletions

View File

@ -1201,6 +1201,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
framepos_t ltc_enc_pos;
double ltc_enc_cnt;
framepos_t ltc_enc_off;
bool restarting;
jack_latency_range_t ltc_out_latency;

View File

@ -81,6 +81,7 @@ Session::ltc_tx_initialize()
ltc_tx_resync_latency();
Xrun.connect_same_thread (*this, boost::bind (&Session::ltc_tx_reset, this));
engine().GraphReordered.connect_same_thread (*this, boost::bind (&Session::ltc_tx_resync_latency, this));
restarting = false;
}
void
@ -136,6 +137,7 @@ Session::ltc_tx_recalculate_position()
config.get_subframes_per_frame(),
config.get_timecode_offset_negative(), config.get_timecode_offset()
);
restarting = false;
}
void
@ -466,6 +468,10 @@ Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end
DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX5 restart encoder: soff %1 byte %2 cycoff %3\n",
soff, ltc_enc_byte, cyc_off));
if ( (ltc_speed < 0 && ltc_enc_byte !=9 ) || (ltc_speed >= 0 && ltc_enc_byte !=0 ) ) {
restarting = true;
}
if (cyc_off > 0 && cyc_off <= nframes) {
/* offset in this cycle */
txf= rint(cyc_off / fabs(ltc_speed));
@ -485,11 +491,11 @@ Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end
/* reduce (low freq) jitter.
* The granularity of the LTC encoder speed is 1 byte =
* (frames-per-timecode-frame / 10) audio-samples.
* Thus, tiny speed changes [as produced by the slave]
* Thus, tiny speed changes [as produced by some slaves]
* may not have any effect in the cycle when they occur,
* but they will add up over time.
*
* This is a linear approx to compensate for this drift
* This is a linear approx to compensate for this jitter
* and prempt re-sync when the drift builds up.
*
* However, for very fast speeds - when 1 LTC bit is
@ -538,13 +544,24 @@ Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end
}
}
if (ltc_encoder_encode_byte(ltc_encoder, ltc_enc_byte, (ltc_speed==0)?1.0:(1.0/ltc_speed))) {
DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.3 encoder error byte %1\n", ltc_enc_byte));
ltc_encoder_buffer_flush(ltc_encoder);
ltc_tx_reset();
return;
int enc_frames;
if (restarting) {
/* write zero bytes -- don't touch encoder until we're at a frame-boundary
* otherwise the biphase polarity may be inverted.
*/
enc_frames = fptcf / 10.0;
memset(&ltc_enc_buf[ltc_buf_len], 127, enc_frames * sizeof(ltcsnd_sample_t));
} else {
if (ltc_encoder_encode_byte(ltc_encoder, ltc_enc_byte, (ltc_speed==0)?1.0:(1.0/ltc_speed))) {
DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.3 encoder error byte %1\n", ltc_enc_byte));
ltc_encoder_buffer_flush(ltc_encoder);
ltc_tx_reset();
return;
}
enc_frames = ltc_encoder_get_buffer(ltc_encoder, &(ltc_enc_buf[ltc_buf_len]));
}
int enc_frames = ltc_encoder_get_buffer(ltc_encoder, &(ltc_enc_buf[ltc_buf_len]));
#ifdef LTC_GEN_FRAMEDBUG
DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.3 encoded %1 bytes for LTC-byte %2 at spd %3\n", enc_frames, ltc_enc_byte, ltc_speed));
#endif
@ -575,6 +592,7 @@ Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end
ltc_enc_cnt = 0;
} else if (ltc_enc_byte == 0) {
ltc_enc_cnt = 0;
restarting=false;
}
}
#ifdef LTC_GEN_FRAMEDBUG