LTC generator - reinit on xrun or graph-reorder
[ardour.git] / libs / ardour / session_ltc.cc
1 /*
2   Copyright (C) 2012 Paul Davis
3   Written by Robin Gareus <robin@gareus.org>
4
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "timecode/time.h"
22
23 #include "ardour/audioengine.h"
24 #include "ardour/audio_port.h"
25 #include "ardour/debug.h"
26 #include "ardour/io.h"
27 #include "ardour/session.h"
28 #include "ardour/slave.h"
29
30 #include "i18n.h"
31
32 using namespace std;
33 using namespace ARDOUR;
34 using namespace MIDI;
35 using namespace PBD;
36 using namespace Timecode;
37
38 /* really verbose timing debug */
39 //#define LTC_GEN_FRAMEDBUG
40 //#define LTC_GEN_TXDBUG
41
42 void
43 Session::ltc_tx_initialize()
44 {
45         ltc_enc_tcformat = config.get_timecode_format();
46
47         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX init sr: %1 fps: %2\n", nominal_frame_rate(), timecode_to_frames_per_second(ltc_enc_tcformat)));
48         ltc_encoder = ltc_encoder_create(nominal_frame_rate(),
49                         timecode_to_frames_per_second(ltc_enc_tcformat),
50                         0);
51
52         ltc_encoder_set_bufsize(ltc_encoder, nominal_frame_rate(), 23.0);
53
54         /* buffersize for 1 LTC frame: (1 + sample-rate / fps) bytes
55          * usually returned by ltc_encoder_get_buffersize(encoder)
56          *
57          * since the fps can change and A3's  min fps: 24000/1001 */
58         ltc_enc_buf = (ltcsnd_sample_t*) calloc((nominal_frame_rate() / 23), sizeof(ltcsnd_sample_t));
59         ltc_speed = 0;
60         ltc_tx_reset();
61         Xrun.connect_same_thread (*this, boost::bind (&Session::ltc_tx_reset, this));
62         engine().GraphReordered.connect_same_thread (*this, boost::bind (&Session::ltc_tx_reset, this));
63 }
64
65 void
66 Session::ltc_tx_cleanup()
67 {
68         DEBUG_TRACE (DEBUG::LTC, "LTC TX cleanup\n");
69         if (ltc_enc_buf) free(ltc_enc_buf);
70         ltc_encoder_free(ltc_encoder);
71         ltc_encoder = NULL;
72 }
73
74 void
75 Session::ltc_tx_reset()
76 {
77         DEBUG_TRACE (DEBUG::LTC, "LTC TX reset\n");
78         ltc_enc_pos = -9999; // force re-start
79         ltc_buf_len = 0;
80         ltc_buf_off = 0;
81         ltc_enc_byte = 0;
82         ltc_enc_cnt = 0;
83
84         boost::shared_ptr<Port> ltcport = ltc_output_port();
85         if (ltcport) {
86                 ltcport->get_connected_latency_range(ltc_out_latency, true);
87         }
88 }
89
90 void
91 Session::ltc_tx_recalculate_position()
92 {
93         SMPTETimecode enctc;
94         Timecode::Time a3tc;
95         ltc_encoder_get_timecode(ltc_encoder, &enctc);
96
97         a3tc.hours   = enctc.hours;
98         a3tc.minutes = enctc.mins;
99         a3tc.seconds = enctc.secs;
100         a3tc.frames  = enctc.frame;
101         a3tc.rate = timecode_to_frames_per_second(ltc_enc_tcformat);
102         a3tc.drop = timecode_has_drop_frames(ltc_enc_tcformat);
103
104         Timecode::timecode_to_sample (a3tc, ltc_enc_pos, true, false,
105                 double(frame_rate()),
106                 config.get_subframes_per_frame(),
107                 config.get_timecode_offset_negative(), config.get_timecode_offset()
108                 );
109 }
110
111 void
112 Session::ltc_tx_send_time_code_for_cycle (framepos_t start_frame, framepos_t end_frame,
113                                           double target_speed, double current_speed,
114                                           pframes_t nframes)
115 {
116         assert (nframes > 0);
117
118         Sample *out;
119         pframes_t txf = 0;
120         boost::shared_ptr<Port> ltcport = ltc_output_port();
121
122         Buffer& buf (ltcport->get_buffer (nframes));
123
124         if (!ltc_encoder || !ltc_enc_buf) {
125                 return;
126         }
127
128         SyncSource sync_src = Config->get_sync_source();
129         if (engine().freewheeling() || !Config->get_send_ltc()
130             /* TODO
131              * decide which time-sources we can generated LTC from.
132              * Internal, JACK or sample-synced slaves should be fine.
133              * talk to oofus.
134              *
135              || (config.get_external_sync() && sync_src == LTC)
136              || (config.get_external_sync() && sync_src == MTC)
137             */
138              ||(config.get_external_sync() && sync_src == MIDIClock)
139                 ) {
140                 return;
141         }
142
143         out = dynamic_cast<AudioBuffer*>(&buf)->data ();
144
145         /* range from libltc (38..218) || - 128.0  -> (-90..90) */
146         const float ltcvol = Config->get_ltc_output_volume()/(90.0); // pow(10, db/20.0)/(90.0);
147
148 #if 1
149         /* TODO read layency only on demand -> ::ltc_tx_reset()
150          * this is already prepared.
151          *
152          * ..but first fix jack2 issue with re-computing latency
153          * in the correct order. Until then, querying it in the
154          * process-callback is the only way to get the current value
155          */
156         ltcport->get_connected_latency_range(ltc_out_latency, true);
157 #endif
158         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX %1 to %2 / %3 | lat: %4\n", start_frame, end_frame, nframes, ltc_out_latency.max));
159
160         /* all systems go. Now here's the plan:
161          *
162          *  1) check if fps has changed
163          *  2) check direction of encoding, calc speed, re-sample existing buffer
164          *  3) calculate frame and byte to send aligned to jack-period size
165          *  4) check if it's the frame/byte that is already in the queue
166          *  5) if (4) mismatch, re-calculate offset of LTC frame relative to period size
167          *  6) actual LTC audio output
168          *  6a) send remaining part of already queued frame; break on nframes
169          *  6b) encode new LTC-frame byte
170          *  6c) goto 6a
171          *  7) done
172          */
173
174         // (1) check fps
175         TimecodeFormat cur_timecode = config.get_timecode_format();
176         if (cur_timecode != ltc_enc_tcformat) {
177                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX1: TC format mismatch - reinit sr: %1 fps: %2\n", nominal_frame_rate(), timecode_to_frames_per_second(cur_timecode)));
178                 if (ltc_encoder_reinit(ltc_encoder, nominal_frame_rate(), timecode_to_frames_per_second(cur_timecode), 0)) {
179                         PBD::error << _("LTC encoder: invalid framerate - LTC encoding is disabled for the remainder of this session.") << endmsg;
180                         ltc_tx_cleanup();
181                         return;
182                 }
183                 ltc_enc_tcformat = cur_timecode;
184                 ltc_tx_reset();
185         }
186
187         /* LTC is max. 30 fps */
188         if (timecode_to_frames_per_second(cur_timecode) > 30) {
189                 return;
190         }
191
192         // (2) speed & direction
193
194         /* speed 0 aka transport stopped is interpreted as rolling forward.
195          * keep repeating current frame
196          */
197 #define SIGNUM(a) ( (a) < 0 ? -1 : 1)
198         bool speed_changed = false;
199
200         /* use port latency compensation */
201 #if 1
202         /* The generated timecode is offset by the port-latency,
203          * therefore the offset depends on the direction of transport.
204          */
205         framepos_t cycle_start_frame = (current_speed < 0) ? (start_frame + ltc_out_latency.max) : (start_frame - ltc_out_latency.max);
206 #else
207         /* This comes in handy when testing sync - record output on an A3 track
208          * see also http://tracker.ardour.org/view.php?id=5073
209          */
210         framepos_t cycle_start_frame = start_frame;
211 #endif
212
213         /* cycle-start may become negative due to latency compensation */
214         if (cycle_start_frame < 0) { cycle_start_frame = 0; }
215
216         double new_ltc_speed = double(labs(end_frame - start_frame) * SIGNUM(current_speed)) / double(nframes);
217
218         if (SIGNUM(new_ltc_speed) != SIGNUM (ltc_speed)) {
219                 DEBUG_TRACE (DEBUG::LTC, "LTC TX2: transport changed direction\n");
220                 ltc_tx_reset();
221         }
222
223         if (ltc_speed != new_ltc_speed) {
224                 /* check ./libs/ardour/interpolation.cc  CubicInterpolation::interpolate
225                  * if target_speed != current_speed we should interpolate, too.
226                  *
227                  * However, currency in A3 target_speed == current_speed for each process cycle
228                  * (except for the sign and if target_speed > 8.0).
229                  * Besides, above speed calculation uses the difference (end_frame - start_frame).
230                  * end_frame is calculated from 'frames_moved' which includes the interpolation.
231                  * so we're good.
232                  */
233                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX2: speed change old: %1 cur: %2 tgt: %3 ctd: %4\n", ltc_speed, current_speed, target_speed, fabs(current_speed) - target_speed));
234                 speed_changed = true;
235         }
236
237         if (end_frame == start_frame || fabs(current_speed) < 0.1 ) {
238                 DEBUG_TRACE (DEBUG::LTC, "LTC TX2: transport is not rolling or absolute-speed < 0.1\n");
239                 /* keep repeating current frame
240                  *
241                  * an LTC generator must be able to continue generating LTC when Ardours transport is in stop
242                  * some machines do odd things if LTC goes away:
243                  * e.g. a tape based machine (video or audio), some think they have gone into park if LTC goes away,
244                  * so unspool the tape from the playhead. That might be inconvenient.
245                  * If LTC keeps arriving they remain in a stop position with the tape on the playhead.
246                  */
247                 new_ltc_speed = 0;
248                 if (!Config->get_ltc_send_continuously()) {
249                         ltc_speed = new_ltc_speed;
250                         return;
251                 }
252         }
253
254         if (fabs(new_ltc_speed) > 10.0) {
255                 DEBUG_TRACE (DEBUG::LTC, "LTC TX2: speed is out of bounds.\n");
256                 ltc_tx_reset();
257                 return;
258         }
259
260         if (ltc_speed == 0 && new_ltc_speed != 0) {
261                 DEBUG_TRACE (DEBUG::LTC, "LTC TX2: transport started rolling - reset\n");
262                 ltc_tx_reset();
263         }
264
265         /* the timecode duration corresponding to the samples that are still
266          * in the buffer. Here, the speed of previous cycle is used to calculate
267          * the alignment at the beginning of this cycle later.
268          */
269         double poff = (ltc_buf_len - ltc_buf_off) * ltc_speed;
270
271         if (speed_changed && new_ltc_speed != 0) {
272                 /* we need to re-sample the existing buffer.
273                  * "make space for the en-coder to catch up to the new speed"
274                  *
275                  * since the LTC signal is a rectangular waveform we can simply squeeze it
276                  * by removing samples or duplicating samples /here and there/.
277                  *
278                  * There may be a more elegant way to do this, in fact one could
279                  * simply re-render the buffer using ltc_encoder_encode_byte()
280                  * but that'd require some timecode offset buffer magic,
281                  * which is left for later..
282                  */
283
284                 double oldbuflen = double(ltc_buf_len - ltc_buf_off);
285                 double newbuflen = double(ltc_buf_len - ltc_buf_off) * fabs(ltc_speed / new_ltc_speed);
286
287                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX2: bufOld %1 bufNew %2 | diff %3\n",
288                                         (ltc_buf_len - ltc_buf_off), newbuflen, newbuflen - oldbuflen
289                                         ));
290
291                 double bufrspdiff = rint(newbuflen - oldbuflen);
292
293                 if (abs(bufrspdiff) > newbuflen || abs(bufrspdiff) > oldbuflen) {
294                         DEBUG_TRACE (DEBUG::LTC, "LTC TX2: resampling buffer would destroy information.\n");
295                         ltc_tx_reset();
296                         poff = 0;
297                 } else if (bufrspdiff != 0 && newbuflen > oldbuflen) {
298                         int incnt = 0;
299                         double samples_to_insert = ceil(newbuflen - oldbuflen);
300                         double avg_distance = newbuflen / samples_to_insert;
301                         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX2: resample buffer insert: %1\n", samples_to_insert));
302
303                         for (int rp = ltc_buf_off; rp < ltc_buf_len - 1; ++rp) {
304                                 const int ro = rp - ltc_buf_off;
305                                 if (ro < (incnt*avg_distance)) continue;
306                                 const ltcsnd_sample_t v1 = ltc_enc_buf[rp];
307                                 const ltcsnd_sample_t v2 = ltc_enc_buf[rp+1];
308                                 if (v1 != v2 && ro < ((incnt+1)*avg_distance)) continue;
309                                 memmove(&ltc_enc_buf[rp+1], &ltc_enc_buf[rp], ltc_buf_len-rp);
310                                 incnt++;
311                                 ltc_buf_len++;
312                         }
313                 } else if (bufrspdiff != 0 && newbuflen < oldbuflen) {
314                         double samples_to_remove = ceil(oldbuflen - newbuflen);
315                         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX2: resample buffer - remove: %1\n", samples_to_remove));
316                         if (oldbuflen <= samples_to_remove) {
317                                 ltc_buf_off = ltc_buf_len= 0;
318                         } else {
319                                 double avg_distance = newbuflen / samples_to_remove;
320                                 int rmcnt = 0;
321                                 for (int rp = ltc_buf_off; rp < ltc_buf_len - 1; ++rp) {
322                                         const int ro = rp - ltc_buf_off;
323                                         if (ro < (rmcnt*avg_distance)) continue;
324                                         const ltcsnd_sample_t v1 = ltc_enc_buf[rp];
325                                         const ltcsnd_sample_t v2 = ltc_enc_buf[rp+1];
326                                         if (v1 != v2 && ro < ((rmcnt+1)*avg_distance)) continue;
327                                         memmove(&ltc_enc_buf[rp], &ltc_enc_buf[rp+1], ltc_buf_len-rp-1);
328                                         ltc_buf_len--;
329                                         rmcnt++;
330                                 }
331                         }
332                 }
333         }
334
335         ltc_speed = new_ltc_speed;
336         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX2: transport speed %1.\n", ltc_speed));
337
338         // (3) bit/sample alignment
339         Timecode::Time tc_start;
340         framepos_t tc_sample_start;
341
342         /* calc timecode frame from current position - round down to nearest timecode */
343         sample_to_timecode(cycle_start_frame, tc_start, true, false);
344
345         /* convert timecode back to sample-position */
346         Timecode::timecode_to_sample (tc_start, tc_sample_start, true, false,
347                 double(frame_rate()),
348                 config.get_subframes_per_frame(),
349                 config.get_timecode_offset_negative(), config.get_timecode_offset()
350                 );
351
352         /* difference between current frame and TC frame in samples */
353         frameoffset_t soff = cycle_start_frame - tc_sample_start;
354         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX3: A3cycle: %1 = A3tc: %2 +off: %3\n",
355                                 cycle_start_frame, tc_sample_start, soff));
356
357
358         // (4) check if alignment matches
359         const double fptcf = frames_per_timecode_frame();
360
361         /* maximum difference of bit alignment in audio-samples.
362          *
363          * if transport and LTC generator differs more than this, the LTC
364          * generator will be re-initialized
365          *
366          * due to rounding error and variations in LTC-bit duration depending
367          * on the speed, it can be off by +- ltc_speed audio-samples.
368          * When the playback speed changes, it can actually reach +- 2 * ltc_speed
369          * in the cycle _after_ the speed changed. The average delta however is 0.
370          */
371         double maxdiff;
372
373         if (config.get_external_sync() && slave()) {
374                 maxdiff = slave()->resolution();
375         } else {
376                 maxdiff = ceil(fabs(ltc_speed))*2.0;
377         }
378
379         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX4: enc: %1 + %2 - %3 || buf-bytes: %4 enc-byte: %5\n",
380                                 ltc_enc_pos, ltc_enc_cnt, poff, (ltc_buf_len - ltc_buf_off), poff, ltc_enc_byte));
381
382         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX4: enc-pos: %1  | d: %2\n",
383                                 ltc_enc_pos + ltc_enc_cnt - poff,
384                                 rint(ltc_enc_pos + ltc_enc_cnt - poff) - cycle_start_frame
385                                 ));
386
387         if (ltc_speed != 0 && fabs(ceil(ltc_enc_pos + ltc_enc_cnt - poff) - cycle_start_frame) > maxdiff) {
388
389                 // (5) re-align
390                 ltc_tx_reset();
391
392                 /* set frame to encode */
393                 SMPTETimecode tc;
394                 tc.hours = tc_start.hours;
395                 tc.mins = tc_start.minutes;
396                 tc.secs = tc_start.seconds;
397                 tc.frame = tc_start.frames;
398                 ltc_encoder_set_timecode(ltc_encoder, &tc);
399
400                 /* workaround for libltc recognizing 29.97 and 30000/1001 as drop-frame TC.
401                  * In A3 30000/1001 or 30 fps can be drop-frame.
402                  */
403                 LTCFrame ltcframe;
404                 ltc_encoder_get_frame(ltc_encoder, &ltcframe);
405                 ltcframe.dfbit = timecode_has_drop_frames(cur_timecode)?1:0;
406                 ltc_encoder_set_frame(ltc_encoder, &ltcframe);
407
408
409                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX4: now: %1 trs: %2 toff %3\n", cycle_start_frame, tc_sample_start, soff));
410
411                 uint32_t cyc_off;
412                 if (soff < 0 || soff >= fptcf) {
413                         /* session framerate change between (2) and now */
414                         ltc_tx_reset();
415                         return;
416                 }
417
418                 if (ltc_speed < 0 ) {
419                         /* calculate the byte that starts at or after the current position */
420                         ltc_enc_byte = floor((10.0 * soff) / (fptcf));
421                         ltc_enc_cnt = double(ltc_enc_byte * fptcf / 10.0);
422
423                         /* calculate difference between the current position and the byte to send */
424                         cyc_off = soff- ceil(ltc_enc_cnt);
425
426                 } else {
427                         /* calculate the byte that starts at or after the current position */
428                         ltc_enc_byte = ceil((10.0 * soff) / fptcf);
429                         ltc_enc_cnt = double(ltc_enc_byte * fptcf / 10.0);
430
431                         /* calculate difference between the current position and the byte to send */
432                         cyc_off = ceil(ltc_enc_cnt) - soff;
433
434                         if (ltc_enc_byte == 10) {
435                                 ltc_enc_byte = 0;
436                                 ltc_encoder_inc_timecode(ltc_encoder);
437                         }
438                 }
439
440                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX5 restart encoder: soff %1 byte %2 cycoff %3\n",
441                                         soff, ltc_enc_byte, cyc_off));
442
443                 if (cyc_off > 0 && cyc_off <= nframes) {
444                         /* offset in this cycle */
445                         txf= rint(cyc_off / fabs(ltc_speed));
446                         memset(out, 0, cyc_off * sizeof(Sample));
447                 } else {
448                         /* resync next cycle */
449                         memset(out, 0, nframes * sizeof(Sample));
450                         return;
451                 }
452
453                 ltc_enc_pos = tc_sample_start;
454
455                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX5 restart @ %1 + %2 - %3 |  byte %4\n",
456                                         ltc_enc_pos, ltc_enc_cnt, cyc_off, ltc_enc_byte));
457         }
458
459
460         // (6) encode and output
461         while (1) {
462 #ifdef LTC_GEN_TXDBUG
463                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.1 @%1  [ %2 / %3 ]\n", txf, ltc_buf_off, ltc_buf_len));
464 #endif
465                 // (6a) send remaining buffer
466                 while ((ltc_buf_off < ltc_buf_len) && (txf < nframes)) {
467                         const float v1 = ltc_enc_buf[ltc_buf_off++] - 128.0;
468                         const Sample val = (Sample) (v1*ltcvol);
469                         out[txf++] = val;
470                 }
471 #ifdef LTC_GEN_TXDBUG
472                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.2 @%1  [ %2 / %3 ]\n", txf, ltc_buf_off, ltc_buf_len));
473 #endif
474
475                 if (txf >= nframes) {
476                         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX7 enc: %1 [ %2 / %3 ] byte: %4 spd %5 fpp %6 || nf: %7\n",
477                                                 ltc_enc_pos, ltc_buf_off, ltc_buf_len, ltc_enc_byte, ltc_speed, nframes, txf));
478                         break;
479                 }
480
481                 ltc_buf_len = 0;
482                 ltc_buf_off = 0;
483
484                 // (6b) encode LTC, bump timecode
485
486                 if (ltc_speed < 0) {
487                         ltc_enc_byte = (ltc_enc_byte + 9)%10;
488                         if (ltc_enc_byte == 9) {
489                                 ltc_encoder_dec_timecode(ltc_encoder);
490                                 ltc_tx_recalculate_position();
491                                 ltc_enc_cnt = fptcf;
492                         }
493                 }
494
495                 if (ltc_encoder_encode_byte(ltc_encoder, ltc_enc_byte, (ltc_speed==0)?1.0:(1.0/ltc_speed))) {
496                         DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.3 encoder error byte %1\n", ltc_enc_byte));
497                         ltc_encoder_buffer_flush(ltc_encoder);
498                         ltc_tx_reset();
499                         return;
500                 }
501                 int enc_frames = ltc_encoder_get_buffer(ltc_encoder, &(ltc_enc_buf[ltc_buf_len]));
502 #ifdef LTC_GEN_FRAMEDBUG
503                 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));
504 #endif
505                 if (enc_frames <=0) {
506                         DEBUG_TRACE (DEBUG::LTC, "LTC TX6.3 encoder empty buffer.\n");
507                         ltc_encoder_buffer_flush(ltc_encoder);
508                         ltc_tx_reset();
509                         return;
510                 }
511
512                 ltc_buf_len += enc_frames;
513                 if (ltc_speed < 0)
514                         ltc_enc_cnt -= fptcf/10.0;
515                 else
516                         ltc_enc_cnt += fptcf/10.0;
517
518                 if (ltc_speed >= 0) {
519                         ltc_enc_byte = (ltc_enc_byte + 1)%10;
520                         if (ltc_enc_byte == 0 && ltc_speed != 0) {
521                                 ltc_encoder_inc_timecode(ltc_encoder);
522                                 ltc_tx_recalculate_position();
523                                 ltc_enc_cnt = 0;
524                         } else if (ltc_enc_byte == 0) {
525                                 ltc_enc_cnt = 0;
526                         }
527                 }
528 #ifdef LTC_GEN_FRAMEDBUG
529                 DEBUG_TRACE (DEBUG::LTC, string_compose("LTC TX6.4 enc-pos: %1 + %2 [ %4 / %5 ] spd %6\n", ltc_enc_pos, ltc_enc_cnt, ltc_buf_off, ltc_buf_len, ltc_speed));
530 #endif
531         }
532
533         dynamic_cast<AudioBuffer*>(&buf)->set_written (true);
534         return;
535 }