Changeset 981

Show
Ignore:
Timestamp:
03/24/08 16:00:49 (13 years ago)
Author:
jwoithe
Message:

config.h.in: reworked MOTU_* constants to get "nearly correct" timestamps in outgoing packets. This makes playback at 2x and 4x samplerates work. More fine-tuning may be needed.

motu_avdevice.cpp: account for different port locations in packet data at 4x rates.

motu_avdevice.cpp: MotuDevice::probe(), MotuDevice::createDevice(): remove commented out references to the ConfigRom? ModelID field; with MOTUs this is useless for differentiating models.

motu_avdevice.cpp: MotuDevice::setOpticalMode(): the 896HD doesn't have an SPDIF/TOSLINK optical mode, so don't try to set it.

RME: implemented first cut at sample rate control. This has about a 50% chance of working as it currently stands.

MOTU: minor whitespace fixes for consistency.

MOTU: start implementation of device status tracking.

Files:

Legend:

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

    r956 r981  
    138138// then used to stamp the packet and determine the transmission 
    139139// time instant. 
    140 #define MOTU_TRANSMIT_TRANSFER_DELAY    (11776U) 
     140//#define MOTU_TRANSMIT_TRANSFER_DELAY    (11776U) 
     141//#define MOTU_TRANSMIT_TRANSFER_DELAY    (3072U) 
     142#define MOTU_TRANSMIT_TRANSFER_DELAY    (0U) 
    141143 
    142144// the absolute minimum number of cycles we want to transmit 
     
    146148// are too late for that, this constant defines how late we can 
    147149// be. 
    148 #define MOTU_MIN_CYCLES_BEFORE_PRESENTATION                1 
     150#define MOTU_MIN_CYCLES_BEFORE_PRESENTATION                0 
    149151 
    150152// the absolute maximum number of cycles we want to transmit 
     
    153155// given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 
    154156// packets early if we want to. 
    155 #define MOTU_MAX_CYCLES_TO_TRANSMIT_EARLY                  6 
     157//#define MOTU_MAX_CYCLES_TO_TRANSMIT_EARLY                  6 
     158#define MOTU_MAX_CYCLES_TO_TRANSMIT_EARLY                  2 
    156159 
    157160// ensure that the MOTU tx SP clips all float values to [-1.0..1.0] 
  • trunk/libffado/src/libstreaming/motu/MotuReceiveStreamProcessor.cpp

    r928 r981  
    7373    : StreamProcessor(parent, ePT_Receive) 
    7474    , m_event_size( event_size ) 
    75 {} 
     75
     76    memset(&m_devctrls, 0, sizeof(m_devctrls)); 
     77
    7678 
    7779unsigned int 
     
    204206{ 
    205207    bool no_problem=true; 
     208 
     209    /* Scan incoming block for device control events */ 
     210    decodeMotuCtrlEvents(data, nevents); 
     211 
    206212    for ( PortVectorIterator it = m_Ports.begin(); 
    207213          it != m_Ports.end(); 
     
    338344} 
    339345 
     346int 
     347MotuReceiveStreamProcessor::decodeMotuCtrlEvents( 
     348                      char *data, unsigned int nevents) 
     349{ 
     350    unsigned int j = 0; 
     351    unsigned char *src = NULL; 
     352    unsigned char *arg = NULL; 
     353 
     354    // Get control bytes if present in any frames within the packet.  The 
     355    // device control messages start at (zero-based) byte 0x04 in the data 
     356    // stream. 
     357    src = (unsigned char *)data + 0x04; 
     358    arg = src+1; 
     359    while (j < nevents) { 
     360         
     361        if (m_devctrls.status == MOTU_DEVCTRL_INVALID) { 
     362            // Start acquiring on reception of a key which we know occurs 
     363            // only once per cycle.  The only potential problem with this is if 
     364            // this key can interrupt a sequence of other keys.  Time will tell 
     365            // whether the assumption that it doesn't is valid. 
     366            if (*src == MOTU_KEY_MAINOUT_VOL) { 
     367                 debugOutput(DEBUG_LEVEL_VERBOSE, "acquiring device control status events\n"); 
     368                 m_devctrls.status = MOTU_DEVCTRL_ACQUIRING; 
     369            } 
     370        } else 
     371        if (m_devctrls.status == MOTU_DEVCTRL_ACQUIRING) { 
     372            // If our "once per cycle" key occurs in the acquiring state we 
     373            // know we've been right through the control event cycle, making 
     374            // our picture of the device status complete.  See note above 
     375            // for the caveats with this logic. 
     376            if (*src == MOTU_KEY_MAINOUT_VOL) { 
     377                debugOutput(DEBUG_LEVEL_VERBOSE, "device control status collection valid\n"); 
     378                m_devctrls.status = MOTU_DEVCTRL_VALID; 
     379            } 
     380        } 
     381 
     382        if (m_devctrls.status != MOTU_DEVCTRL_INVALID) { 
     383            switch (*src) { 
     384                case MOTU_KEY_CHANNEL_GAIN: 
     385                case MOTU_KEY_CHANNEL_PAN: 
     386                case MOTU_KEY_CHANNEL_CTRL: 
     387                case MOTU_KEY_MIXBUS_GAIN: 
     388                case MOTU_KEY_MIXBUS_DEST: 
     389                case MOTU_KEY_MAINOUT_VOL: 
     390                case MOTU_KEY_PHONES_VOL: 
     391                case MOTU_KEY_PHONES_DEST: 
     392                case MOTU_KEY_INPUT_6dB_BOOST: 
     393                case MOTU_KEY_INPUT_REF_LEVEL: 
     394                    break; 
     395                case MOTU_KEY_MIDI: 
     396                    // MIDI is dealt with elsewhere, so just pass it over 
     397                    break; 
     398                default: 
     399                    // Ignore any unknown keys or those we don't care about, at 
     400                    // least for now. 
     401                    break; 
     402            } 
     403        } 
     404        j++; 
     405        src += m_event_size; 
     406        arg += m_event_size; 
     407    } 
     408 
     409    return 0;     
     410} 
     411 
    340412} // end of namespace Streaming 
  • trunk/libffado/src/libstreaming/motu/MotuReceiveStreamProcessor.h

    r873 r981  
    3636 
    3737namespace Streaming { 
     38 
     39#define MOTUFW_MAX_MIXBUSES        4 
     40#define MOTUFW_MAX_MIXBUS_CHANNELS 20 
     41 
     42#define MOTU_CHANNEL_NORMAL        0x00 
     43#define MOTU_CHANNEL_MUTE          0x01 
     44#define MOTU_CHANNEL_SOLO          0x02 
     45#define MOTU_CHANNEL_PAIRED        0x08 
     46 
     47#define MOTU_CHANNEL_PAN_LEFT      0x00 
     48#define MOTU_CHANNEL_PAN_RIGHT     0x80 
     49#define MOTU_CHANNEL_PAN_CENTRE    0x40 
     50 
     51#define MOTU_DEST_DISABLED         0x00 
     52#define MOTU_DEST_HEADPHONE        0x01 
     53#define MOTU_DEST_ANALOG1_2        0x02 
     54#define MOTU_DEST_ANALOG3_4        0x03 
     55#define MOTU_DEST_ANALOG5_6        0x04 
     56#define MOTU_DEST_ANALOG7_8        0x05 
     57#define MOTU_DEST_AESEBU           0x06 
     58#define MOTU_DEST_SPDIF            0x07 
     59#define MOTU_DEST_ADAT1_1_2        0x08 
     60#define MOTU_DEST_ADAT1_3_4        0x09 
     61#define MOTU_DEST_ADAT1_5_6        0x0a 
     62#define MOTU_DEST_ADAT1_7_8        0x0b 
     63#define MOTU_DEST_MUTE             0x10 
     64 
     65enum EMotuDevCtrlStatus { 
     66  MOTU_DEVCTRL_INVALID           = 0x00, 
     67  MOTU_DEVCTRL_ACQUIRING         = 0x01, 
     68  MOTU_DEVCTRL_VALID             = 0x02, 
     69}; 
     70 
     71struct MotuDevControls { 
     72    unsigned int status, lastkey; 
     73    unsigned int input_6dB_boost; 
     74    unsigned int input_ref_level; 
     75    unsigned int input_20dB_pad; 
     76    unsigned int input_gaintrim[MOTUFW_MAX_MIXBUS_CHANNELS]; 
     77    unsigned char input_gaintrim_index; 
     78    struct MixBus { 
     79      unsigned char channel_gain[MOTUFW_MAX_MIXBUS_CHANNELS]; 
     80      unsigned char channel_gain_index; 
     81      unsigned char channel_pan[MOTUFW_MAX_MIXBUS_CHANNELS]; 
     82      unsigned char channel_pan_index; 
     83      unsigned char channel_control[MOTUFW_MAX_MIXBUS_CHANNELS]; 
     84      unsigned char channel_control_index; 
     85      unsigned char bus_gain; 
     86      unsigned char bus_dest; 
     87    } mixbus[MOTUFW_MAX_MIXBUSES]; 
     88    unsigned char mixbus_index; 
     89    unsigned char main_out_volume; 
     90    unsigned char phones_volume; 
     91    unsigned char phones_assign; 
     92}; 
     93 
     94enum EMotuCtrlKeys { 
     95  MOTU_KEY_MIDI            = 0x01, 
     96  MOTU_KEY_CHANNEL_GAIN    = 0x14, 
     97  MOTU_KEY_CHANNEL_PAN     = 0x1c, 
     98  MOTU_KEY_CHANNEL_CTRL    = 0x24, 
     99  MOTU_KEY_MIXBUS_GAIN     = 0x2c, 
     100  MOTU_KEY_MIXBUS_DEST     = 0x34, 
     101  MOTU_KEY_MAINOUT_VOL     = 0x3c, 
     102  MOTU_KEY_PHONES_VOL      = 0x44, 
     103  MOTU_KEY_PHONES_DEST     = 0x4c, 
     104  MOTU_KEY_INPUT_6dB_BOOST = 0x6c, 
     105  MOTU_KEY_INPUT_REF_LEVEL = 0x74, 
     106}; 
    38107 
    39108class MotuAudioPort; 
     
    85154    int decodeMotuEventsToPort(MotuAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); 
    86155    int decodeMotuMidiEventsToPort(MotuMidiPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); 
     156    int decodeMotuCtrlEvents(char *data, unsigned int nevents); 
    87157 
    88158    /* 
     
    91161     */ 
    92162    unsigned int m_event_size; 
     163 
     164    struct MotuDevControls m_devctrls; 
     165 
    93166}; 
    94167 
  • trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

    r952 r981  
    298298#endif 
    299299 
     300//fprintf(stderr,"tx: %d/%d\n", 
     301//  TICKS_TO_CYCLES(fullTicksToSph(m_last_timestamp)), 
     302//  TICKS_TO_OFFSET(fullTicksToSph(m_last_timestamp))); 
    300303        // Set up each frames's SPH. 
     304//fprintf(stderr,"tpf=%f\n", ticks_per_frame); 
    301305        for (int i=0; i < n_events; i++, quadlet += dbs) { 
    302306            int64_t ts_frame = addTicks(m_last_timestamp, (unsigned int)lrintf(i * ticks_per_frame)); 
    303307            *quadlet = htonl(fullTicksToSph(ts_frame)); 
     308//fprintf(stderr,"tx: %d/%d\n", 
     309//  CYCLE_TIMER_GET_CYCLES(fullTicksToSph(ts_frame)), 
     310//  CYCLE_TIMER_GET_OFFSET(fullTicksToSph(ts_frame))); 
    304311        } 
    305312 
  • trunk/libffado/src/motu/motu_avdevice.cpp

    r950 r981  
    149149    {"Phones-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 10}, 
    150150    {"Phones-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 13}, 
    151     {"Analog1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16}, 
    152     {"Analog2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19}, 
    153     {"Analog3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 22}, 
    154     {"Analog4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 25}, 
    155     {"Analog5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 28}, 
    156     {"Analog6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 31}, 
    157     {"Analog7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 34}, 
    158     {"Analog8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 37}, 
     151    {"Analog1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 16}, 
     152    {"Analog1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 10}, 
     153    {"Analog2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 19}, 
     154    {"Analog2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 13}, 
     155    {"Analog3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 22}, 
     156    {"Analog3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 16}, 
     157    {"Analog4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 25}, 
     158    {"Analog4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 19}, 
     159    {"Analog5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 28}, 
     160    {"Analog5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 22}, 
     161    {"Analog6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 31}, 
     162    {"Analog6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 25}, 
     163    {"Analog7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 34}, 
     164    {"Analog7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 28}, 
     165    {"Analog8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 37}, 
     166    {"Analog8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_4x|MOTUFW_PA_OPTICAL_ANY, 31}, 
    159167    {"AES/EBU1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 40}, 
    160168    {"AES/EBU2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 43}, 
     
    255263    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Motu::MotuDevice (NodeID %d)\n", 
    256264                 getConfigRom().getNodeId() ); 
    257  
    258265} 
    259266 
     
    276283{ 
    277284    unsigned int vendorId = configRom.getNodeVendorId(); 
    278 //     unsigned int modelId = configRom.getModelId(); 
    279285    unsigned int unitVersion = configRom.getUnitVersion(); 
    280286    unsigned int unitSpecifierId = configRom.getUnitSpecifierId(); 
     
    285291    { 
    286292        if ( ( supportedDeviceList[i].vendor_id == vendorId ) 
    287 //              && ( supportedDeviceList[i].model_id == modelId ) 
    288293             && ( supportedDeviceList[i].unit_version == unitVersion ) 
    289294             && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId ) 
     
    307312{ 
    308313    unsigned int vendorId = getConfigRom().getNodeVendorId(); 
    309 //     unsigned int modelId = getConfigRom().getModelId(); 
    310314    unsigned int unitVersion = getConfigRom().getUnitVersion(); 
    311315    unsigned int unitSpecifierId = getConfigRom().getUnitSpecifierId(); 
     
    316320    { 
    317321        if ( ( supportedDeviceList[i].vendor_id == vendorId ) 
    318 //              && ( supportedDeviceList[i].model_id == modelId ) 
    319322             && ( supportedDeviceList[i].unit_version == unitVersion ) 
    320323             && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId ) 
     
    817820    unsigned int opt_ctrl = 0x0000002; 
    818821 
     822    /* THe 896HD doesn't have an SPDIF/TOSLINK optical mode, so don't try to 
     823     * set it 
     824     */ 
     825    if (m_motu_model==MOTUFW_MODEL_896HD && mode==MOTUFW_OPTICAL_MODE_TOSLINK) 
     826        return -1; 
     827 
    819828    // Set up the optical control register value according to the current 
    820829    // optical port modes.  At this stage it's not completely understood 
  • trunk/libffado/src/motu/motu_avdevice.h

    r962 r981  
    9191 
    9292enum EMotuModel { 
    93       MOTUFW_MODEL_NONE     = 0x0000, 
    94       MOTUFW_MODEL_828mkII  = 0x0001, 
    95       MOTUFW_MODEL_TRAVELER = 0x0002, 
    96       MOTUFW_MODEL_ULTRALITE= 0x0003, 
    97       MOTUFW_MODEL_8PRE     = 0x0004, 
    98       MOTUFW_MODEL_828MkI   = 0x0005, 
    99       MOTUFW_MODEL_896HD    = 0x0006, 
     93    MOTUFW_MODEL_NONE     = 0x0000, 
     94    MOTUFW_MODEL_828mkII  = 0x0001, 
     95    MOTUFW_MODEL_TRAVELER = 0x0002, 
     96    MOTUFW_MODEL_ULTRALITE= 0x0003, 
     97    MOTUFW_MODEL_8PRE     = 0x0004, 
     98    MOTUFW_MODEL_828MkI   = 0x0005, 
     99    MOTUFW_MODEL_896HD    = 0x0006, 
    100100}; 
    101101 
  • trunk/libffado/src/rme/rme_avdevice.cpp

    r929 r981  
    5656    , m_model( NULL ) 
    5757    , m_rme_model( RME_MODEL_NONE ) 
     58    , m_ddsFreq( -1 ) 
    5859{ 
    5960    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Rme::RmeDevice (NodeID %d)\n", 
     
    124125RmeDevice::getSamplingFrequency( ) { 
    125126/* 
    126  * Retrieve the current sample rate from the RME device. 
     127 * Retrieve the current sample rate from the RME device.  At this stage it 
     128 * seems that the "current rate" can't be retrieved from the device.  Other 
     129 * drivers don't read the DDS control register and there isn't anywhere else 
     130 * where the frequency is sent back to the PC.  Unless we test the DDS 
     131 * control register for readabilty and find it can be read we'll assume it 
     132 * can't and instead cache the DDS frequency. 
     133 * 
     134 * If the device frequency has not been set this function will return -1 
     135 * (the default value of m_ddsFreq). 
    127136 */ 
    128        return 48000
     137    return m_ddsFreq
    129138} 
    130139 
     
    139148{ 
    140149/* 
    141  * Set the RME device's samplerate. 
     150 * Set the RME device's samplerate.  The RME can do sampling frequencies of 
     151 * 32k, 44.1k and 48k along with the corresponding 2x and 4x rates.  
     152 * However, it can also do +/- 4% from any of these "base" frequencies. 
     153 * This makes it a little long-winded to work out whether a given frequency 
     154 * is supported or not. 
    142155 */ 
    143         if (samplingFrequency == 48000) 
    144                 return true; 
    145         return false; 
     156 
     157    /* Work out whether the requested rate is supported */ 
     158    if (!((samplingFrequency >= 32000*0.96 && samplingFrequency <= 32000*1.04) || 
     159        (samplingFrequency >= 44100*0.96 && samplingFrequency <= 44100*1.04) || 
     160        (samplingFrequency >= 48000*0.96 && samplingFrequency <= 48000*1.04) || 
     161        (samplingFrequency >= 64000*0.96 && samplingFrequency <= 64000*1.04) || 
     162        (samplingFrequency >= 88200*0.96 && samplingFrequency <= 88200*1.04) || 
     163        (samplingFrequency >= 96000*0.96 && samplingFrequency <= 96000*1.04) || 
     164        (samplingFrequency >= 128000*0.96 && samplingFrequency <= 128000*1.04) || 
     165        (samplingFrequency >= 176000*0.96 && samplingFrequency <= 176000*1.04) || 
     166        (samplingFrequency >= 192000*0.96 && samplingFrequency <= 192000*1.04))) { 
     167        return false; 
     168    } 
     169     
     170    /* Send the desired frequency to the RME */ 
     171    if (writeRegister(RME_REG_DDS_CONTROL, samplingFrequency) != 0) 
     172      return false; 
     173 
     174    m_ddsFreq = samplingFrequency; 
     175    return true; 
    146176} 
    147177 
     
    213243} 
    214244 
    215 
     245unsigned int  
     246RmeDevice::readRegister(unsigned int reg) { 
     247 
     248    quadlet_t quadlet; 
     249     
     250    quadlet = 0; 
     251    if (get1394Service().read(0xffc0 | getNodeId(), reg, 1, &quadlet) < 0) { 
     252        debugError("Error doing RME read from register 0x%06x\n",reg); 
     253    } 
     254    return ntohl(quadlet); 
     255
     256 
     257signed int 
     258RmeDevice::writeRegister(unsigned int reg, quadlet_t data) { 
     259 
     260    unsigned int err = 0; 
     261    data = htonl(data); 
     262    if (get1394Service().write(0xffc0 | getNodeId(), reg, 1, &data) < 0) { 
     263        err = 1; 
     264        debugError("Error doing RME write to register 0x%06x\n",reg); 
     265    } 
     266//    SleepRelativeUsec(100); 
     267    return (err==0)?0:-1; 
     268
     269                   
     270
  • trunk/libffado/src/rme/rme_avdevice.h

    r929 r981  
    3232 
    3333// #include "libstreaming/rme/RmeStreamProcessor.h" 
     34 
     35/* RME Fireface register definitions */ 
     36#define RME_REG_DDS_CONTROL       0xfc88f000 
    3437 
    3538class ConfigRom; 
     
    8891    virtual bool stopStreamByIndex(int i); 
    8992 
     93    unsigned int readRegister(unsigned int reg); 
     94    signed int writeRegister(unsigned int reg, quadlet_t data); 
     95 
    9096protected: 
    9197    struct VendorModelEntry *m_model; 
    9298    enum ERmeModel m_rme_model; 
     99 
     100    signed int m_ddsFreq; 
    93101}; 
    94102