Changeset 304 for branches

Show
Ignore:
Timestamp:
09/18/06 00:57:30 (18 years ago)
Author:
jwoithe
Message:

Whitespace cleanup.
Improve device sample rate configuration.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libfreebob-2.0/src/motu/motu_avdevice.cpp

    r302 r304  
    170170int  
    171171MotuDevice::getSamplingFrequency( ) { 
    172     /* 
    173      Implement the procedure to retrieve the samplerate here 
    174     */ 
    175     quadlet_t q = ReadRegister(MOTUFW_REG_RATECTRL); 
    176     int rate = 0; 
    177  
    178     switch (q & MOTUFW_RATE_BASE_MASK) { 
    179         case MOTUFW_RATE_BASE_44100: 
    180             rate = 44100; 
    181             break; 
    182         case MOTUFW_RATE_BASE_48000: 
    183             rate = 48000; 
    184             break; 
    185    
    186     switch (q & MOTUFW_RATE_MULTIPLIER_MASK) { 
    187         case MOTUFW_RATE_MULTIPLIER_2X: 
    188             rate *= 2; 
    189             break; 
    190         case MOTUFW_RATE_MULTIPLIER_4X: 
    191             rate *= 4; 
    192             break; 
    193    
    194     return rate; 
     172/* 
     173 * Retrieve the current sample rate from the MOTU device. 
     174 */ 
     175       quadlet_t q = ReadRegister(MOTUFW_REG_CLK_CTRL); 
     176       int rate = 0; 
     177 
     178       switch (q & MOTUFW_RATE_BASE_MASK) { 
     179               case MOTUFW_RATE_BASE_44100: 
     180                       rate = 44100; 
     181                       break; 
     182               case MOTUFW_RATE_BASE_48000: 
     183                       rate = 48000; 
     184                       break; 
     185       
     186       switch (q & MOTUFW_RATE_MULTIPLIER_MASK) { 
     187               case MOTUFW_RATE_MULTIPLIER_2X: 
     188                       rate *= 2; 
     189                       break; 
     190               case MOTUFW_RATE_MULTIPLIER_4X: 
     191                       rate *= 4; 
     192                       break; 
     193       
     194       return rate; 
    195195} 
    196196 
     
    199199{ 
    200200/* 
    201  * Set the device samplerate. 
     201 * Set the MOTU device's samplerate. 
    202202 */ 
    203203        char *src_name; 
    204204        quadlet_t q, new_rate=0; 
    205         int i, supported=true
     205        int i, supported=true, cancel_adat=false
    206206 
    207207        switch ( samplingFrequency ) { 
     
    228228                        break; 
    229229                case eSF_176400Hz: 
    230                         new_rate = MOTUFW_RATE_BASE_44100 | MOTUFW_RATE_MULTIPLIER_4X; 
     230                        // Currently only the Traveler supports 4x sample rates 
     231                        if (m_motu_model == MOTUFW_MODEL_TRAVELER) { 
     232                                new_rate = MOTUFW_RATE_BASE_44100 | MOTUFW_RATE_MULTIPLIER_4X; 
     233                                cancel_adat = true; 
     234                        } else 
     235                                supported=false; 
    231236                        break; 
    232237                case eSF_192000Hz: 
    233                         new_rate = MOTUFW_RATE_BASE_48000 | MOTUFW_RATE_MULTIPLIER_4X; 
     238                        // Currently only the Traveler supports 4x sample rates 
     239                        if (m_motu_model == MOTUFW_MODEL_TRAVELER) { 
     240                                new_rate = MOTUFW_RATE_BASE_48000 | MOTUFW_RATE_MULTIPLIER_4X; 
     241                                cancel_adat = true; 
     242                        } else 
     243                                supported=false; 
    234244                        break; 
    235245                default: 
     
    237247        } 
    238248 
    239         // Update the clock control register.  FIXME: there's more to it than this 
     249        // Update the clock control register.  FIXME: while this is now rather 
     250        // comprehensive there may still be a need to manipulate MOTUFW_REG_CLK_CTRL 
     251        // a little more than we do. 
    240252        if (supported) { 
    241                 quadlet_t value=ReadRegister(MOTUFW_REG_RATECTRL); 
     253                quadlet_t value=ReadRegister(MOTUFW_REG_CLK_CTRL); 
     254 
     255                // If optical port must be disabled (because a 4x sample rate has 
     256                // been selected) then do so before changing the sample rate.  At 
     257                // this stage it will be up to the user to re-enable the optical 
     258                // port if the sample rate is set to a 1x or 2x rate later. 
     259                if (cancel_adat) { 
     260                        setOpticalMode(MOTUFW_DIR_INOUT, MOTUFW_OPTICAL_MODE_OFF); 
     261                } 
     262 
    242263                value &= ~(MOTUFW_RATE_BASE_MASK|MOTUFW_RATE_MULTIPLIER_MASK); 
    243264                value |= new_rate; 
    244 //        value |= 0x04000000; 
    245                 if (WriteRegister(MOTUFW_REG_RATECTRL, value) == 0) { 
     265 
     266                // In other OSes bit 26 of MOTUFW_REG_CLK_CTRL always seems 
     267                // to be set when this register is written to although the 
     268                // reason isn't currently known.  When we set it, it appears 
     269                // to prevent output being produced so we'll leave it unset 
     270                // until we work out what's going on.  Other systems write 
     271                // to MOTUFW_REG_CLK_CTRL multiple times, so that may be 
     272                // part of the mystery. 
     273                //   value |= 0x04000000; 
     274                if (WriteRegister(MOTUFW_REG_CLK_CTRL, value) == 0) { 
    246275                        supported=true; 
    247276                } else { 
     
    259288                                break; 
    260289                        case MOTUFW_CLKSRC_SPDIF_TOSLINK: 
    261                                 src_name = "SPDIF/TOSLink   "; 
     290                                if (getOpticalMode(MOTUFW_DIR_IN)  == MOTUFW_OPTICAL_MODE_TOSLINK) 
     291                                        src_name = "TOSLink         "; 
     292                                else 
     293                                        src_name = "SPDIF           "; 
    262294                                break; 
    263295                        case MOTUFW_CLKSRC_SMTPE: 
     
    286318 
    287319bool MotuDevice::setId( unsigned int id) { 
    288     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %d...\n", id); 
    289     m_id=id; 
    290     return true; 
     320       debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %d...\n", id); 
     321       m_id=id; 
     322       return true; 
    291323} 
    292324 
     
    294326MotuDevice::showDevice() const 
    295327{ 
    296     printf( "MOTU %s at node %d\n"
    297         motufw_modelname[m_motu_model], 
    298         m_nodeId ); 
     328       debugOutput(DEBUG_LEVEL_VERBOSE
     329               "MOTU %s at node %d\n", motufw_modelname[m_motu_model], 
     330               m_nodeId); 
    299331} 
    300332 
     
    303335 
    304336        int samp_freq = getSamplingFrequency(); 
    305         unsigned int optical_mode = getOpticalMode(); 
    306         unsigned int event_size = getEventSize(); 
     337        unsigned int optical_in_mode = getOpticalMode(MOTUFW_DIR_IN); 
     338        unsigned int optical_out_mode = getOpticalMode(MOTUFW_DIR_OUT); 
     339        unsigned int event_size_in = getEventSize(MOTUFW_DIR_IN); 
     340        unsigned int event_size_out= getEventSize(MOTUFW_DIR_OUT); 
    307341 
    308342        raw1394handle_t handle = m_1394Service->getHandle(); 
     
    356390 
    357391        m_receiveProcessor=new FreebobStreaming::MotuReceiveStreamProcessor( 
    358                 m_1394Service->getPort(), samp_freq, event_size); 
    359                                   
     392                m_1394Service->getPort(), samp_freq, event_size_in); 
     393 
    360394        // The first thing is to initialize the processor.  This creates the 
    361395        // data structures. 
     
    374408 
    375409        // Add audio capture ports 
    376         if (!addDirPorts(FreebobStreaming::Port::E_Capture, samp_freq, optical_mode)) { 
     410        if (!addDirPorts(FreebobStreaming::Port::E_Capture, samp_freq, optical_in_mode)) { 
    377411                return false; 
    378412        } 
     
    423457        // Do the same for the transmit processor 
    424458        m_transmitProcessor=new FreebobStreaming::MotuTransmitStreamProcessor( 
    425                 m_1394Service->getPort(), getSamplingFrequency(), event_size); 
     459                m_1394Service->getPort(), getSamplingFrequency(), event_size_out); 
    426460 
    427461        m_transmitProcessor->setVerboseLevel(getDebugLevel()); 
     
    440474 
    441475        // Add audio playback ports 
    442         if (!addDirPorts(FreebobStreaming::Port::E_Playback, samp_freq, optical_mode)) { 
     476        if (!addDirPorts(FreebobStreaming::Port::E_Playback, samp_freq, optical_out_mode)) { 
    443477                return false; 
    444478        } 
     
    600634} 
    601635 
    602 unsigned int MotuDevice::getOpticalMode(void) { 
     636unsigned int MotuDevice::getOpticalMode(unsigned int dir) { 
    603637        unsigned int reg = ReadRegister(MOTUFW_REG_ROUTE_PORT_CONF); 
    604         return reg & MOTUFW_OPTICAL_MODE_MASK; 
    605 
    606  
    607 signed int MotuDevice::setOpticalMode(unsigned int mode) { 
     638 
     639        if (dir == MOTUFW_DIR_IN) 
     640                return (reg & MOTUFW_OPTICAL_IN_MODE_MASK) >> 8; 
     641        else 
     642                return (reg & MOTUFW_OPTICAL_OUT_MODE_MASK) >> 12; 
     643
     644 
     645signed int MotuDevice::setOpticalMode(unsigned int dir, unsigned int mode) { 
    608646        unsigned int reg = ReadRegister(MOTUFW_REG_ROUTE_PORT_CONF); 
    609  
    610         // FIXME: there seems to be more to it than this. 
    611         reg &= ~MOTUFW_OPTICAL_MODE_MASK; 
    612         reg |= mode & MOTUFW_OPTICAL_MODE_MASK; 
    613         return WriteRegister(MOTUFW_REG_ROUTE_PORT_CONF, reg); 
    614 
    615  
    616 signed int MotuDevice::getEventSize(void) { 
     647        unsigned int opt_ctrl = 0x0000002; 
     648 
     649        // Set up the optical control register value according to the current 
     650        // optical port modes.  At this stage it's not completely understood  
     651        // what the "Optical control" register does, so the values its set to 
     652        // are more or less "magic" numbers. 
     653        if (reg & MOTUFW_OPTICAL_IN_MODE_MASK != (MOTUFW_OPTICAL_MODE_ADAT<<8)) 
     654                opt_ctrl |= 0x00000080; 
     655        if (reg & MOTUFW_OPTICAL_OUT_MODE_MASK != (MOTUFW_OPTICAL_MODE_ADAT<<12)) 
     656                opt_ctrl |= 0x00000040; 
     657 
     658        if (mode & MOTUFW_DIR_IN) { 
     659                reg &= ~MOTUFW_OPTICAL_IN_MODE_MASK; 
     660                reg |= (mode << 8) & MOTUFW_OPTICAL_IN_MODE_MASK; 
     661                if (mode != MOTUFW_OPTICAL_MODE_ADAT) 
     662                        opt_ctrl |= 0x00000080; 
     663                else 
     664                        opt_ctrl &= ~0x00000080; 
     665        } 
     666        if (mode & MOTUFW_DIR_OUT) { 
     667                reg &= ~MOTUFW_OPTICAL_OUT_MODE_MASK; 
     668                reg |= (mode <<12) & MOTUFW_OPTICAL_OUT_MODE_MASK; 
     669                if (mode != MOTUFW_OPTICAL_MODE_ADAT) 
     670                        opt_ctrl |= 0x00000040; 
     671                else 
     672                        opt_ctrl &= ~0x00000040; 
     673        } 
     674 
     675        // FIXME: there seems to be more to it than this, but for  
     676        // the moment at least this seems to work. 
     677        WriteRegister(MOTUFW_REG_ROUTE_PORT_CONF, reg); 
     678        return WriteRegister(MOTUFW_REG_OPTICAL_CTRL, opt_ctrl); 
     679
     680 
     681signed int MotuDevice::getEventSize(unsigned int dir) { 
    617682// 
    618 // Return the size of a single event sent by the MOTU as part of an iso 
    619 // data packet in bytes
     683// Return the size in bytes of a single event sent to (dir==MOTUFW_OUT) or 
     684// from (dir==MOTUFW_IN) the MOTU as part of an iso data packet
    620685// 
    621686// FIXME: for performance it may turn out best to calculate the event 
     
    628693// all audio channels are sent using 3 bytes. 
    629694signed int sample_rate = getSamplingFrequency(); 
    630 signed int optical_mode = getOpticalMode(); 
     695signed int optical_mode = getOpticalMode(dir); 
    631696signed int size = 4+6+8*3; 
    632697 
  • branches/libfreebob-2.0/src/motu/motu_avdevice.h

    r302 r304  
    4141#define MOTUFW_RATE_MULTIPLIER_MASK     (0x00000030) 
    4242 
    43 #define MOTUFW_OPTICAL_MODE_OFF         (0<<8) 
    44 #define MOTUFW_OPTICAL_MODE_ADAT        (1<<8) 
    45 #define MOTUFW_OPTICAL_MODE_TOSLINK     (2<<8) 
    46 #define MOTUFW_OPTICAL_MODE_MASK        (0x00000300) 
     43#define MOTUFW_OPTICAL_MODE_OFF         0x00 
     44#define MOTUFW_OPTICAL_MODE_ADAT        0x01 
     45#define MOTUFW_OPTICAL_MODE_TOSLINK     0x02 
     46#define MOTUFW_OPTICAL_IN_MODE_MASK     (0x00000300) 
     47#define MOTUFW_OPTICAL_OUT_MODE_MASK    (0x00003000) 
     48#define MOTUFW_OPTICAL_MODE_MASK        (MOTUFW_OPTICAL_IN_MODE_MASK|MOTUFW_OPTICAL_MODE_MASK) 
    4749 
    4850#define MOTUFW_CLKSRC_MASK              0x00000007 
     
    5557#define MOTUFW_CLKSRC_AES_EBU           7 
    5658 
     59#define MOTUFW_DIR_IN                   1 
     60#define MOTUFW_DIR_OUT                  2 
     61#define MOTUFW_DIR_INOUT                (MOTUFW_DIR_IN | MOTUFW_DIR_OUT) 
     62 
    5763/* Device registers */ 
    5864#define MOTUFW_REG_ISOCTRL              0x0b00 
    59 #define MOTUFW_REG_RATECTRL             0x0b14 
     65#define MOTUFW_REG_OPTICAL_CTRL         0x0b10 
     66#define MOTUFW_REG_CLK_CTRL             0x0b14 
    6067#define MOTUFW_REG_ROUTE_PORT_CONF      0x0c04 
    6168#define MOTUFW_REG_CLKSRC_NAME0         0x0c60 
     
    102109    signed int getIsoRecvChannel(void); 
    103110    signed int getIsoSendChannel(void); 
    104     unsigned int getOpticalMode(void); 
    105     signed int setOpticalMode(unsigned int mode); 
     111    unsigned int getOpticalMode(unsigned int dir); 
     112    signed int setOpticalMode(unsigned int dir, unsigned int mode); 
    106113 
    107     signed int getEventSize(void); 
     114    signed int getEventSize(unsigned int dir); 
    108115   
    109116protected: