Changeset 274
- Timestamp:
- 06/25/06 18:45:12 (17 years ago)
- Files:
-
- branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp (modified) (11 diffs)
- branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h (modified) (2 diffs)
- branches/libfreebob-2.0/src/motu/motu_avdevice.cpp (modified) (7 diffs)
- branches/libfreebob-2.0/tests/streaming/teststreaming2.c (modified) (5 diffs)
- branches/libfreebob-2.0/tests/streaming/teststreaming3.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp
r272 r274 912 912 unsigned int bytes2read = m_period * m_event_size; 913 913 914 // FIXME: remove once the stuff below has been tweaked for the MOTU915 //return true;916 917 914 /* Read events2read bytes from the ringbuffer. 918 915 * First see if it can be done in one read. If so, ok. … … 968 965 969 966 if(xrun<0) { 970 967 // xrun detected 971 968 debugError("RCV: Frame buffer overrun in processor %p\n",this); 972 969 break; … … 994 991 for ( PortVectorIterator it = m_PeriodPorts.begin(); 995 992 it != m_PeriodPorts.end(); 996 ++it ) 997 { 998 999 if((*it)->isDisabled()) {continue;}; 993 ++it ) { 994 if((*it)->isDisabled()) {continue;}; 1000 995 1001 996 //FIXME: make this into a static_cast when not DEBUG? 1002 1003 MotuPortInfo *pinfo=dynamic_cast<MotuPortInfo *>(*it); 1004 assert(pinfo); // this should not fail!! 997 Port *port=dynamic_cast<Port *>(*it); 1005 998 1006 /* AMDTP, left as reference 1007 switch(pinfo->getFormat()) { 999 switch(port->getPortType()) { 1008 1000 1009 case MotuPortInfo::E_MBLA:1001 case Port::E_Audio: 1010 1002 if(decodeMBLAEventsToPort(static_cast<MotuAudioPort *>(*it), (quadlet_t *)data, offset, nevents)) { 1011 1003 debugWarning("Could not decode packet MBLA to port %s",(*it)->getName().c_str()); … … 1013 1005 } 1014 1006 break; 1015 case MotuPortInfo::E_SPDIF: // still unimplemented 1016 break; 1017 // midi is a packet based port, don't process 1018 // case MotuPortInfo::E_Midi: 1019 // break; 1007 // midi is a packet based port, don't process 1008 // case MotuPortInfo::E_Midi: 1009 // break; 1020 1010 1021 1011 default: // ignore 1022 1012 break; 1023 1013 } 1024 */ 1025 } 1014 } 1026 1015 return problem; 1027 1028 1016 } 1029 1017 … … 1044 1032 1045 1033 for ( PortVectorIterator it = m_PacketPorts.begin(); 1046 it != m_PacketPorts.end(); 1047 ++it ) 1048 { 1034 it != m_PacketPorts.end(); 1035 ++it ) { 1049 1036 1050 1037 #ifdef DEBUG … … 1065 1052 } 1066 1053 1067 /* for reference 1068 1069 int MotuReceiveStreamProcessor::decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, 1070 unsigned int offset, unsigned int nevents) 1054 signed int MotuReceiveStreamProcessor::decodeMBLAEventsToPort(MotuAudioPort *p, 1055 quadlet_t *data, unsigned int offset, unsigned int nevents) 1071 1056 { 1072 1057 unsigned int j=0; … … 1076 1061 // printf("****************\n"); 1077 1062 1078 quadlet_t *target_event; 1079 1080 target_event=(quadlet_t *)(data + p->getPosition()); 1063 // Use char here since a port's source address won't necessarily be 1064 // aligned; use of an unaligned quadlet_t may cause issues on certain 1065 // architectures. 1066 unsigned char *src_data; 1067 src_data = (unsigned char *)data + p->getPosition(); 1081 1068 1082 1069 switch(p->getDataType()) { … … 1090 1077 buffer+=offset; 1091 1078 1092 for(j = 0; j < nevents; j += 1) { // decode max nsamples 1093 *(buffer)=(ntohl((*target_event) ) & 0x00FFFFFF); 1079 for(j = 0; j < nevents; j += 1) { // Decode nsamples 1080 *buffer = (*src_data<<16)+(*(src_data+1)<<8)+*(src_data+2); 1081 // Sign-extend highest bit of 24-bit int. 1082 // FIXME: this isn't strictly needed since E_Int24 is a 24-bit, 1083 // but doing so shouldn't break anything and makes the data 1084 // easier to deal with during debugging. 1085 if (*src_data & 0x80) 1086 *buffer |= 0xff000000; 1087 1094 1088 buffer++; 1095 target_event+=m_dimension;1089 src_data+=m_event_size; 1096 1090 } 1097 1091 } … … 1108 1102 for(j = 0; j < nevents; j += 1) { // decode max nsamples 1109 1103 1110 unsigned int v = ntohl(*target_event) & 0x00FFFFFF; 1104 unsigned int v = (*src_data<<16)+(*(src_data+1)<<8)+*(src_data+2); 1105 1111 1106 // sign-extend highest bit of 24-bit int 1112 1107 int tmp = (int)(v << 8) / 256; … … 1115 1110 1116 1111 buffer++; 1117 target_event+=m_dimension;1112 src_data+=m_event_size; 1118 1113 } 1119 1114 } … … 1123 1118 return 0; 1124 1119 } 1125 */1126 1120 1127 1121 signed int MotuReceiveStreamProcessor::setEventSize(unsigned int size) { branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h
r272 r274 34 34 35 35 namespace FreebobStreaming { 36 37 class MotuAudioPort; 36 38 37 39 /** … … 136 138 int receiveBlock(char *data, unsigned int nevents, unsigned int offset); 137 139 bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); 138 140 signed int decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents); 139 141 140 142 freebob_ringbuffer_t * m_event_buffer; branches/libfreebob-2.0/src/motu/motu_avdevice.cpp
r272 r274 584 584 debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",name); 585 585 } 586 p->enable(); 586 587 } 587 588 free(name); … … 604 605 const char *aux_str = direction==FreebobStreaming::Port::E_Capture?"Mix1":"Phones"; 605 606 FreebobStreaming::StreamProcessor *s_processor; 606 unsigned int i ;607 unsigned int i, ofs; 607 608 char *buff; 608 609 … … 612 613 s_processor = m_transmitProcessor; 613 614 } 615 // Offset into an event's data of the first audio data 616 ofs = 10; 617 618 // Add ports for the Mix1 return / Phones send which is present for 619 // 1x and 2x sampling rates. 620 if (sample_rate<=96000) { 621 for (i=0; i<2; i++, ofs+=3) { 622 asprintf(&buff,"dev%d_%s_%s-%c", m_id, mode_str, 623 aux_str, i==0?'L':'R'); 624 if (!addPort(s_processor, buff, direction, ofs, 0)) 625 return false; 626 } 627 } 614 628 615 629 // Unconditionally add the 8 analog capture ports since they are 616 630 // always present no matter what the device configuration is. 617 for (i=0; i<8; i++ ) {631 for (i=0; i<8; i++, ofs+=3) { 618 632 asprintf(&buff,"dev%d_%s_Analog%d", m_id, mode_str, i+1); 619 if (!addPort(s_processor, buff, direction, 0, 0))633 if (!addPort(s_processor, buff, direction, ofs, 0)) 620 634 return false; 621 635 } 622 636 623 // AES/EBU ports are present for 1x and 2x sampling rates 637 // AES/EBU ports are present for 1x and 2x sampling rates on the 638 // Traveler. On earlier interfaces (for example, 828 MkII) this 639 // space was taken up with a separate "main out" send. 640 // FIXME: what is in this position of incoming data on an 828 MkII? 624 641 if (sample_rate <= 96000) { 625 for (i=0; i<2; i++) { 626 asprintf(&buff,"dev%d_%s_AES/EBU%d", m_id, mode_str, i+1); 627 if (!addPort(s_processor, buff, direction, 0, 0)) 642 for (i=0; i<2; i++, ofs+=3) { 643 if (m_motu_model == MOTUFW_MODEL_TRAVELER) { 644 asprintf(&buff,"dev%d_%s_AES/EBU%d", m_id, mode_str, i+1); 645 } else { 646 if (direction == FreebobStreaming::Port::E_Capture) 647 asprintf(&buff,"dev%d_%s_MainOut-%c", m_id, mode_str, i==0?'L':'R'); 648 else 649 asprintf(&buff,"dev%d_%s_????%d", m_id, mode_str, i+1); 650 } 651 if (!addPort(s_processor, buff, direction, ofs, 0)) 628 652 return false; 629 653 } … … 633 657 // as the optical mode is not TOSLINK. 634 658 if (sample_rate<=96000 && optical_mode!=MOTUFW_OPTICAL_MODE_TOSLINK) { 635 for (i=0; i<2; i++ ) {659 for (i=0; i<2; i++, ofs+=3) { 636 660 asprintf(&buff,"dev%d_%s_SPDIF%d", m_id, mode_str, i+1); 637 if (!addPort(s_processor, buff, direction, 0, 0))661 if (!addPort(s_processor, buff, direction, ofs, 0)) 638 662 return false; 639 663 } … … 643 667 // as the optical mode is set to TOSLINK. 644 668 if (sample_rate<=96000 && optical_mode==MOTUFW_OPTICAL_MODE_TOSLINK) { 645 for (i=0; i<2; i++ ) {669 for (i=0; i<2; i++, ofs+=3) { 646 670 asprintf(&buff,"dev%d_%s_TOSLINK%d", m_id, mode_str, i+1); 647 if (!addPort(s_processor, buff, direction, 0, 0))671 if (!addPort(s_processor, buff, direction, ofs, 0)) 648 672 return false; 649 673 } … … 653 677 // as the optical mode is set to ADAT. 654 678 if (sample_rate<=96000 && optical_mode==MOTUFW_OPTICAL_MODE_ADAT) { 655 for (i=0; i<4; i++ ) {679 for (i=0; i<4; i++, ofs+=3) { 656 680 asprintf(&buff,"dev%d_%s_ADAT%d", m_id, mode_str, i+1); 657 if (!addPort(s_processor, buff, direction, 0, 0))681 if (!addPort(s_processor, buff, direction, ofs, 0)) 658 682 return false; 659 683 } … … 663 687 // optical mode is set to ADAT. 664 688 if (sample_rate<=48000 && optical_mode==MOTUFW_OPTICAL_MODE_ADAT) { 665 for (i=4; i<8; i++ ) {689 for (i=4; i<8; i++, ofs+=3) { 666 690 asprintf(&buff,"dev%d_%s_ADAT%d", m_id, mode_str, i+1); 667 if (!addPort(s_processor, buff, direction, 0, 0)) 668 return false; 669 } 670 } 671 672 // Finally add ports for the Mix1 return / Phones send which is 673 // present for 1x and 2x sampling rates. 674 if (sample_rate<=96000) { 675 for (i=0; i<2; i++) { 676 asprintf(&buff,"dev%d_%s_%s-%c", m_id, mode_str, 677 aux_str, i==0?'L':'R'); 678 if (!addPort(s_processor, buff, direction, 0, 0)) 691 if (!addPort(s_processor, buff, direction, ofs, 0)) 679 692 return false; 680 693 } branches/libfreebob-2.0/tests/streaming/teststreaming2.c
r272 r274 100 100 /* assign the audiobuffer to the stream */ 101 101 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i])); 102 freebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_int24); 102 103 break; 103 104 // this is done with read/write routines because the nb of bytes can differ. … … 179 180 } 180 181 182 FILE *of=fopen("foo.dat","w"); 183 181 184 // prepare and start the streaming layer 182 185 freebob_streaming_prepare(dev); … … 222 225 } 223 226 224 /* fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 225 hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(freebob_sample_t)+1);*/ 227 // fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 228 // hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(freebob_sample_t)+1); 229 // FIXME: Dump analog1 as raw data to a separate binary file for testing 230 if (i==2) { 231 fwrite(audiobuffer[i],sizeof(freebob_sample_t),samplesread,of); 232 } 226 233 } 227 234 … … 236 243 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 237 244 case freebob_stream_type_audio: 238 sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 239 // sampleswritten=PERIOD_SIZE; 245 //// Calling freebob_streaming_write() causes problems since the buffer is external here. 246 //// Just mirror the read case since it seems to work. 247 //// sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 248 sampleswritten=PERIOD_SIZE; 240 249 break; 241 250 case freebob_stream_type_midi: … … 258 267 259 268 freebob_streaming_finish(dev); 269 fclose(of); 260 270 261 271 for (i=0;i<nb_out_channels;i++) { branches/libfreebob-2.0/tests/streaming/teststreaming3.c
r194 r274 103 103 case freebob_stream_type_audio: 104 104 /* assign the audiobuffer to the stream */ 105 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i]), freebob_buffer_type_float); 105 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 106 freebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_float); 106 107 break; 107 108 // this is done with read/write routines because the nb of bytes can differ. … … 119 120 if (i<nb_in_channels) { 120 121 /* assign the audiobuffer to the stream */ 121 freebob_streaming_set_playback_stream_buffer(dev, i, (char *)audiobuffers_in[i], freebob_buffer_type_float); 122 freebob_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 123 freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_float); 122 124 } else { 123 freebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer, freebob_buffer_type_uint24); 125 freebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 126 freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_uint24); 124 127 } 125 128 break;