Changeset 948

Show
Ignore:
Timestamp:
03/16/08 15:13:45 (13 years ago)
Author:
jwoithe
Message:

MOTU: Use fast C99 lrint()/lrintf() for float-int casts in MOTU transmit stream if available. There may be a neater way of detecting the suitability of these in SConstruct but what's there now seems to work.

MOTU: only output the test tone if the debug level is greater than 0.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/config.h.in

    r939 r948  
    3232#define LIBDIR "$LIBDIR" 
    3333#define SHAREDIR "$SHAREDIR" 
     34 
     35/* Define indicating availability of lrint() */ 
     36#define HAVE_LRINT $HAVE_LRINT 
     37 
     38/* Define indicatin availability of lrintf() */ 
     39#define HAVE_LRINTF $HAVE_LRINTF 
    3440 
    3541#define DEBUG_IMPLEMENT_BACKLOG     0 
  • trunk/libffado/SConstruct

    r947 r948  
    33# Copyright (C) 2007 Arnold Krille 
    44# Copyright (C) 2007 Pieter Palmers 
     5# Copyright (C) 2008 Jonathan Woithe 
    56# 
    67# This file is part of FFADO 
     
    208209                Exit( 1 ) 
    209210 
     211        # Check for C99 lrint() and lrintf() functions used to convert from 
     212        # float to integer more efficiently via float_cast.h.  If not 
     213        # present the standard slower methods will be used instead.  This 
     214        # might not be the best way of testing for these but it's the only 
     215        # way which seems to work properly.  CheckFunc() fails due to 
     216        # argument count problems. 
     217        oldcf = env['CFLAGS'] 
     218        oldcf = env.Append(CFLAGS = '-std=c99') 
     219        if conf.CheckLibWithHeader( "m", "math.h", "c", "lrint(3.2);" ): 
     220                HAVE_LRINT = 1 
     221        else: 
     222                HAVE_LRINT = 0 
     223        if conf.CheckLibWithHeader( "m", "math.h", "c", "lrintf(3.2);" ): 
     224                HAVE_LRINTF = 1 
     225        else: 
     226                HAVE_LRINTF = 0 
     227        env['HAVE_LRINT'] = HAVE_LRINT; 
     228        env['HAVE_LRINTF'] = HAVE_LRINTF; 
     229        env.Replace(CFLAGS=oldcf) 
     230 
    210231        # 
    211232        # Optional checks follow: 
  • trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

    r928 r948  
    2525#include "config.h" 
    2626 
     27#include "libutil/float_cast.h" 
     28 
    2729#include "MotuTransmitStreamProcessor.h" 
    2830#include "MotuPort.h" 
     
    3739#include <assert.h> 
    3840 
    39 // Set to 1 to enable the generation of a 1 kHz test tone in analog output 1 
     41// Set to 1 to enable the generation of a 1 kHz test tone in analog output 1.  Even with 
     42// this defined to 1 the test tone will now only be produced if run with a non-zero  
     43// debug level. 
    4044#define TESTTONE 1 
    4145 
     
    268272 
    269273#if TESTTONE 
     274    /* Now things are beginning to stabilise, make things easier for others by only playing 
     275     * the test tone when run with a non-zero debug level. 
     276     */ 
     277    if (getDebugLevel() > 0) { 
    270278        // FIXME: remove this hacked in 1 kHz test signal to 
    271279        // analog-1 when testing is complete. 
    272         signed int i, int_tpf = (int)ticks_per_frame
     280        signed int i, int_tpf = lrintf(ticks_per_frame)
    273281        unsigned char *sample = data+8+16; 
    274282        for (i=0; i<n_events; i++, sample+=m_event_size) { 
     
    277285            // network byte order).  After byte order swap, the 24-bit 
    278286            // MSB is in the second byte of val. 
    279             signed int val = htonl((int)(0x7fffff*sin((1000.0*2.0*M_PI/24576000.0)*a_cx))); 
     287            signed int val = htonl(lrintf(0x7fffff*sin((1000.0*2.0*M_PI/24576000.0)*a_cx))); 
    280288            memcpy(sample,((char *)&val)+1,3); 
    281289            if ((a_cx+=int_tpf) >= 24576000) { 
     
    283291            } 
    284292        } 
     293    } 
    285294#endif 
    286295 
    287296        // Set up each frames's SPH. 
    288297        for (int i=0; i < n_events; i++, quadlet += dbs) { 
    289 //FIXME: not sure which is best for the MOTU.  Should be consistent with generateSilentPacketData(). 
    290 //            int64_t ts_frame = addTicks(ts, (unsigned int)(i * ticks_per_frame)); 
    291             int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)(i * ticks_per_frame)); 
     298            int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)lrintf(i * ticks_per_frame)); 
    292299            *quadlet = htonl(fullTicksToSph(ts_frame)); 
    293300        } 
     
    385392    // Set up each frames's SPH. 
    386393    for (int i=0; i < n_events; i++, quadlet += dbs) { 
    387 //FIXME: not sure which is best for the MOTU.  Should be consistent with generatePacketData(). 
    388 //        int64_t ts_frame = addTicks(ts, (unsigned int)(i * ticks_per_frame)); 
    389         int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)(i * ticks_per_frame)); 
     394        int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)lrintf(i * ticks_per_frame)); 
    390395        *quadlet = htonl(fullTicksToSph(ts_frame)); 
    391396    } 
     
    577582 
    578583                for(j = 0; j < nevents; j += 1) { // decode max nsamples 
    579                     unsigned int v = (int)(*buffer * multiplier); 
     584                    unsigned int v = lrintf(*buffer * multiplier); 
    580585                    *target = (v >> 16) & 0xff; 
    581586                    *(target+1) = (v >> 8) & 0xff;