~artfwo/ubuntu/raring/libffado/bug-1105818

« back to all changes in this revision

Viewing changes to src/libstreaming/rme/RmeTransmitStreamProcessor.cpp

  • Committer: Artem Popov
  • Date: 2013-01-26 08:06:17 UTC
  • mfrom: (8.1.11 experimental)
  • Revision ID: artfwo@ubuntu.com-20130126080617-j953b0j3nr2g85l5
* Merge with Debian (LP: #1105818); remaining changes:
  - Build using dh_python2
* Imported Upstream version 2.1.0+svn2240
* Drop all local patches (all integrated upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
295
295
    // Size of a single data frame in quadlets
296
296
//    unsigned dbs = m_event_size / 4;
297
297
 
 
298
    // Flag the successful start of streaming so generateEmptyPacketHeader()
 
299
    // knows that true empty packets are now required.
 
300
    streaming_has_run=1;
 
301
 
298
302
    // The number of events per packet expected by the RME is solely
299
303
    // dependent on the current sample rate.  An 'event' is one sample from
300
304
    // all channels plus possibly other midi and control data.
338
342
                }
339
343
            }
340
344
        }
 
345
#endif
341
346
}
342
 
#endif
343
347
 
344
348
        return eCRV_OK;
345
349
    }
347
351
    {
348
352
        // FIXME: debugOutput() for initial testing only
349
353
        debugOutput(DEBUG_LEVEL_VERBOSE, "readFrames() failure\n");
 
354
        // If there's an xrun, ensure the data doesn't contain junk just
 
355
        // in case it gets sent to the interface.
 
356
        memset(data, 0, *length);
350
357
        return eCRV_XRun;
351
358
    }
352
359
}
372
379
    // sending data to the DACs and sending data from the ADCs) 
373
380
    // packets once it has received a certain amount of data from the PC.
374
381
    // Since the receive stream processor won't register as dry running 
375
 
    // until data is received, we therefore need to send some data during
376
 
    // the dry running state in order to kick the process into gear.
 
382
    // until data is received, we therefore need to send some data while in
 
383
    // the initial states during startup in order to kick the process into
 
384
    // gear.
377
385
    //
378
386
    // Non-empty "empty" packets are not desired during the dry-running
379
 
    // state encountered during closedown, however, so take steps to ensure
380
 
    // they are only sent during the startup sequence.  This logic is
381
 
    // presently a quick and dirty hack and will be revisited in due course
382
 
    // once a final control method has been established.
383
 
    if (streaming_has_run==0 && isDryRunning()) {
 
387
    // state encountered during any other stage (eg: during streaming or
 
388
    // closedown), however, so take steps to ensure they are only sent
 
389
    // during the startup sequence.
 
390
 
 
391
    // Experimentation showed that it was necessary to send "silent" packets
 
392
    // for the duration of the pre-streaming setup.  Otherwise the FF800
 
393
    // especially would give a burst of digital noise out of some or all
 
394
    // outputs during the first FFADO streaming startup following the
 
395
    // powering up of the interface (the duration of the burst was estimated
 
396
    // to be of the order of 250 ms at 48 kHz sampling rate).  Therefore if
 
397
    // streaming has not yet run assume we're in the pre-streaming stages
 
398
    // and send a silent data packet.
 
399
    //
 
400
    // While a single packet was sufficient to get data flowing from the
 
401
    // fireface, the noise bursts would almost always occur in this case.
 
402
    //
 
403
    // Sending during the ePS_DryRunning seemed to reduce the probability
 
404
    // of getting the bursts slightly.
 
405
    //
 
406
    // Sending during the ePS_DryRunning and ePS_WaitingForStreamEnable
 
407
    // states was almost enough to prevent the noise burst: the bursts were
 
408
    // far less frequent and when they did happen they were very short.
 
409
    //
 
410
    // Further notes about the noise burst:
 
411
    //  * it was not due to bad data from readFrames().
 
412
    //  * it seemed to be aligned to the time around the transition to
 
413
    //    the ePS_DryRunning state, although this was never explicitly 
 
414
    //    measured.
 
415
    //  * once streaming had been run once the bursts were very unlikely
 
416
    //    to occur on second and subsequent runs until the Fireface was
 
417
    //    powercycled.  Bursts after the initial run were observed on very
 
418
    //    isolated occasions, but they could have been a side effect of
 
419
    //    testing at the time.
 
420
 
 
421
    if (streaming_has_run == 0) {
384
422
        signed n_events = getNominalFramesPerPacket();
385
 
//        unsigned int cycle = CYCLE_TIMER_GET_CYCLES(pkt_ctr);
386
423
 
387
424
        streaming_has_dryrun = 1;
388
 
        if (streaming_start_count < (1)*n_events) {
389
 
            streaming_start_count += n_events;
390
 
            *length = n_events * m_event_size;
391
 
//            generateSilentPacketData(data, length);
392
 
        }
 
425
 
 
426
        streaming_start_count += n_events;
 
427
        *length = n_events * m_event_size;
393
428
    }
394
429
 
395
 
    if (!isDryRunning() && streaming_has_dryrun==1)
396
 
        streaming_has_run=1;
397
 
 
398
 
//    m_tx_dbc += fillNoDataPacketHeader ( (quadlet_t *)data, length );
399
 
 
400
430
    return eCRV_OK;
401
431
}
402
432
 
436
466
    // no audio data.
437
467
    *sy = 0x00;
438
468
 
439
 
    /* Assume the packet will have audio data.  If it turns out we need an empty packet
440
 
     * the length will be overridden by fillNoDataPacketHeader().
441
 
     */
442
 
    *length = n_events*m_event_size;
 
469
    /* Assume the packet will be empty unless proven otherwise */
 
470
    *length = 0;
443
471
 
444
472
    uint64_t presentation_time;
445
473
    unsigned int presentation_cycle;
466
494
 
467
495
    if (cycles_until_transmit < 0)
468
496
    {
469
 
        if (cycles_until_presentation >= RME_MIN_CYCLES_BEFORE_PRESENTATION)
470
 
        {
471
 
            m_last_timestamp = presentation_time;
472
 
            m_tx_dbc += fillDataPacketHeader((quadlet_t *)data, length, m_last_timestamp);
473
 
            if (m_tx_dbc > 0xff)
474
 
                m_tx_dbc -= 0x100;
475
 
            return eCRV_Packet;
476
 
        }
477
 
        else
478
 
        {
479
 
            return eCRV_XRun;
480
 
        }
 
497
        // At this point we've theoretically missed the cycle at which
 
498
        // the data needs to be transmitted.  Technically, if 
 
499
        // cycles_until_presentation is greater than or equal to 
 
500
        // RME_MIN_CYCLES_BEFORE_PRESENTATION we have an xrun.  However,
 
501
        // since this is a silent packet there's no real harm in indicating
 
502
        // that a silent packet can still be sent; it's not as if a silent
 
503
        // packet consumes data.  Furthermore, due to the fact that
 
504
        // presentation time is estimated from m_last_timestamp it's possible
 
505
        // that any xrun indication here is a false trigger.
 
506
        //
 
507
        // In any case, when silent packets are utilised during shutdown
 
508
        // an eCRV_XRun return is "invalid" (see StreamProcessor, function
 
509
        // getPacket().  Since silent packets are usually used during startup 
 
510
        // and/or shutdown there's little to be gained by flagging xruns; all
 
511
        // they seem to do is prevent an otherwise clean shutdown.
 
512
        m_last_timestamp = presentation_time;
 
513
        m_tx_dbc += fillDataPacketHeader((quadlet_t *)data, length, m_last_timestamp);
 
514
        if (m_tx_dbc > 0xff)
 
515
            m_tx_dbc -= 0x100;
 
516
        return eCRV_Packet;
481
517
    }
482
518
    else if (cycles_until_transmit <= RME_MAX_CYCLES_TO_TRANSMIT_EARLY)
483
519
    {
517
553
    // dependent on the current sample rate.  An 'event' is one sample from
518
554
    // all channels plus possibly other midi and control data.
519
555
    signed n_events = getNominalFramesPerPacket();
 
556
    *length = n_events*m_event_size;
520
557
 
521
558
    return n_events;
522
559
}