Changeset 194
- Timestamp:
- 05/12/06 09:19:08 (18 years ago)
- Files:
-
- trunk/libfreebob/ChangeLog (modified) (1 diff)
- trunk/libfreebob/configure.ac (modified) (1 diff)
- trunk/libfreebob/libfreebob/freebob_streaming.h (modified) (2 diffs)
- trunk/libfreebob/src/libfreebobstreaming/freebob_connections.c (modified) (2 diffs)
- trunk/libfreebob/src/libfreebobstreaming/freebob_connections.h (modified) (3 diffs)
- trunk/libfreebob/src/libfreebobstreaming/freebob_streaming.c (modified) (48 diffs)
- trunk/libfreebob/tests/streaming/testmidistreaming1.c (modified) (1 diff)
- trunk/libfreebob/tests/streaming/teststreaming.c (modified) (1 diff)
- trunk/libfreebob/tests/streaming/teststreaming2.c (modified) (1 diff)
- trunk/libfreebob/tests/streaming/teststreaming3.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libfreebob/ChangeLog
r192 r194 1 2006-05-12 Pieter Palmers <pieterpalmers@users.sourceforge.net> 2 * src/libfreebobstreaming/*: 3 - Code cleanup 4 - Improved SSE code 5 - ISO connection parameters are calculated instead of being user 6 specified. Note: you need a new jackd backend version due to this. 7 8 * configure.ac: Version bumped to 0.8.2 9 1 10 2006-05-06 Daniel Wagner <wagi@monom.org> 2 11 trunk/libfreebob/configure.ac
r190 r194 24 24 m4_define(freebob_major_version, 0) 25 25 m4_define(freebob_minor_version, 8) 26 m4_define(freebob_micro_version, 1)26 m4_define(freebob_micro_version, 2) 27 27 28 28 m4_define(freebob_version, freebob_major_version.freebob_minor_version.freebob_micro_version) trunk/libfreebob/libfreebob/freebob_streaming.h
r185 r194 108 108 int nb_buffers; /* the size of the frame buffer (in periods) */ 109 109 110 /* RAW1394 related settings */111 int iso_buffers;112 int iso_prebuffers;113 int iso_irq_interval;114 115 110 /* packetizer thread options */ 116 111 int realtime; … … 121 116 int port; 122 117 123 124 118 /* direction map */ 125 119 int directions; trunk/libfreebob/src/libfreebobstreaming/freebob_connections.c
r185 r194 118 118 connection->status.xruns = 0; 119 119 connection->status.packets=0; 120 121 #ifdef DEBUG 122 connection->status.total_packets_prev=0; 123 #endif 124 120 125 connection->status.dropped=0; 121 126 122 127 // make sure the connection is polled next time 123 128 if(connection->pfd) { // this can be called before everything is init'ed … … 146 151 } 147 152 raw1394_set_userdata(connection->raw_handle, (void *)connection); 148 149 // these have quite some influence on latency150 connection->iso.buffers = dev->options.iso_buffers;151 connection->iso.prebuffers = dev->options.iso_prebuffers;152 connection->iso.irq_interval = dev->options.iso_irq_interval;153 153 154 154 connection->iso.speed = RAW1394_ISO_SPEED_400; trunk/libfreebob/src/libfreebobstreaming/freebob_connections.h
r185 r194 152 152 int irq_interval; 153 153 int startcycle; 154 154 enum raw1394_iso_dma_recv_mode receive_mode; 155 155 156 int iso_channel; 156 157 int do_disconnect; 157 158 int bandwidth; 159 160 int packets_per_period; 161 int max_packet_size; // tailored to result in optimal IRQ timing 162 int packet_size; // expected packet size 158 163 159 164 int hostplug; … … 165 170 int packets; 166 171 int events; 167 //int total_packets;168 int total_packets_prev;169 172 int total_events; 170 173 … … 179 182 int dropped; 180 183 184 185 #ifdef DEBUG 181 186 int fdf; 182 187 int total_packets_prev; 183 188 int last_cycle; 189 #endif 184 190 185 191 int packet_info_table_size; trunk/libfreebob/src/libfreebobstreaming/freebob_streaming.c
r190 r194 101 101 printMessage(" Period Size : %d\n",options.period_size); 102 102 printMessage(" Nb Buffers : %d\n",options.nb_buffers); 103 printMessage(" RAW1394 ISO Buffers : %d\n",options.iso_buffers);104 printMessage(" RAW1394 ISO Prebuffers : %d\n",options.iso_prebuffers);105 printMessage(" RAW1394 ISO IRQ Interval : %d\n",options.iso_irq_interval);106 103 printMessage(" Directions : %X\n",options.directions); 107 104 … … 561 558 err=0; 562 559 freebob_connection_t *connection= &(dev->connections[i]); 563 560 561 int fdf, syt_interval; 562 563 int samplerate=dev->options.sample_rate; 564 565 switch (samplerate) { 566 case 32000: 567 syt_interval = 8; 568 fdf = IEC61883_FDF_SFC_32KHZ; 569 break; 570 case 44100: 571 syt_interval = 8; 572 fdf = IEC61883_FDF_SFC_44K1HZ; 573 break; 574 default: 575 case 48000: 576 syt_interval = 8; 577 fdf = IEC61883_FDF_SFC_48KHZ; 578 break; 579 case 88200: 580 syt_interval = 16; 581 fdf = IEC61883_FDF_SFC_88K2HZ; 582 break; 583 case 96000: 584 syt_interval = 16; 585 fdf = IEC61883_FDF_SFC_96KHZ; 586 break; 587 case 176400: 588 syt_interval = 32; 589 fdf = IEC61883_FDF_SFC_176K4HZ; 590 break; 591 case 192000: 592 syt_interval = 32; 593 fdf = IEC61883_FDF_SFC_192KHZ; 594 break; 595 } 596 597 if(dev->options.period_size < syt_interval) { 598 printError("Period size (%d) too small! Samplerate %d requires period >= %d\n", 599 dev->options.period_size, samplerate, syt_interval); 600 return -1; 601 } 602 connection->iso.packets_per_period = dev->options.period_size/syt_interval; 603 564 604 //connection->plug=0; 565 605 connection->iso.hostplug=-1; … … 596 636 597 637 } 598 599 // this moved to iso_connection_start in order to work around a raw1394 bug 600 #if 0 601 if (connection->spec.is_master) { //master connection 602 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO master receive handler on channel %d...\n",connection->iso.iso_channel); 603 debugPrint(DEBUG_LEVEL_STARTUP, " (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n",connection->iso.buffers,AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 604 raw1394_iso_recv_init( 605 connection->raw_handle, 606 iso_master_receive_handler, 607 connection->iso.buffers, 608 AMDTP_MAX_PACKET_SIZE, 609 connection->iso.iso_channel, 610 RAW1394_DMA_BUFFERFILL, 611 connection->iso.irq_interval); 612 613 dev->sync_master_connection=connection; 614 connection->status.master=NULL; 615 638 639 // setup the optimal parameters for the raw1394 ISO buffering 640 connection->iso.packets_per_period=dev->options.period_size/syt_interval; 641 // hardware interrupts occur when one DMA block is full, and the size of one DMA 642 // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq 643 // occurs at a period boundary (optimal CPU use) 644 // note: try and use 2 interrupts per period for better latency. 645 connection->iso.max_packet_size=getpagesize() / connection->iso.packets_per_period * 2; 646 connection->iso.irq_interval=connection->iso.packets_per_period/2; 647 648 connection->iso.packet_size=4 * (2 + syt_interval * connection->spec.dimension); 649 650 if (connection->iso.max_packet_size < connection->iso.packet_size) { 651 connection->iso.max_packet_size=connection->iso.packet_size; 652 } 653 654 /* the receive buffer size doesn't matter for the latency, 655 but it has a minimal value in order for libraw to operate correctly (300) */ 656 connection->iso.buffers=400; 657 658 // this is a hack 659 if(dev->options.period_size < 128) { 660 connection->iso.receive_mode=RAW1394_DMA_PACKET_PER_BUFFER; 616 661 } else { 617 //slave receive connection 618 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO slave receive handler on channel %d...\n",connection->iso.iso_channel); 619 debugPrint(DEBUG_LEVEL_STARTUP, " (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n", connection->iso.buffers, AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 620 raw1394_iso_recv_init( 621 connection->raw_handle, 622 iso_slave_receive_handler, 623 connection->iso.buffers, 624 AMDTP_MAX_PACKET_SIZE, 625 connection->iso.iso_channel, 626 RAW1394_DMA_BUFFERFILL, 627 connection->iso.irq_interval); 662 connection->iso.receive_mode=RAW1394_DMA_BUFFERFILL; 628 663 } 629 #endif 664 630 665 break; 631 666 case FREEBOB_PLAYBACK: … … 651 686 connection->status.master=NULL; 652 687 } 653 654 // this moved to iso_connection_start in order to work around a raw1394 bug 655 #if 0 656 if (connection->spec.is_master) { // master connection 657 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO master transmit handler on channel %d...\n",connection->iso.iso_channel); 658 debugPrint(DEBUG_LEVEL_STARTUP, " other mode (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n",connection->iso.buffers,AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 659 660 raw1394_iso_xmit_init( 661 connection->raw_handle, 662 iso_master_transmit_handler, 663 connection->iso.buffers, 664 AMDTP_MAX_PACKET_SIZE, 665 connection->iso.iso_channel, 666 RAW1394_ISO_SPEED_400, 667 connection->iso.irq_interval); 668 669 dev->sync_master_connection=connection; 670 connection->status.master=NULL; 671 672 } else { 673 674 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO slave transmit handler on channel %d...\n",connection->iso.iso_channel); 675 debugPrint(DEBUG_LEVEL_STARTUP, " (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n",connection->iso.buffers,AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 676 raw1394_iso_xmit_init( 677 connection->raw_handle, 678 iso_slave_transmit_handler, 679 connection->iso.buffers, 680 AMDTP_MAX_PACKET_SIZE, 681 connection->iso.iso_channel, 682 RAW1394_ISO_SPEED_400, 683 connection->iso.irq_interval); 684 } 685 #endif 686 int fdf, syt_interval; 687 // FIXME: 688 int samplerate=dev->options.sample_rate; 689 // int samplerate=connection->spec.samplerate; 690 691 switch (samplerate) { 692 case 32000: 693 syt_interval = 8; 694 fdf = IEC61883_FDF_SFC_32KHZ; 695 break; 696 case 44100: 697 syt_interval = 8; 698 fdf = IEC61883_FDF_SFC_44K1HZ; 699 break; 700 default: 701 case 48000: 702 syt_interval = 8; 703 fdf = IEC61883_FDF_SFC_48KHZ; 704 break; 705 case 88200: 706 syt_interval = 16; 707 fdf = IEC61883_FDF_SFC_88K2HZ; 708 break; 709 case 96000: 710 syt_interval = 16; 711 fdf = IEC61883_FDF_SFC_96KHZ; 712 break; 713 case 176400: 714 syt_interval = 32; 715 fdf = IEC61883_FDF_SFC_176K4HZ; 716 break; 717 case 192000: 718 syt_interval = 32; 719 fdf = IEC61883_FDF_SFC_192KHZ; 720 break; 721 } 722 688 723 689 iec61883_cip_init ( 724 690 &connection->status.cip, … … 733 699 IEC61883_MODE_BLOCKING_EMPTY); 734 700 701 702 // setup the optimal parameters for the raw1394 ISO buffering 703 connection->iso.packets_per_period=dev->options.period_size/syt_interval; 704 // hardware interrupts occur when one DMA block is full, and the size of one DMA 705 // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq is 706 // occurs at a period boundary (optimal CPU use) 707 // note: try and use 2 interrupts per period for better latency. 708 connection->iso.max_packet_size=getpagesize() / connection->iso.packets_per_period * 2; 709 connection->iso.irq_interval=connection->iso.packets_per_period / 2; 710 711 connection->iso.packet_size=4 * (2 + syt_interval * connection->spec.dimension); 712 713 if (connection->iso.max_packet_size < connection->iso.packet_size) { 714 connection->iso.max_packet_size=connection->iso.packet_size; 715 } 716 717 /* the transmit buffer size should be as low as possible for latency. 718 */ 719 connection->iso.buffers=connection->iso.packets_per_period; 720 if (connection->iso.buffers<10) connection->iso.buffers=10; 721 735 722 break; 736 723 } … … 741 728 while(i>=0) { 742 729 connection= &(dev->connections[i]); 743 744 // not nescessary anymore since it moved to the iso_start function745 /* debugPrint(DEBUG_LEVEL_STARTUP, "Shutdown connection %d on channel %d ...\n", i, connection->iso.iso_channel);746 747 raw1394_iso_shutdown(connection->raw_handle);748 */749 730 750 731 if (connection->iso.do_disconnect) { … … 843 824 debugPrint(DEBUG_LEVEL_STARTUP,"Armed...\n"); 844 825 845 //freebob_streaming_start_iso(dev);846 847 826 freebob_streaming_start_thread(dev); 848 827 … … 857 836 freebob_streaming_stop_thread(dev); 858 837 859 //freebob_streaming_stop_iso(dev);860 861 838 // stop ISO xmit/receive 862 839 for(i=0; i < dev->nb_connections; i++) { 863 840 freebob_connection_t *connection= &(dev->connections[i]); 864 865 // this moved to iso_connection_stop in order to work around a raw1394 bug866 #if 0867 debugPrint(DEBUG_LEVEL_STARTUP, "Shutdown connection %d on channel %d ...\n", i, connection->iso.iso_channel);868 869 raw1394_iso_shutdown(connection->raw_handle);870 #endif871 841 872 842 if (connection->iso.do_disconnect) { … … 1449 1419 connection->status.dropped=0; 1450 1420 if (connection->spec.is_master) { //master connection 1451 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO master receive handler on channel %d...\n",connection->iso.iso_channel); 1452 debugPrint(DEBUG_LEVEL_STARTUP, " (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n",connection->iso.buffers,AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 1421 1422 debugPrint(DEBUG_LEVEL_STARTUP, 1423 "Init ISO master receive handler on channel %d...\n", 1424 connection->iso.iso_channel); 1425 1426 debugPrint(DEBUG_LEVEL_STARTUP, 1427 " (%s, BUFFERS=%d, PACKET_SIZE=%d, PACKET_MAX=%d, IRQ=%d, %d PKT/PERIOD)...\n", 1428 (connection->iso.receive_mode==RAW1394_DMA_PACKET_PER_BUFFER ? "PACKET_PER_BUFFER" : "BUFFERFILL"), 1429 connection->iso.buffers, 1430 connection->iso.packet_size, 1431 connection->iso.max_packet_size, 1432 connection->iso.irq_interval, 1433 connection->iso.packets_per_period); 1434 1453 1435 raw1394_iso_recv_init( 1454 1436 connection->raw_handle, 1455 1437 iso_master_receive_handler, 1456 /* the receive buffer size doesn't matter for the latency, 1457 but it has a minimal value in order for libraw to operate correctly (300) 1458 */ 1459 400, 1460 AMDTP_MAX_PACKET_SIZE, 1438 connection->iso.buffers, 1439 connection->iso.max_packet_size, 1461 1440 connection->iso.iso_channel, 1462 // RAW1394_DMA_BUFFERFILL, 1463 /* Packet per buffer enables low latency */ 1464 RAW1394_DMA_PACKET_PER_BUFFER, 1441 connection->iso.receive_mode, // RAW1394_DMA_BUFFERFILL, 1465 1442 connection->iso.irq_interval); 1466 1443 1467 1444 } else { 1468 //slave receive connection 1469 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO slave receive handler on channel %d...\n",connection->iso.iso_channel); 1470 debugPrint(DEBUG_LEVEL_STARTUP, " (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n", connection->iso.buffers, AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 1445 //slave receive connection 1446 debugPrint(DEBUG_LEVEL_STARTUP, 1447 "Init ISO slave receive handler on channel %d...\n", 1448 connection->iso.iso_channel); 1449 1450 debugPrint(DEBUG_LEVEL_STARTUP, 1451 " (%s, BUFFERS=%d, PACKET_SIZE=%d, PACKET_MAX=%d, IRQ=%d, %d PKT/PERIOD)...\n", 1452 (connection->iso.receive_mode==RAW1394_DMA_PACKET_PER_BUFFER ? "PACKET_PER_BUFFER" : "BUFFERFILL"), connection->iso.buffers, 1453 connection->iso.packet_size, 1454 connection->iso.max_packet_size, 1455 connection->iso.irq_interval, 1456 connection->iso.packets_per_period); 1457 1471 1458 raw1394_iso_recv_init( 1472 1459 connection->raw_handle, 1473 1460 iso_slave_receive_handler, 1474 /* the receive buffer size doesn't matter for the latency, 1475 but it has a minimal value in order for libraw to operate correctly (300) 1476 */ 1477 400, 1478 AMDTP_MAX_PACKET_SIZE, 1461 connection->iso.buffers, 1462 connection->iso.max_packet_size, 1479 1463 connection->iso.iso_channel, 1480 // RAW1394_DMA_BUFFERFILL, 1481 /* Packet per buffer enables low latency */ 1482 RAW1394_DMA_PACKET_PER_BUFFER, 1464 connection->iso.receive_mode, // RAW1394_DMA_BUFFERFILL, 1483 1465 connection->iso.irq_interval); 1484 1466 } 1485 1467 1486 debugPrint(DEBUG_LEVEL_STARTUP, "Start ISO receive for connection on channel %d at cycle %d...\n", connection->iso.iso_channel, connection->iso.startcycle); 1468 debugPrint(DEBUG_LEVEL_STARTUP, 1469 "Start ISO receive for connection on channel %d at cycle %d...\n", 1470 connection->iso.iso_channel, connection->iso.startcycle); 1487 1471 1488 1472 err = raw1394_iso_recv_start( … … 1502 1486 1503 1487 if (connection->spec.is_master) { // master connection 1504 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO master transmit handler on channel %d...\n",connection->iso.iso_channel); 1505 debugPrint(DEBUG_LEVEL_STARTUP, " other mode (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n",connection->iso.buffers,AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 1488 debugPrint(DEBUG_LEVEL_STARTUP, 1489 "Init ISO master transmit handler on channel %d...\n", 1490 connection->iso.iso_channel); 1491 1492 debugPrint(DEBUG_LEVEL_STARTUP, 1493 " (BUFFERS=%d, PACKET_SIZE=%d, PACKET_MAX=%d, IRQ=%d, %d PKT/PERIOD)...\n", 1494 connection->iso.buffers, 1495 connection->iso.packet_size, 1496 connection->iso.max_packet_size, 1497 connection->iso.irq_interval, 1498 connection->iso.packets_per_period); 1499 1506 1500 1507 1501 raw1394_iso_xmit_init( … … 1509 1503 iso_master_transmit_handler, 1510 1504 connection->iso.buffers, 1511 AMDTP_MAX_PACKET_SIZE,1505 connection->iso.max_packet_size, 1512 1506 connection->iso.iso_channel, 1513 1507 RAW1394_ISO_SPEED_400, … … 1515 1509 } else { 1516 1510 1517 debugPrint(DEBUG_LEVEL_STARTUP, "Init ISO slave transmit handler on channel %d...\n",connection->iso.iso_channel); 1518 debugPrint(DEBUG_LEVEL_STARTUP, " (BUFFER=%d,PACKET_MAX=%d,IRQ=%d)...\n",connection->iso.buffers,AMDTP_MAX_PACKET_SIZE, connection->iso.irq_interval); 1511 debugPrint(DEBUG_LEVEL_STARTUP, 1512 "Init ISO slave transmit handler on channel %d...\n", 1513 connection->iso.iso_channel); 1514 1515 debugPrint(DEBUG_LEVEL_STARTUP, 1516 " (BUFFERS=%d, PACKET_SIZE=%d, PACKET_MAX=%d, IRQ=%d, %d PKT/PERIOD)...\n", 1517 connection->iso.buffers, 1518 connection->iso.packet_size, 1519 connection->iso.max_packet_size, 1520 connection->iso.irq_interval, 1521 connection->iso.packets_per_period); 1522 1519 1523 raw1394_iso_xmit_init( 1520 1524 connection->raw_handle, 1521 1525 iso_slave_transmit_handler, 1522 1526 connection->iso.buffers, 1523 AMDTP_MAX_PACKET_SIZE,1527 connection->iso.max_packet_size, 1524 1528 connection->iso.iso_channel, 1525 1529 RAW1394_ISO_SPEED_400, 1526 connection->iso.irq_interval); 1527 } 1528 debugPrint(DEBUG_LEVEL_STARTUP, "Start ISO transmit for connection on channel %d at cycle %d\n", connection->iso.iso_channel, connection->iso.startcycle); 1530 connection->iso.irq_interval); 1531 1532 } 1533 1534 debugPrint(DEBUG_LEVEL_STARTUP, 1535 "Start ISO transmit for connection on channel %d at cycle %d\n", 1536 connection->iso.iso_channel, connection->iso.startcycle); 1529 1537 1530 1538 err=raw1394_iso_xmit_start( 1531 1532 connection->iso.startcycle,1533 connection->iso.prebuffers);1539 connection->raw_handle, 1540 connection->iso.startcycle, 1541 connection->iso.prebuffers); 1534 1542 1535 1543 if (err) { … … 1716 1724 debugPrint(DEBUG_LEVEL_STARTUP, "Go Go Go!!!\n"); 1717 1725 1718 //sem_post(&dev->packetizer.transfer_ack);1719 1726 #define POLL_BASED 1720 1727 #ifdef POLL_BASED 1721 1728 while (dev->packetizer.run && !underrun_detected) { 1722 //sem_wait(&dev->packetizer.transfer_ack);1723 1729 1724 1730 freebob_streaming_period_reset(dev); … … 1754 1760 } 1755 1761 1756 // if(dev->pfds[i].revents & (POLLIN | POLLPRI)) {1757 1762 if(dev->pfds[i].revents & (POLLIN)) { 1758 1763 // FIXME: this can segfault … … 1788 1793 if(underrun_detected) { 1789 1794 dev->xrun_detected=TRUE; 1790 //underrun_detected=0;1791 1795 } 1792 1796 1793 1797 #else 1794 1798 while (dev->packetizer.run && !underrun_detected) { 1795 //sem_wait(&dev->packetizer.transfer_ack);1796 1799 1797 1800 freebob_streaming_period_reset(dev); … … 1836 1839 connection = &(dev->connections[c]); 1837 1840 1838 // skip the sync master and the connections that are finished1839 //if ((connection == dev->sync_master_connection) || (connection->status.frames_left <= 0))1840 1841 1841 if ((connection == dev->sync_master_connection)) 1842 1842 continue; … … 1865 1865 if(underrun_detected) { 1866 1866 dev->xrun_detected=TRUE; 1867 //underrun_detected=0;1868 1867 } 1869 1868 … … 1883 1882 1884 1883 #ifdef DEBUG 1885 // update the packet counter1886 1884 if((dev->sync_master_connection->status.packets - dev->sync_master_connection->status.total_packets_prev) > 1024*2) { 1887 // if(1) {1888 1885 unsigned int i; 1889 1886 debugPrintShort(DEBUG_LEVEL_PACKETCOUNTER,"\r -> "); … … 1893 1890 assert(connection); 1894 1891 1895 /* Debug info format:1896 * [direction, packetcount, bufferfill, packetdrop1897 */1898 1892 debugPrintShort(DEBUG_LEVEL_PACKETCOUNTER,"[%s, %02d, %10d, %04d, %4d, (R: %04d)]", 1899 1893 (connection->spec.direction==FREEBOB_CAPTURE ? "C" : "P"), … … 1950 1944 } 1951 1945 1952 in t freebob_streaming_decode_midi(freebob_connection_t *connection,1946 inline int freebob_streaming_decode_midi(freebob_connection_t *connection, 1953 1947 quadlet_t* events, 1954 1948 unsigned int nsamples, … … 1984 1978 written=0; 1985 1979 1986 // debugPrint(DEBUG_LEVEL_PACKETCOUNTER, "Stream %d,%d,%d is midi, dbc=%d [",s,stream->spec.location,stream->spec.position,dbc);1987 1988 // for(j = (dbc%8)+stream->spec.location-1; j < nsamples; j += 8) {1989 1980 for(j = (dbc & 0x07)+stream->spec.location-1; j < nsamples; j += 8) { 1990 1981 target_event=(quadlet_t *)(events + ((j * connection->spec.dimension) + stream->spec.position)); … … 1992 1983 if(IEC61883_AM824_GET_LABEL(sample_int) != IEC61883_AM824_LABEL_MIDI_NO_DATA) { 1993 1984 *(buffer)=(sample_int >> 16); 1994 // debugPrintShort(DEBUG_LEVEL_PACKETCOUNTER, "%08X-%08X-%d ",*target_event,*buffer,((j * connection->spec.dimension) + stream->spec.position));1995 1985 buffer++; 1996 1986 written++; … … 2002 1992 printMessage("MIDI OUT bytes lost (%d/%d)",written_to_rb,written); 2003 1993 } 2004 // debugPrintShort(DEBUG_LEVEL_PACKETCOUNTER, "]\n");2005 2006 2007 /*2008 for(j = 0; j < nsamples; j += 1) {2009 target_event=(quadlet_t *)(events + j);2010 quadlet_t sample_int=ntohl(*target_event);2011 *(buffer)=sample_int;2012 buffer++;2013 written++;2014 2015 }2016 written=freebob_ringbuffer_write(stream->buffer, (char *)(stream->user_buffer), written*sizeof(quadlet_t))/sizeof(quadlet_t);2017 */2018 1994 } 2019 1995 } … … 2027 2003 */ 2028 2004 2029 in t freebob_streaming_encode_midi(freebob_connection_t *connection,2005 inline int freebob_streaming_encode_midi(freebob_connection_t *connection, 2030 2006 quadlet_t* events, 2031 2007 unsigned int nsamples, … … 2081 2057 stream->midi_counter--; 2082 2058 } 2083 /*2084 for(j=0; (j < nsamples); j++) {2085 target_event=(quadlet_t *)(events + ((j * connection->spec.dimension) + stream->spec.position));2086 2087 hexDumpQuadlets( target_event,1);2088 }2089 */2090 2091 2059 } 2092 2060 } … … 2106 2074 unsigned int dropped) 2107 2075 { 2108 enum raw1394_iso_disposition retval=RAW1394_ISO_OK; 2109 // static quadlet_t cntr=0; 2110 2111 // int xrun=0; 2076 enum raw1394_iso_disposition retval=RAW1394_ISO_OK; 2112 2077 2113 2078 freebob_connection_t *connection=(freebob_connection_t *) raw1394_get_userdata (handle); … … 2118 2083 2119 2084 // FIXME: dropped packets are very bad when transmitting and the other side is sync'ing on that! 2120 //connection->status.packets+=dropped;2121 2085 connection->status.dropped+=dropped; 2122 2086 2087 #ifdef DEBUG 2123 2088 connection->status.last_cycle=cycle; 2089 #endif 2124 2090 2125 2091 if((packet->fmt == 0x10) && (packet->fdf != 0xFF) && (packet->dbs>0) && (length>=2*sizeof(quadlet_t))) { … … 2129 2095 2130 2096 assert(connection->spec.dimension == packet->dbs); 2131 2132 // if(nevents>2) {2133 // quadlet_t *t=(quadlet_t *)(data+8);2134 // t+=2;2135 //2136 // t++;2137 // *t=0x40000000 | ((cntr) & 0xFFFFFF);2138 // t++;2139 // *t=0x40000000 | ((cntr++) & 0xFFFFFF);2140 // }2141 2097 2142 2098 if (freebob_ringbuffer_write( … … 2159 2115 // keep track of the total amount of events received 2160 2116 connection->status.events+=nevents; 2161 2117 2118 #ifdef DEBUG 2162 2119 connection->status.fdf=packet->fdf; 2163 2164 connection->status.last_timestamp.cycle=cycle; 2165 connection->status.last_timestamp.syt=packet->syt; 2166 2167 freebob_streaming_append_master_timestamp(connection->parent, &connection->status.last_timestamp); 2120 #endif 2121 2168 2122 } else { 2169 2123 // discard packet … … 2189 2143 return RAW1394_ISO_DEFER; 2190 2144 } 2191 // if( (!(connection->status.packets % 2))) { 2192 if( (!(connection->status.packets & 0x01))) { 2193 return RAW1394_ISO_DEFER; 2194 } 2145 2195 2146 return retval; 2196 2147 } … … 2211 2162 /* TODO: implement correct SYT behaviour */ 2212 2163 2213 // int xrun=0;2214 2215 2164 freebob_connection_t *connection=(freebob_connection_t *) raw1394_get_userdata (handle); 2216 2165 assert(connection); … … 2223 2172 connection->status.dropped+=dropped; 2224 2173 2174 #ifdef DEBUG 2225 2175 connection->status.last_cycle=cycle; 2176 #endif 2226 2177 2227 2178 if((packet->fmt == 0x10) && (packet->fdf != 0xFF) && (packet->dbs>0) && (length>=2*sizeof(quadlet_t))) { 2228 2179 unsigned int nevents=((length / sizeof (quadlet_t)) - 2)/packet->dbs; 2180 2181 #ifdef DEBUG 2229 2182 connection->status.fdf=packet->fdf; 2183 #endif 2230 2184 2231 2185 // add the data payload to the ringbuffer … … 2261 2215 if(packet->dbs) { 2262 2216 debugPrintWithTimeStamp(DEBUG_LEVEL_HANDLERS_LOWLEVEL, 2263 "SLAVE RCV: CH = %d, FDF = %X. SYT = %6d, DBS = %3d, DBC = %3d, FMT = %3d, LEN = %4d (%2d), DROPPED = %6d\n", 2264 channel, packet->fdf,packet->syt,packet->dbs,packet->dbc,packet->fmt, length, 2265 ((length / sizeof (quadlet_t)) - 2)/packet->dbs, dropped); 2217 "SLAVE RCV: CH = %d, FDF = %X. SYT = %6d, DBS = %3d, DBC = %3d, FMT = %3d, LEN = %4d (%2d), DROPPED = %6d\n", 2218 channel, packet->fdf, 2219 packet->syt, 2220 packet->dbs, 2221 packet->dbc, 2222 packet->fmt, 2223 length, 2224 ((length / sizeof (quadlet_t)) - 2)/packet->dbs, dropped); 2266 2225 } 2267 2226 … … 2271 2230 return RAW1394_ISO_DEFER; 2272 2231 } 2273 // if( (!(connection->status.packets % 2))) { 2274 if( (!(connection->status.packets & 0x01))) { 2275 return RAW1394_ISO_DEFER; 2276 } 2232 2277 2233 return retval; 2278 2234 } … … 2305 2261 // construct the packet cip 2306 2262 int nevents = iec61883_cip_fill_header (handle, &connection->status.cip, packet); 2307 // int xrun=0;2308 2263 int nsamples=0; 2309 2264 int bytes_read; 2310 2265 2311 freebob_timestamp_t tstamp; 2312 2313 // unsigned int syt; 2314 2266 #ifdef DEBUG 2315 2267 connection->status.last_cycle=cycle; 2316 2317 enum raw1394_iso_disposition retval = RAW1394_ISO_OK; 2318 2319 int i; 2320 // if packets are dropped, also drop the same amount of timestamps from the ringbuffer 2321 for (i=0;i<dropped;i++) { 2322 freebob_ringbuffer_read(connection->timestamp_buffer,(char *)&tstamp,sizeof(freebob_timestamp_t)); 2323 } 2324 2325 // debug 2268 2326 2269 if(packet->fdf != 0xFF) { 2327 2270 connection->status.fdf=packet->fdf; 2328 2271 } 2272 #endif 2273 2274 enum raw1394_iso_disposition retval = RAW1394_ISO_OK; 2275 2276 2329 2277 2330 2278 if (nevents > 0) { … … 2341 2289 2342 2290 // dropped packets are very bad when transmitting and the other side is sync'ing on that! 2343 //connection->status.packets+=dropped;2344 2291 connection->status.dropped += dropped; 2345 2292 2346 2293 if (nsamples > 0) { 2347 2348 if(freebob_ringbuffer_read(connection->timestamp_buffer,(char *)&tstamp,sizeof(freebob_timestamp_t))) {2349 packet->syt=tstamp.syt+connection->total_delay;2350 }2351 2294 2352 2295 assert(connection->spec.dimension == packet->dbs); … … 2368 2311 } 2369 2312 2370 // if (xrun) {2371 // printError("SLAVE XMT: Buffer underrun!\n");2372 // connection->status.xruns++;2373 // retval=RAW1394_ISO_DEFER;2374 // nsamples=0;2375 // }2376 2377 2313 *length = nsamples * connection->spec.dimension * sizeof (quadlet_t) + 8; 2378 2314 *tag = IEC61883_TAG_WITH_CIP; … … 2394 2330 nevents, nsamples); 2395 2331 } 2396 // TODO: the -100 should be derrived from the buffer size 2332 2397 2333 if((connection->status.frames_left<=0)) { 2398 2334 connection->pfd->events=0; 2399 2335 return RAW1394_ISO_DEFER; 2400 2336 } 2401 // if( (!(connection->status.packets % 2))) { 2402 if( (!(connection->status.packets & 0x01))) { 2403 return RAW1394_ISO_DEFER; 2404 } 2337 2405 2338 return retval; 2406 2339 … … 2427 2360 2428 2361 int nevents = iec61883_cip_fill_header (handle, &connection->status.cip, packet); 2429 // int xrun=0;2430 2362 int nsamples=0; 2431 2363 int bytes_read; 2432 2433 freebob_timestamp_t tstamp; 2434 2435 // unsigned int syt; 2364 2365 #ifdef DEBUG 2436 2366 connection->status.last_cycle=cycle; 2437 2438 enum raw1394_iso_disposition retval = RAW1394_ISO_OK; 2439 2440 int i; 2441 // if packets are dropped, also drop the same amount of timestamps from the ringbuffer 2442 for (i=0;i<dropped;i++) { 2443 freebob_ringbuffer_read(connection->timestamp_buffer,(char *)&tstamp,sizeof(freebob_timestamp_t)); 2444 } 2445 2446 // debug 2367 2447 2368 if(packet->fdf != 0xFF) { 2448 2369 connection->status.fdf=packet->fdf; 2449 2370 } 2371 #endif 2372 2373 enum raw1394_iso_disposition retval = RAW1394_ISO_OK; 2374 2450 2375 2451 2376 if (nevents > 0) { … … 2467 2392 if (nsamples > 0) { 2468 2393 int bytes_to_read=nsamples*sizeof(quadlet_t)*connection->spec.dimension; 2469 2470 if(freebob_ringbuffer_read(connection->timestamp_buffer,(char *)&tstamp,sizeof(freebob_timestamp_t))) {2471 packet->syt=tstamp.syt+connection->total_delay;2472 }2473 2394 2474 2395 assert(connection->spec.dimension == packet->dbs); … … 2508 2429 freebob_streaming_encode_midi(connection,(quadlet_t *)(data+8), nevents, packet->dbc); 2509 2430 } 2510 // hexDumpQuadlets( data,nsamples*connection->spec.dimension+2);2511 2431 } 2512 2432 … … 2531 2451 } 2532 2452 2533 /*if((connection->status.frames_left<=0)) {2453 if((connection->status.frames_left<=0)) { 2534 2454 connection->pfd->events=0; 2535 2455 return RAW1394_ISO_DEFER; 2536 2456 } 2537 */ 2538 /* if( (!(connection->status.packets % 2))) { 2539 return RAW1394_ISO_DEFER; 2540 }*/ 2457 2541 2458 return retval; 2542 2459 … … 2585 2502 case freebob_buffer_type_per_stream: 2586 2503 default: 2587 // assert(nsamples < dev->options.period_size);2588 2589 2504 // use the preallocated buffer (at init time) 2590 2505 buffer=((freebob_sample_t *)(stream->user_buffer))+stream->user_buffer_position; … … 2618 2533 for(j = 0; j < nsamples; j += 1) { // decode max nsamples 2619 2534 *(buffer)=(ntohl((*target_event) ) & 0x00FFFFFF); 2620 // fprintf(stderr,"[%03d, %02d: %08p %08X %08X]\n",j, stream->spec.position, target_event, *target_event, *buffer);2621 2535 buffer++; 2622 2536 target_event+=dimension; … … 2624 2538 break; 2625 2539 case freebob_buffer_type_float: 2626 // assert(nsamples>=4);2627 2540 j=0; 2628 2541 if(nsamples>3) { 2629 for(j = 0; j < nsamples- 4; j += 4) {2542 for(j = 0; j < nsamples-3; j += 4) { 2630 2543 tmp[0] = ntohl(*target_event); 2631 2544 target_event += dimension; … … 2653 2566 } 2654 2567 } 2655 if (j != nsamples) { 2656 for(; j < nsamples; ++j) { // decode max nsamples 2657 unsigned int v = ntohl(*target_event) & 0x00FFFFFF; 2658 // sign-extend highest bit of 24-bit int 2659 int tmp = (int)(v << 8) / 256; 2660 *floatbuff = tmp * multiplier; 2661 2662 floatbuff++; 2663 target_event += dimension; 2664 } 2568 for(; j < nsamples; ++j) { // decode max nsamples 2569 unsigned int v = ntohl(*target_event) & 0x00FFFFFF; 2570 // sign-extend highest bit of 24-bit int 2571 int tmp = (int)(v << 8) / 256; 2572 *floatbuff = tmp * multiplier; 2573 2574 floatbuff++; 2575 target_event += dimension; 2665 2576 } 2666 2577 asm volatile("emms"); … … 2793 2704 j=0; 2794 2705 if(read>3) { 2795 for (j = 0; j < read- 4; j += 4) {2706 for (j = 0; j < read-3; j += 4) { 2796 2707 asm("movups %[floatbuff], %%xmm0\n\t" 2797 2708 "mulps %[ssemult], %%xmm0\n\t" … … 2820 2731 } 2821 2732 } 2822 if (j != read) { 2823 for(; j < read; ++j) { 2824 // don't care for overflow 2825 float v = *floatbuff * multiplier; // v: -231 .. 231 2826 unsigned int tmp = (int)v; 2827 *target_event = htonl((tmp >> 8) | 0x40000000); 2828 2829 floatbuff++; 2830 target_event += dimension; 2831 } 2733 for(; j < read; ++j) { 2734 // don't care for overflow 2735 float v = *floatbuff * multiplier; // v: -231 .. 231 2736 unsigned int tmp = (int)v; 2737 *target_event = htonl((tmp >> 8) | 0x40000000); 2738 2739 floatbuff++; 2740 target_event += dimension; 2832 2741 } 2742 2833 2743 asm volatile("emms"); 2834 2744 break; trunk/libfreebob/tests/streaming/testmidistreaming1.c
r160 r194 159 159 dev_options.nb_buffers=3; 160 160 161 dev_options.iso_buffers=100;162 dev_options.iso_prebuffers=8;163 dev_options.iso_irq_interval=8;164 165 161 dev_options.port=1; 166 162 dev_options.node_id=-1; trunk/libfreebob/tests/streaming/teststreaming.c
r185 r194 73 73 dev_options.nb_buffers=3; 74 74 75 dev_options.iso_buffers=100;76 dev_options.iso_prebuffers=8;77 dev_options.iso_irq_interval=8;78 79 75 dev_options.port=0; 80 76 dev_options.node_id=-1; trunk/libfreebob/tests/streaming/teststreaming2.c
r183 r194 76 76 dev_options.nb_buffers=3; 77 77 78 dev_options.iso_buffers=100;79 dev_options.iso_prebuffers=8;80 dev_options.iso_irq_interval=8;81 82 78 dev_options.port=1; 83 79 dev_options.node_id=-1; trunk/libfreebob/tests/streaming/teststreaming3.c
r185 r194 78 78 dev_options.nb_buffers=3; 79 79 80 dev_options.iso_buffers=40;81 dev_options.iso_prebuffers=4;82 dev_options.iso_irq_interval=2;83 84 80 dev_options.port=0; 85 81 dev_options.node_id=-1;