| 105 | // Initialise the cycle counter if this is the first time |
---|
| 106 | // iso data has been requested. |
---|
| 107 | if (!m_disabled && m_cycle_count<0) { |
---|
| 108 | debugOutput(DEBUG_LEVEL_VERBOSE, "tx enabled at cycle %d, dll=%g\n",cycle, |
---|
| 109 | m_sph_ofs_dll->get()); |
---|
| 110 | m_cycle_count = cycle; |
---|
| 111 | m_cycle_ofs = 0.0; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | // Do housekeeping expected for all packets sent to the MOTU, even |
---|
| 115 | // for packets containing no audio data. |
---|
| 116 | *sy = 0x00; |
---|
| 117 | *tag = 1; // All MOTU packets have a CIP-like header |
---|
| 118 | |
---|
| 119 | debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "get packet...\n"); |
---|
| 120 | |
---|
| 121 | // Size of a single data frame in quadlets |
---|
| 122 | unsigned dbs = m_event_size / 4; |
---|
| 123 | |
---|
| 124 | // The number of events expected by the MOTU is solely dependent on |
---|
| 125 | // the current sample rate. An 'event' is one sample from all channels |
---|
| 126 | // plus possibly other midi and control data. |
---|
| 127 | signed n_events = m_framerate<=48000?8:(m_framerate<=96000?16:32); |
---|
| 128 | |
---|
111 | | m_cycle_count = -1; |
---|
| 139 | // m_cycle_count = -1; |
---|
| 140 | debugOutput(DEBUG_LEVEL_VERBOSE, "now=%d, last call=%d, diff=%d\n", |
---|
| 141 | tv.tv_usec, last_us, tv.tv_usec>last_us?(tv.tv_usec-last_us):(1000000-last_us+tv.tv_usec)); |
---|
| 142 | |
---|
| 143 | #if 0 |
---|
| 144 | m_cycle_count = cycle; |
---|
| 145 | m_cycle_ofs = 0.0; |
---|
| 146 | m_tx_dbc = 0; |
---|
| 147 | #else |
---|
| 148 | signed int ccount, fcount; |
---|
| 149 | |
---|
| 150 | ccount = next_cycle; |
---|
| 151 | while (ccount!=cycle) { |
---|
| 152 | if (ccount < m_cycle_count) { |
---|
| 153 | if (++ccount == 8000) |
---|
| 154 | ccount = 0; |
---|
| 155 | continue; |
---|
| 156 | } |
---|
| 157 | m_tx_dbc += n_events; |
---|
| 158 | if (m_tx_dbc > 0xff) |
---|
| 159 | m_tx_dbc -= 0x100; |
---|
| 160 | for (fcount=0; fcount<n_events; fcount++) { |
---|
| 161 | m_cycle_ofs += m_sph_ofs_dll->get(); |
---|
| 162 | if (m_cycle_ofs >= 3072) { |
---|
| 163 | m_cycle_ofs -= 3072; |
---|
| 164 | if (++m_cycle_count > 7999) |
---|
| 165 | m_cycle_count -= 8000; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | if (++ccount == 8000) |
---|
| 169 | ccount = 0; |
---|
| 170 | } |
---|
| 171 | #endif |
---|
| 172 | debugOutput(DEBUG_LEVEL_VERBOSE, " resuming with cyclecount=%d, cycleofs=%g (dll=%g)\n", |
---|
| 173 | m_cycle_count, m_cycle_ofs, m_sph_ofs_dll->get()); |
---|
117 | | |
---|
118 | | // Initialise the cycle counter if this is the first time |
---|
119 | | // iso data has been requested. |
---|
120 | | if (!m_disabled && m_cycle_count<0) { |
---|
121 | | m_cycle_count = cycle; |
---|
122 | | m_cycle_ofs = 0.0; |
---|
123 | | } |
---|
124 | | |
---|
125 | | // Do housekeeping expected for all packets sent to the MOTU, even |
---|
126 | | // for packets containing no audio data. |
---|
127 | | *sy = 0x00; |
---|
128 | | *tag = 1; // All MOTU packets have a CIP-like header |
---|
129 | | |
---|
130 | | debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "get packet...\n"); |
---|
131 | | |
---|
132 | | // Size of a single data frame in quadlets |
---|
133 | | unsigned dbs = m_event_size / 4; |
---|
134 | | |
---|
135 | | // The number of events expected by the MOTU is solely dependent on |
---|
136 | | // the current sample rate. An 'event' is one sample from all channels |
---|
137 | | // plus possibly other midi and control data. |
---|
138 | | signed n_events = m_framerate<=48000?8:(m_framerate<=96000?16:32); |
---|
| 179 | last_us = tv.tv_usec; |
---|
| 905 | |
---|
| 906 | #if 1 |
---|
| 907 | /* FIXME: test whether things are improved by doing this in the |
---|
| 908 | * actual receive handler. The advantage is that we don't have to |
---|
| 909 | * wait until the stream is enabled before the DLL starts tracking. |
---|
| 910 | * This has the desireable side-effect of having a relatively |
---|
| 911 | * accurate value in the DLL by the time the transmit stream is |
---|
| 912 | * enabled. A disadvantage of having this in here is that it |
---|
| 913 | * increases the time spent in this function. Whether this is |
---|
| 914 | * important in practice remains to be seen. Ad hoc evidence thus |
---|
| 915 | * far seems to suggest that it does increase the chances of a |
---|
| 916 | * faulty startup, but more tests are needed. |
---|
| 917 | */ |
---|
| 918 | /* Push cycle offset differences from each event's SPH into the DLL. |
---|
| 919 | * If this is the very first block received, use the first event to |
---|
| 920 | * initialise the last cycle offset. |
---|
| 921 | * FIXME: it might be best to use differences only within the given |
---|
| 922 | * block rather than keeping a store of the last cycle offset. |
---|
| 923 | * Otherwise in the event of a lost incoming packet the DLL will |
---|
| 924 | * have an abnormally large value sent to it. Perhaps this doesn't |
---|
| 925 | * matter? |
---|
| 926 | */ |
---|
| 927 | unsigned int ev; |
---|
| 928 | signed int sph_ofs = ntohl(*(quadlet_t *)(data+8)) & 0xfff; |
---|
| 929 | |
---|
| 930 | // if (m_last_cycle_ofs < 0) { |
---|
| 931 | // m_last_cycle_ofs = sph_ofs-(int)m_sph_ofs_dll->get(); |
---|
| 932 | // } |
---|
| 933 | m_last_cycle_ofs = sph_ofs; |
---|
| 934 | for (ev=1; ev<n_events; ev++) { |
---|
| 935 | sph_ofs = ntohl(*(quadlet_t *)(data+8+ev*m_event_size)) & 0xfff; |
---|
| 936 | m_sph_ofs_dll->put((m_last_cycle_ofs<sph_ofs)? |
---|
| 937 | sph_ofs-m_last_cycle_ofs:sph_ofs+3072-m_last_cycle_ofs); |
---|
| 938 | m_last_cycle_ofs = sph_ofs; |
---|
| 939 | } |
---|
| 940 | #endif |
---|
| 941 | |
---|
| 942 | |
---|