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