- Timestamp:
- 09/18/06 00:57:30 (17 years ago)
- Files:
-
- branches/libfreebob-2.0/src/motu/motu_avdevice.cpp (modified) (14 diffs)
- branches/libfreebob-2.0/src/motu/motu_avdevice.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libfreebob-2.0/src/motu/motu_avdevice.cpp
r302 r304 170 170 int 171 171 MotuDevice::getSamplingFrequency( ) { 172 173 Implement the procedure to retrieve the samplerate here174 175 quadlet_t q = ReadRegister(MOTUFW_REG_RATECTRL);176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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; 195 195 } 196 196 … … 199 199 { 200 200 /* 201 * Set the devicesamplerate.201 * Set the MOTU device's samplerate. 202 202 */ 203 203 char *src_name; 204 204 quadlet_t q, new_rate=0; 205 int i, supported=true ;205 int i, supported=true, cancel_adat=false; 206 206 207 207 switch ( samplingFrequency ) { … … 228 228 break; 229 229 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; 231 236 break; 232 237 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; 234 244 break; 235 245 default: … … 237 247 } 238 248 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. 240 252 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 242 263 value &= ~(MOTUFW_RATE_BASE_MASK|MOTUFW_RATE_MULTIPLIER_MASK); 243 264 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) { 246 275 supported=true; 247 276 } else { … … 259 288 break; 260 289 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 "; 262 294 break; 263 295 case MOTUFW_CLKSRC_SMTPE: … … 286 318 287 319 bool MotuDevice::setId( unsigned int id) { 288 289 290 320 debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %d...\n", id); 321 m_id=id; 322 return true; 291 323 } 292 324 … … 294 326 MotuDevice::showDevice() const 295 327 { 296 printf( "MOTU %s at node %d\n",297 298 m_nodeId);328 debugOutput(DEBUG_LEVEL_VERBOSE, 329 "MOTU %s at node %d\n", motufw_modelname[m_motu_model], 330 m_nodeId); 299 331 } 300 332 … … 303 335 304 336 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); 307 341 308 342 raw1394handle_t handle = m_1394Service->getHandle(); … … 356 390 357 391 m_receiveProcessor=new FreebobStreaming::MotuReceiveStreamProcessor( 358 m_1394Service->getPort(), samp_freq, event_size );359 392 m_1394Service->getPort(), samp_freq, event_size_in); 393 360 394 // The first thing is to initialize the processor. This creates the 361 395 // data structures. … … 374 408 375 409 // 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)) { 377 411 return false; 378 412 } … … 423 457 // Do the same for the transmit processor 424 458 m_transmitProcessor=new FreebobStreaming::MotuTransmitStreamProcessor( 425 m_1394Service->getPort(), getSamplingFrequency(), event_size );459 m_1394Service->getPort(), getSamplingFrequency(), event_size_out); 426 460 427 461 m_transmitProcessor->setVerboseLevel(getDebugLevel()); … … 440 474 441 475 // 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)) { 443 477 return false; 444 478 } … … 600 634 } 601 635 602 unsigned int MotuDevice::getOpticalMode( void) {636 unsigned int MotuDevice::getOpticalMode(unsigned int dir) { 603 637 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 645 signed int MotuDevice::setOpticalMode(unsigned int dir, unsigned int mode) { 608 646 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 681 signed int MotuDevice::getEventSize(unsigned int dir) { 617 682 // 618 // Return the size of a single event sent by the MOTU as part of an iso619 // 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. 620 685 // 621 686 // FIXME: for performance it may turn out best to calculate the event … … 628 693 // all audio channels are sent using 3 bytes. 629 694 signed int sample_rate = getSamplingFrequency(); 630 signed int optical_mode = getOpticalMode( );695 signed int optical_mode = getOpticalMode(dir); 631 696 signed int size = 4+6+8*3; 632 697 branches/libfreebob-2.0/src/motu/motu_avdevice.h
r302 r304 41 41 #define MOTUFW_RATE_MULTIPLIER_MASK (0x00000030) 42 42 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) 47 49 48 50 #define MOTUFW_CLKSRC_MASK 0x00000007 … … 55 57 #define MOTUFW_CLKSRC_AES_EBU 7 56 58 59 #define MOTUFW_DIR_IN 1 60 #define MOTUFW_DIR_OUT 2 61 #define MOTUFW_DIR_INOUT (MOTUFW_DIR_IN | MOTUFW_DIR_OUT) 62 57 63 /* Device registers */ 58 64 #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 60 67 #define MOTUFW_REG_ROUTE_PORT_CONF 0x0c04 61 68 #define MOTUFW_REG_CLKSRC_NAME0 0x0c60 … … 102 109 signed int getIsoRecvChannel(void); 103 110 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); 106 113 107 signed int getEventSize( void);114 signed int getEventSize(unsigned int dir); 108 115 109 116 protected: