Changeset 274

Show
Ignore:
Timestamp:
06/25/06 18:45:12 (17 years ago)
Author:
jwoithe
Message:

Fix buffer type configuration in teststreaming{2,3}.c.
Audio data can now be streamed in from a MOTU to teststreaming2.c.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp

    r272 r274  
    912912        unsigned int bytes2read = m_period * m_event_size; 
    913913 
    914 // FIXME: remove once the stuff below has been tweaked for the MOTU 
    915 //return true; 
    916  
    917914        /* Read events2read bytes from the ringbuffer. 
    918915        *  First see if it can be done in one read.  If so, ok. 
     
    968965                                 
    969966                        if(xrun<0) { 
    970                                        // xrun detected 
     967                                // xrun detected 
    971968                                debugError("RCV: Frame buffer overrun in processor %p\n",this); 
    972969                                break; 
     
    994991        for ( PortVectorIterator it = m_PeriodPorts.begin(); 
    995992          it != m_PeriodPorts.end(); 
    996           ++it ) 
    997     { 
    998  
    999         if((*it)->isDisabled()) {continue;}; 
     993          ++it ) { 
     994                if((*it)->isDisabled()) {continue;}; 
    1000995 
    1001996                //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); 
    1005998                 
    1006 /* AMDTP, left as reference 
    1007                 switch(pinfo->getFormat()) { 
     999                switch(port->getPortType()) { 
    10081000                 
    1009                 case MotuPortInfo::E_MBLA
     1001                case Port::E_Audio
    10101002                        if(decodeMBLAEventsToPort(static_cast<MotuAudioPort *>(*it), (quadlet_t *)data, offset, nevents)) { 
    10111003                                debugWarning("Could not decode packet MBLA to port %s",(*it)->getName().c_str()); 
     
    10131005                        } 
    10141006                        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; 
    10201010 
    10211011                default: // ignore 
    10221012                        break; 
    10231013                } 
    1024 */ 
    1025     } 
     1014        } 
    10261015        return problem; 
    1027  
    10281016} 
    10291017 
     
    10441032         
    10451033        for ( PortVectorIterator it = m_PacketPorts.begin(); 
    1046           it != m_PacketPorts.end(); 
    1047           ++it ) 
    1048         { 
     1034          it != m_PacketPorts.end(); 
     1035          ++it ) { 
    10491036 
    10501037#ifdef DEBUG 
     
    10651052} 
    10661053 
    1067 /* for reference 
    1068  
    1069 int MotuReceiveStreamProcessor::decodeMBLAEventsToPort(MotuAudioPort *p, quadlet_t *data,  
    1070                                            unsigned int offset, unsigned int nevents) 
     1054signed int MotuReceiveStreamProcessor::decodeMBLAEventsToPort(MotuAudioPort *p,  
     1055                quadlet_t *data, unsigned int offset, unsigned int nevents) 
    10711056{ 
    10721057        unsigned int j=0; 
     
    10761061//      printf("****************\n"); 
    10771062 
    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(); 
    10811068 
    10821069        switch(p->getDataType()) { 
     
    10901077                                buffer+=offset; 
    10911078 
    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 
    10941088                                        buffer++; 
    1095                                         target_event+=m_dimension
     1089                                        src_data+=m_event_size
    10961090                                } 
    10971091                        } 
     
    11081102                                for(j = 0; j < nevents; j += 1) { // decode max nsamples                 
    11091103         
    1110                                         unsigned int v = ntohl(*target_event) & 0x00FFFFFF; 
     1104                                        unsigned int v = (*src_data<<16)+(*(src_data+1)<<8)+*(src_data+2); 
     1105 
    11111106                                        // sign-extend highest bit of 24-bit int 
    11121107                                        int tmp = (int)(v << 8) / 256; 
     
    11151110                                 
    11161111                                        buffer++; 
    1117                                         target_event+=m_dimension
     1112                                        src_data+=m_event_size
    11181113                                } 
    11191114                        } 
     
    11231118        return 0; 
    11241119} 
    1125 */ 
    11261120 
    11271121signed int MotuReceiveStreamProcessor::setEventSize(unsigned int size) { 
  • branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.h

    r272 r274  
    3434 
    3535namespace FreebobStreaming { 
     36 
     37class MotuAudioPort; 
    3638 
    3739/** 
     
    136138        int receiveBlock(char *data, unsigned int nevents, unsigned int offset); 
    137139        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); 
    139141 
    140142        freebob_ringbuffer_t * m_event_buffer; 
  • branches/libfreebob-2.0/src/motu/motu_avdevice.cpp

    r272 r274  
    584584                        debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",name); 
    585585                } 
     586                p->enable(); 
    586587        } 
    587588        free(name); 
     
    604605const char *aux_str = direction==FreebobStreaming::Port::E_Capture?"Mix1":"Phones"; 
    605606FreebobStreaming::StreamProcessor *s_processor; 
    606 unsigned int i
     607unsigned int i, ofs
    607608char *buff; 
    608609 
     
    612613                s_processor = m_transmitProcessor; 
    613614        } 
     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        } 
    614628 
    615629        // Unconditionally add the 8 analog capture ports since they are 
    616630        // 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) { 
    618632                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)) 
    620634                        return false; 
    621635        } 
    622636 
    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? 
    624641        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)) 
    628652                                return false; 
    629653                } 
     
    633657        // as the optical mode is not TOSLINK. 
    634658        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) { 
    636660                        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)) 
    638662                                return false; 
    639663                } 
     
    643667        // as the optical mode is set to TOSLINK. 
    644668        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) { 
    646670                        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)) 
    648672                                return false; 
    649673                } 
     
    653677        // as the optical mode is set to ADAT. 
    654678        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) { 
    656680                        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)) 
    658682                                return false; 
    659683                } 
     
    663687        // optical mode is set to ADAT. 
    664688        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) { 
    666690                        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)) 
    679692                                return false; 
    680693                } 
  • branches/libfreebob-2.0/tests/streaming/teststreaming2.c

    r272 r274  
    100100                                /* assign the audiobuffer to the stream */ 
    101101                                freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i])); 
     102                                freebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_int24); 
    102103                                break; 
    103104                                // this is done with read/write routines because the nb of bytes can differ. 
     
    179180        } 
    180181 
     182FILE *of=fopen("foo.dat","w"); 
     183 
    181184        // prepare and start the streaming layer 
    182185        freebob_streaming_prepare(dev); 
     
    222225                        } 
    223226         
    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 
     230if (i==2) { 
     231  fwrite(audiobuffer[i],sizeof(freebob_sample_t),samplesread,of); 
     232
    226233                } 
    227234 
     
    236243                        switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    237244                        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; 
    240249                                break; 
    241250                        case freebob_stream_type_midi: 
     
    258267 
    259268        freebob_streaming_finish(dev); 
     269fclose(of); 
    260270 
    261271        for (i=0;i<nb_out_channels;i++) { 
  • branches/libfreebob-2.0/tests/streaming/teststreaming3.c

    r194 r274  
    103103                        case freebob_stream_type_audio: 
    104104                                /* 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); 
    106107                                break; 
    107108                                // this is done with read/write routines because the nb of bytes can differ. 
     
    119120                                if (i<nb_in_channels) { 
    120121                                        /* 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); 
    122124                                } 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);  
    124127                                } 
    125128                                break;