root/trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

Revision 766, 23.8 kB (checked in by ppalmers, 13 years ago)

introduce local references to frequently used objects

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "AmdtpTransmitStreamProcessor.h"
25 #include "AmdtpPort.h"
26 #include "../StreamProcessorManager.h"
27 #include "devicemanager.h"
28
29 #include "libieee1394/ieee1394service.h"
30 #include "libieee1394/IsoHandlerManager.h"
31 #include "libieee1394/cycletimer.h"
32
33 #include <netinet/in.h>
34 #include <assert.h>
35
36 // in ticks
37 // as per AMDTP2.1:
38 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks
39 #define DEFAULT_TRANSFER_DELAY (11776U)
40
41 #define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY
42
43 namespace Streaming
44 {
45
46 /* transmit */
47 AmdtpTransmitStreamProcessor::AmdtpTransmitStreamProcessor(FFADODevice &parent, int dimension)
48         : StreamProcessor(parent, ePT_Transmit)
49         , m_dimension( dimension )
50         , m_dbc( 0 )
51 {}
52
53 enum StreamProcessor::eChildReturnValue
54 AmdtpTransmitStreamProcessor::generatePacketHeader (
55     unsigned char *data, unsigned int *length,
56     unsigned char *tag, unsigned char *sy,
57     int cycle, unsigned int dropped, unsigned int max_length )
58 {
59     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
60     /* Our node ID can change after a bus reset, so it is best to fetch
61     * our node ID for each packet. */
62     packet->sid = m_1394service.getLocalNodeId() & 0x3f;
63
64     packet->dbs = m_dimension;
65     packet->fn = 0;
66     packet->qpc = 0;
67     packet->sph = 0;
68     packet->reserved = 0;
69     packet->dbc = m_dbc;
70     packet->eoh1 = 2;
71     packet->fmt = IEC61883_FMT_AMDTP;
72
73     *tag = IEC61883_TAG_WITH_CIP;
74     *sy = 0;
75
76     signed int fc;
77     uint64_t presentation_time;
78     unsigned int presentation_cycle;
79     int cycles_until_presentation;
80
81     uint64_t transmit_at_time;
82     unsigned int transmit_at_cycle;
83     int cycles_until_transmit;
84
85     // FIXME: should become a define
86     // the absolute minimum number of cycles we want to transmit
87     // a packet ahead of the presentation time. The nominal time
88     // the packet is transmitted ahead of the presentation time is
89     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we
90     // are too late for that, this constant defines how late we can
91     // be.
92     const int min_cycles_before_presentation = 1;
93     // FIXME: should become a define
94     // the absolute maximum number of cycles we want to transmit
95     // a packet ahead of the ideal transmit time. The nominal time
96     // the packet is transmitted ahead of the presentation time is
97     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send
98     // packets early if we want to. (not completely according to spec)
99     const int max_cycles_to_transmit_early = 2;
100
101 try_block_of_frames:
102     debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "Try for cycle %d\n", cycle );
103     // check whether the packet buffer has packets for us to send.
104     // the base timestamp is the one of the next sample in the buffer
105     ffado_timestamp_t ts_head_tmp;
106     m_data_buffer->getBufferHeadTimestamp ( &ts_head_tmp, &fc ); // thread safe
107
108     // the timestamp gives us the time at which we want the sample block
109     // to be output by the device
110     presentation_time = ( uint64_t ) ts_head_tmp;
111     m_last_timestamp = presentation_time;
112
113     // now we calculate the time when we have to transmit the sample block
114     transmit_at_time = substractTicks ( presentation_time, TRANSMIT_TRANSFER_DELAY );
115
116     // calculate the cycle this block should be presented in
117     // (this is just a virtual calculation since at that time it should
118     //  already be in the device's buffer)
119     presentation_cycle = ( unsigned int ) ( TICKS_TO_CYCLES ( presentation_time ) );
120
121     // calculate the cycle this block should be transmitted in
122     transmit_at_cycle = ( unsigned int ) ( TICKS_TO_CYCLES ( transmit_at_time ) );
123
124     // we can check whether this cycle is within the 'window' we have
125     // to send this packet.
126     // first calculate the number of cycles left before presentation time
127     cycles_until_presentation = diffCycles ( presentation_cycle, cycle );
128
129     // we can check whether this cycle is within the 'window' we have
130     // to send this packet.
131     // first calculate the number of cycles left before presentation time
132     cycles_until_transmit = diffCycles ( transmit_at_cycle, cycle );
133
134     if (dropped) {
135         debugOutput ( DEBUG_LEVEL_VERBOSE,
136                     "Gen HDR: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
137                     cycle,
138                     transmit_at_cycle, cycles_until_transmit,
139                     transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
140                     presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
141     }
142     // two different options:
143     // 1) there are not enough frames for one packet
144     //      => determine wether this is a problem, since we might still
145     //         have some time to send it
146     // 2) there are enough packets
147     //      => determine whether we have to send them in this packet
148     if ( fc < ( signed int ) m_syt_interval )
149     {
150         // not enough frames in the buffer,
151
152         // we can still postpone the queueing of the packets
153         // if we are far enough ahead of the presentation time
154         if ( cycles_until_presentation <= min_cycles_before_presentation )
155         {
156             debugOutput ( DEBUG_LEVEL_VERBOSE,
157                         "Insufficient frames (P): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
158                         fc, cycle, transmit_at_cycle, cycles_until_transmit );
159             // we are too late
160             return eCRV_XRun;
161         }
162         else
163         {
164             debugOutput ( DEBUG_LEVEL_VERBOSE,
165                         "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
166                         fc, cycle, transmit_at_cycle, cycles_until_transmit );
167             debugWarning( "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
168                           fc, cycle, transmit_at_cycle, cycles_until_transmit );
169             // there is still time left to send the packet
170             // we want the system to give this packet another go at a later time instant
171             return eCRV_Again; // note that the raw1394 again system doesn't work as expected
172
173             // we could wait here for a certain time before trying again. However, this
174             // is not going to work since we then block the iterator thread, hence also
175             // the receiving code, meaning that we are not processing received packets,
176             // and hence there is no progression in the number of frames available.
177
178             // for example:
179             // usleep(125); // one cycle
180             // goto try_block_of_frames;
181
182             // or more advanced, calculate how many cycles we are ahead of 'now' and
183             // base the sleep on that.
184
185             // note that this requires that there is one thread for each IsoHandler,
186             // otherwise we're in the deadlock described above.
187         }
188     }
189     else
190     {
191         // there are enough frames, so check the time they are intended for
192         // all frames have a certain 'time window' in which they can be sent
193         // this corresponds to the range of the timestamp mechanism:
194         // we can send a packet 15 cycles in advance of the 'presentation time'
195         // in theory we can send the packet up till one cycle before the presentation time,
196         // however this is not very smart.
197
198         // There are 3 options:
199         // 1) the frame block is too early
200         //      => send an empty packet
201         // 2) the frame block is within the window
202         //      => send it
203         // 3) the frame block is too late
204         //      => discard (and raise xrun?)
205         //         get next block of frames and repeat
206
207         if(cycles_until_transmit < 0)
208         {
209             // we are too late
210             debugOutput(DEBUG_LEVEL_VERBOSE,
211                         "Too late: CY=%04u, TC=%04u, CUT=%04d, TSP=%011llu (%04u)\n",
212                         cycle,
213                         transmit_at_cycle, cycles_until_transmit,
214                         presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time) );
215
216             // however, if we can send this sufficiently before the presentation
217             // time, it could be harmless.
218             // NOTE: dangerous since the device has no way of reporting that it didn't get
219             //       this packet on time.
220             if(cycles_until_presentation >= min_cycles_before_presentation)
221             {
222                 // we are not that late and can still try to transmit the packet
223                 m_dbc += fillDataPacketHeader(packet, length, m_last_timestamp);
224                 return (fc < (signed)(2*m_syt_interval) ? eCRV_Defer : eCRV_Packet);
225             }
226             else   // definitely too late
227             {
228                 return eCRV_XRun;
229             }
230         }
231         else if(cycles_until_transmit <= max_cycles_to_transmit_early)
232         {
233             // it's time send the packet
234             m_dbc += fillDataPacketHeader(packet, length, m_last_timestamp);
235             return (fc < (signed)(2*m_syt_interval) ? eCRV_Defer : eCRV_Packet);
236         }
237         else
238         {
239             debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
240                         "Too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
241                         cycle,
242                         transmit_at_cycle, cycles_until_transmit,
243                         transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
244                         presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
245 #ifdef DEBUG
246             if ( cycles_until_transmit > max_cycles_to_transmit_early + 1 )
247             {
248                 debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
249                             "Way too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
250                             cycle,
251                             transmit_at_cycle, cycles_until_transmit,
252                             transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
253                             presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
254             }
255 #endif
256             // we are too early, send only an empty packet
257             return eCRV_EmptyPacket;
258         }
259     }
260     return eCRV_Invalid;
261 }
262
263 enum StreamProcessor::eChildReturnValue
264 AmdtpTransmitStreamProcessor::generatePacketData (
265     unsigned char *data, unsigned int *length,
266     unsigned char *tag, unsigned char *sy,
267     int cycle, unsigned int dropped, unsigned int max_length )
268 {
269     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
270     if ( m_data_buffer->readFrames ( m_syt_interval, ( char * ) ( data + 8 ) ) )
271     {
272         // process all ports that should be handled on a per-packet base
273         // this is MIDI for AMDTP (due to the need of DBC)
274         if ( !encodePacketPorts ( ( quadlet_t * ) ( data+8 ), m_syt_interval, packet->dbc ) )
275         {
276             debugWarning ( "Problem encoding Packet Ports\n" );
277         }
278         debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, "XMIT DATA: TSP=%011llu (%04u)\n",
279                     cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) );
280         return eCRV_OK;
281     }
282     else return eCRV_XRun;
283
284 }
285
286 enum StreamProcessor::eChildReturnValue
287 AmdtpTransmitStreamProcessor::generateSilentPacketHeader (
288     unsigned char *data, unsigned int *length,
289     unsigned char *tag, unsigned char *sy,
290     int cycle, unsigned int dropped, unsigned int max_length )
291 {
292     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
293     debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, "XMIT NONE: CY=%04u, TSP=%011llu (%04u)\n",
294                 cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) );
295
296     /* Our node ID can change after a bus reset, so it is best to fetch
297     * our node ID for each packet. */
298     packet->sid = m_1394service.getLocalNodeId() & 0x3f;
299
300     packet->dbs = m_dimension;
301     packet->fn = 0;
302     packet->qpc = 0;
303     packet->sph = 0;
304     packet->reserved = 0;
305     packet->dbc = m_dbc;
306     packet->eoh1 = 2;
307     packet->fmt = IEC61883_FMT_AMDTP;
308
309     *tag = IEC61883_TAG_WITH_CIP;
310     *sy = 0;
311
312     m_dbc += fillNoDataPacketHeader ( packet, length );
313     return eCRV_OK;
314 }
315
316 enum StreamProcessor::eChildReturnValue
317 AmdtpTransmitStreamProcessor::generateSilentPacketData (
318     unsigned char *data, unsigned int *length,
319     unsigned char *tag, unsigned char *sy,
320     int cycle, unsigned int dropped, unsigned int max_length )
321 {
322     return eCRV_OK; // no need to do anything
323 }
324
325 unsigned int AmdtpTransmitStreamProcessor::fillDataPacketHeader (
326     struct iec61883_packet *packet, unsigned int* length,
327     uint32_t ts )
328 {
329
330     packet->fdf = m_fdf;
331
332     // convert the timestamp to SYT format
333     uint16_t timestamp_SYT = TICKS_TO_SYT ( ts );
334     packet->syt = ntohs ( timestamp_SYT );
335
336     *length = m_syt_interval*sizeof ( quadlet_t ) *m_dimension + 8;
337
338     return m_syt_interval;
339 }
340
341 unsigned int AmdtpTransmitStreamProcessor::fillNoDataPacketHeader (
342     struct iec61883_packet *packet, unsigned int* length )
343 {
344
345     // no-data packets have syt=0xFFFF
346     // and have the usual amount of events as dummy data (?)
347     packet->fdf = IEC61883_FDF_NODATA;
348     packet->syt = 0xffff;
349
350     // FIXME: either make this a setting or choose
351     bool send_payload=true;
352     if ( send_payload )
353     {
354         // this means no-data packets with payload (DICE doesn't like that)
355         *length = 2*sizeof ( quadlet_t ) + m_syt_interval * m_dimension * sizeof ( quadlet_t );
356         return m_syt_interval;
357     }
358     else
359     {
360         // dbc is not incremented
361         // this means no-data packets without payload
362         *length = 2*sizeof ( quadlet_t );
363         return 0;
364     }
365 }
366
367 unsigned int
368 AmdtpTransmitStreamProcessor::getSytInterval() {
369     switch (m_StreamProcessorManager.getNominalRate()) {
370         case 32000:
371         case 44100:
372         case 48000:
373             return 8;
374         case 88200:
375         case 96000:
376             return 16;
377         case 176400:
378         case 192000:
379             return 32;
380         default:
381             debugError("Unsupported rate: %d\n", m_StreamProcessorManager.getNominalRate());
382             return 0;
383     }
384 }
385 unsigned int
386 AmdtpTransmitStreamProcessor::getFDF() {
387     switch (m_StreamProcessorManager.getNominalRate()) {
388         case 32000: return IEC61883_FDF_SFC_32KHZ;
389         case 44100: return IEC61883_FDF_SFC_44K1HZ;
390         case 48000: return IEC61883_FDF_SFC_48KHZ;
391         case 88200: return IEC61883_FDF_SFC_88K2HZ;
392         case 96000: return IEC61883_FDF_SFC_96KHZ;
393         case 176400: return IEC61883_FDF_SFC_176K4HZ;
394         case 192000: return IEC61883_FDF_SFC_192KHZ;
395         default:
396             debugError("Unsupported rate: %d\n", m_StreamProcessorManager.getNominalRate());
397             return 0;
398     }
399 }
400
401 bool AmdtpTransmitStreamProcessor::prepareChild()
402 {
403     debugOutput ( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this );
404     m_syt_interval = getSytInterval();
405     m_fdf = getFDF();
406
407     iec61883_cip_init (
408         &m_cip_status,
409         IEC61883_FMT_AMDTP,
410         m_fdf,
411         m_StreamProcessorManager.getNominalRate(),
412         m_dimension,
413         m_syt_interval );
414
415     for ( PortVectorIterator it = m_Ports.begin();
416             it != m_Ports.end();
417             ++it )
418     {
419         if ( ( *it )->getPortType() == Port::E_Midi )
420         {
421             // we use a timing unit of 10ns
422             // this makes sure that for the max syt interval
423             // we don't have rounding, and keeps the numbers low
424             // we have 1 slot every 8 events
425             // we have syt_interval events per packet
426             // => syt_interval/8 slots per packet
427             // packet rate is 8000pkt/sec => interval=125us
428             // so the slot interval is (1/8000)/(syt_interval/8)
429             // or: 1/(1000 * syt_interval) sec
430             // which is 1e9/(1000*syt_interval) nsec
431             // or 100000/syt_interval 'units'
432             // the event interval is fixed to 320us = 32000 'units'
433             if ( ! ( *it )->useRateControl ( true, ( 100000/m_syt_interval ),32000, false ) )
434             {
435                 debugFatal ( "Could not set signal type to PeriodSignalling" );
436                 return false;
437             }
438             break;
439         }
440     }
441     return true;
442 }
443
444 /*
445 * compose the event streams for the packets from the port buffers
446 */
447 bool AmdtpTransmitStreamProcessor::processWriteBlock ( char *data,
448         unsigned int nevents, unsigned int offset )
449 {
450     bool no_problem = true;
451
452     for ( PortVectorIterator it = m_PeriodPorts.begin();
453           it != m_PeriodPorts.end();
454           ++it )
455     {
456         if ( (*it)->isDisabled() ) { continue; };
457
458         //FIXME: make this into a static_cast when not DEBUG?
459         AmdtpPortInfo *pinfo = dynamic_cast<AmdtpPortInfo *> ( *it );
460         assert ( pinfo ); // this should not fail!!
461
462         switch( pinfo->getFormat() )
463         {
464             case AmdtpPortInfo::E_MBLA:
465                 if( encodePortToMBLAEvents(static_cast<AmdtpAudioPort *>(*it), (quadlet_t *)data, offset, nevents) )
466                 {
467                     debugWarning ( "Could not encode port %s to MBLA events", (*it)->getName().c_str() );
468                     no_problem = false;
469                 }
470                 break;
471             case AmdtpPortInfo::E_SPDIF: // still unimplemented
472                 break;
473             default: // ignore
474                 break;
475         }
476     }
477     return no_problem;
478 }
479
480 bool
481 AmdtpTransmitStreamProcessor::transmitSilenceBlock(
482     char *data, unsigned int nevents, unsigned int offset)
483 {
484     bool no_problem = true;
485     for(PortVectorIterator it = m_PeriodPorts.begin();
486         it != m_PeriodPorts.end();
487         ++it )
488     {
489         //FIXME: make this into a static_cast when not DEBUG?
490         AmdtpPortInfo *pinfo=dynamic_cast<AmdtpPortInfo *>(*it);
491         assert(pinfo); // this should not fail!!
492
493         switch( pinfo->getFormat() )
494         {
495             case AmdtpPortInfo::E_MBLA:
496                 if ( encodeSilencePortToMBLAEvents(static_cast<AmdtpAudioPort *>(*it), (quadlet_t *)data, offset, nevents) )
497                 {
498                     debugWarning("Could not encode port %s to MBLA events", (*it)->getName().c_str());
499                     no_problem = false;
500                 }
501                 break;
502             case AmdtpPortInfo::E_SPDIF: // still unimplemented
503                 break;
504             default: // ignore
505                 break;
506         }
507     }
508     return no_problem;
509 }
510
511 /**
512 * @brief decode a packet for the packet-based ports
513 *
514 * @param data Packet data
515 * @param nevents number of events in data (including events of other ports & port types)
516 * @param dbc DataBlockCount value for this packet
517 * @return true if all successfull
518 */
519 bool AmdtpTransmitStreamProcessor::encodePacketPorts ( quadlet_t *data, unsigned int nevents, unsigned int dbc )
520 {
521     bool ok=true;
522     quadlet_t byte;
523
524     quadlet_t *target_event=NULL;
525     unsigned int j;
526
527     for ( PortVectorIterator it = m_PacketPorts.begin();
528             it != m_PacketPorts.end();
529             ++it )
530     {
531
532 #ifdef DEBUG
533         AmdtpPortInfo *pinfo=dynamic_cast<AmdtpPortInfo *> ( *it );
534         assert ( pinfo ); // this should not fail!!
535
536         // the only packet type of events for AMDTP is MIDI in mbla
537         assert ( pinfo->getFormat() ==AmdtpPortInfo::E_Midi );
538 #endif
539
540         AmdtpMidiPort *mp=static_cast<AmdtpMidiPort *> ( *it );
541
542         // we encode this directly (no function call) due to the high frequency
543         /* idea:
544         spec says: current_midi_port=(dbc+j)%8;
545         => if we start at (dbc+stream->location-1)%8,
546         we'll start at the right event for the midi port.
547         => if we increment j with 8, we stay at the right event.
548         */
549         // FIXME: as we know in advance how big a packet is (syt_interval) we can
550         //        predict how much loops will be present here
551         // first prefill the buffer with NO_DATA's on all time muxed channels
552
553         for ( j = ( dbc & 0x07 ) +mp->getLocation(); j < nevents; j += 8 )
554         {
555
556             quadlet_t tmpval;
557
558             target_event= ( quadlet_t * ) ( data + ( ( j * m_dimension ) + mp->getPosition() ) );
559
560             if ( mp->canRead() )   // we can send a byte
561             {
562                 mp->readEvent ( &byte );
563                 byte &= 0xFF;
564                 tmpval=htonl (
565                         IEC61883_AM824_SET_LABEL ( ( byte ) <<16,
566                                                     IEC61883_AM824_LABEL_MIDI_1X ) );
567
568                 debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "MIDI port %s, pos=%d, loc=%d, dbc=%d, nevents=%d, dim=%d\n",
569                             mp->getName().c_str(), mp->getPosition(), mp->getLocation(), dbc, nevents, m_dimension );
570                 debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "base=%p, target=%p, value=%08X\n",
571                             data, target_event, tmpval );
572
573             }
574             else
575             {
576                 // can't send a byte, either because there is no byte,
577                 // or because this would exceed the maximum rate
578                 tmpval=htonl (
579                         IEC61883_AM824_SET_LABEL ( 0,IEC61883_AM824_LABEL_MIDI_NO_DATA ) );
580             }
581
582             *target_event=tmpval;
583         }
584
585     }
586     return ok;
587 }
588
589
590 int AmdtpTransmitStreamProcessor::encodePortToMBLAEvents ( AmdtpAudioPort *p, quadlet_t *data,
591         unsigned int offset, unsigned int nevents )
592 {
593     unsigned int j=0;
594
595     quadlet_t *target_event;
596
597     target_event= ( quadlet_t * ) ( data + p->getPosition() );
598
599     switch ( p->getDataType() )
600     {
601         default:
602         case Port::E_Int24:
603         {
604             quadlet_t *buffer= ( quadlet_t * ) ( p->getBufferAddress() );
605
606             assert ( nevents + offset <= p->getBufferSize() );
607
608             buffer+=offset;
609
610             for ( j = 0; j < nevents; j += 1 )   // decode max nsamples
611             {
612                 *target_event = htonl ( ( * ( buffer ) & 0x00FFFFFF ) | 0x40000000 );
613                 buffer++;
614                 target_event += m_dimension;
615             }
616         }
617         break;
618         case Port::E_Float:
619         {
620             const float multiplier = ( float ) ( 0x7FFFFF00 );
621             float *buffer= ( float * ) ( p->getBufferAddress() );
622
623             assert ( nevents + offset <= p->getBufferSize() );
624
625             buffer+=offset;
626
627             for ( j = 0; j < nevents; j += 1 )   // decode max nsamples
628             {
629
630                 // don't care for overflow
631                 float v = *buffer * multiplier;  // v: -231 .. 231
632                 unsigned int tmp = ( ( int ) v );
633                 *target_event = htonl ( ( tmp >> 8 ) | 0x40000000 );
634
635                 buffer++;
636                 target_event += m_dimension;
637             }
638         }
639         break;
640     }
641
642     return 0;
643 }
644 int AmdtpTransmitStreamProcessor::encodeSilencePortToMBLAEvents ( AmdtpAudioPort *p, quadlet_t *data,
645         unsigned int offset, unsigned int nevents )
646 {
647     unsigned int j=0;
648
649     quadlet_t *target_event;
650
651     target_event= ( quadlet_t * ) ( data + p->getPosition() );
652
653     switch ( p->getDataType() )
654     {
655         default:
656         case Port::E_Int24:
657         case Port::E_Float:
658         {
659             for ( j = 0; j < nevents; j += 1 )   // decode max nsamples
660             {
661                 *target_event = htonl ( 0x40000000 );
662                 target_event += m_dimension;
663             }
664         }
665         break;
666     }
667
668     return 0;
669 }
670
671 } // end of namespace Streaming
Note: See TracBrowser for help on using the browser.