root/branches/ppalmers-streaming/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

Revision 732, 23.4 kB (checked in by ppalmers, 16 years ago)

reorganize motu SP files to prepare for updated streaming implementation (disfunctional)

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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #include "AmdtpTransmitStreamProcessor.h"
25 #include "AmdtpPort.h"
26 #include "../StreamProcessorManager.h"
27
28 #include "../util/cycletimer.h"
29
30 #include <netinet/in.h>
31 #include <assert.h>
32
33 // in ticks
34 // as per AMDTP2.1:
35 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks
36 #define DEFAULT_TRANSFER_DELAY (11776U)
37
38 #define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY
39
40 namespace Streaming
41 {
42
43 /* transmit */
44 AmdtpTransmitStreamProcessor::AmdtpTransmitStreamProcessor ( int port, int dimension )
45         : StreamProcessor ( ePT_Transmit, port )
46         , m_dimension ( dimension )
47         , m_dbc ( 0 )
48 {}
49
50 enum StreamProcessor::eChildReturnValue
51 AmdtpTransmitStreamProcessor::generatePacketHeader (
52     unsigned char *data, unsigned int *length,
53     unsigned char *tag, unsigned char *sy,
54     int cycle, unsigned int dropped, unsigned int max_length )
55 {
56     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
57     /* Our node ID can change after a bus reset, so it is best to fetch
58     * our node ID for each packet. */
59     packet->sid = m_handler->getLocalNodeId() & 0x3f;
60
61     packet->dbs = m_dimension;
62     packet->fn = 0;
63     packet->qpc = 0;
64     packet->sph = 0;
65     packet->reserved = 0;
66     packet->dbc = m_dbc;
67     packet->eoh1 = 2;
68     packet->fmt = IEC61883_FMT_AMDTP;
69
70     *tag = IEC61883_TAG_WITH_CIP;
71     *sy = 0;
72
73     signed int fc;
74     uint64_t presentation_time;
75     unsigned int presentation_cycle;
76     int cycles_until_presentation;
77
78     uint64_t transmit_at_time;
79     unsigned int transmit_at_cycle;
80     int cycles_until_transmit;
81
82     // FIXME: should become a define
83     // the absolute minimum number of cycles we want to transmit
84     // a packet ahead of the presentation time. The nominal time
85     // the packet is transmitted ahead of the presentation time is
86     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we
87     // are too late for that, this constant defines how late we can
88     // be.
89     const int min_cycles_before_presentation = 1;
90     // FIXME: should become a define
91     // the absolute maximum number of cycles we want to transmit
92     // a packet ahead of the ideal transmit time. The nominal time
93     // the packet is transmitted ahead of the presentation time is
94     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send
95     // packets early if we want to. (not completely according to spec)
96     const int max_cycles_to_transmit_early = 2;
97
98 try_block_of_frames:
99     debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "Try for cycle %d\n", cycle );
100     // check whether the packet buffer has packets for us to send.
101     // the base timestamp is the one of the next sample in the buffer
102     ffado_timestamp_t ts_head_tmp;
103     m_data_buffer->getBufferHeadTimestamp ( &ts_head_tmp, &fc ); // thread safe
104
105     // the timestamp gives us the time at which we want the sample block
106     // to be output by the device
107     presentation_time = ( uint64_t ) ts_head_tmp;
108     m_last_timestamp = presentation_time;
109
110     // now we calculate the time when we have to transmit the sample block
111     transmit_at_time = substractTicks ( presentation_time, TRANSMIT_TRANSFER_DELAY );
112
113     // calculate the cycle this block should be presented in
114     // (this is just a virtual calculation since at that time it should
115     //  already be in the device's buffer)
116     presentation_cycle = ( unsigned int ) ( TICKS_TO_CYCLES ( presentation_time ) );
117
118     // calculate the cycle this block should be transmitted in
119     transmit_at_cycle = ( unsigned int ) ( TICKS_TO_CYCLES ( transmit_at_time ) );
120
121     // we can check whether this cycle is within the 'window' we have
122     // to send this packet.
123     // first calculate the number of cycles left before presentation time
124     cycles_until_presentation = diffCycles ( presentation_cycle, cycle );
125
126     // we can check whether this cycle is within the 'window' we have
127     // to send this packet.
128     // first calculate the number of cycles left before presentation time
129     cycles_until_transmit = diffCycles ( transmit_at_cycle, cycle );
130
131     if (dropped) {
132         debugOutput ( DEBUG_LEVEL_VERBOSE,
133                     "Gen HDR: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
134                     cycle,
135                     transmit_at_cycle, cycles_until_transmit,
136                     transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
137                     presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
138     }
139     // two different options:
140     // 1) there are not enough frames for one packet
141     //      => determine wether this is a problem, since we might still
142     //         have some time to send it
143     // 2) there are enough packets
144     //      => determine whether we have to send them in this packet
145     if ( fc < ( signed int ) m_syt_interval )
146     {
147         // not enough frames in the buffer,
148
149         // we can still postpone the queueing of the packets
150         // if we are far enough ahead of the presentation time
151         if ( cycles_until_presentation <= min_cycles_before_presentation )
152         {
153             debugOutput ( DEBUG_LEVEL_VERBOSE,
154                         "Insufficient frames (P): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
155                         fc, cycle, transmit_at_cycle, cycles_until_transmit );
156             // we are too late
157             return eCRV_XRun;
158         }
159         else
160         {
161             debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
162                         "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
163                         fc, cycle, transmit_at_cycle, cycles_until_transmit );
164             // there is still time left to send the packet
165             // we want the system to give this packet another go at a later time instant
166             return eCRV_Again;
167         }
168     }
169     else
170     {
171         // there are enough frames, so check the time they are intended for
172         // all frames have a certain 'time window' in which they can be sent
173         // this corresponds to the range of the timestamp mechanism:
174         // we can send a packet 15 cycles in advance of the 'presentation time'
175         // in theory we can send the packet up till one cycle before the presentation time,
176         // however this is not very smart.
177
178         // There are 3 options:
179         // 1) the frame block is too early
180         //      => send an empty packet
181         // 2) the frame block is within the window
182         //      => send it
183         // 3) the frame block is too late
184         //      => discard (and raise xrun?)
185         //         get next block of frames and repeat
186
187         if(cycles_until_transmit < 0)
188         {
189             // we are too late
190             debugOutput(DEBUG_LEVEL_VERBOSE,
191                         "Too late: CY=%04u, TC=%04u, CUT=%04d, TSP=%011llu (%04u)\n",
192                         cycle,
193                         transmit_at_cycle, cycles_until_transmit,
194                         presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time) );
195
196             // however, if we can send this sufficiently before the presentation
197             // time, it could be harmless.
198             // NOTE: dangerous since the device has no way of reporting that it didn't get
199             //       this packet on time.
200             if(cycles_until_presentation >= min_cycles_before_presentation)
201             {
202                 // we are not that late and can still try to transmit the packet
203                 m_dbc += fillDataPacketHeader(packet, length, m_last_timestamp);
204                 return eCRV_Packet;
205             }
206             else   // definitely too late
207             {
208                 return eCRV_XRun;
209             }
210         }
211         else if(cycles_until_transmit <= max_cycles_to_transmit_early)
212         {
213             // it's time send the packet
214             m_dbc += fillDataPacketHeader(packet, length, m_last_timestamp);
215             return eCRV_Packet;
216         }
217         else
218         {
219             debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
220                         "Too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
221                         cycle,
222                         transmit_at_cycle, cycles_until_transmit,
223                         transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
224                         presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
225 #ifdef DEBUG
226             if ( cycles_until_transmit > max_cycles_to_transmit_early + 1 )
227             {
228                 debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
229                             "Way too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
230                             cycle,
231                             transmit_at_cycle, cycles_until_transmit,
232                             transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
233                             presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
234             }
235 #endif
236             // we are too early, send only an empty packet
237             return eCRV_EmptyPacket;
238         }
239     }
240     return eCRV_Invalid;
241 }
242
243 enum StreamProcessor::eChildReturnValue
244 AmdtpTransmitStreamProcessor::generatePacketData (
245     unsigned char *data, unsigned int *length,
246     unsigned char *tag, unsigned char *sy,
247     int cycle, unsigned int dropped, unsigned int max_length )
248 {
249     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
250     if ( m_data_buffer->readFrames ( m_syt_interval, ( char * ) ( data + 8 ) ) )
251     {
252         // process all ports that should be handled on a per-packet base
253         // this is MIDI for AMDTP (due to the need of DBC)
254         if ( !encodePacketPorts ( ( quadlet_t * ) ( data+8 ), m_syt_interval, packet->dbc ) )
255         {
256             debugWarning ( "Problem encoding Packet Ports\n" );
257         }
258         debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, "XMIT DATA: TSP=%011llu (%04u)\n",
259                     cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) );
260         return eCRV_OK;
261     }
262     else return eCRV_XRun;
263
264 }
265
266 enum StreamProcessor::eChildReturnValue
267 AmdtpTransmitStreamProcessor::generateSilentPacketHeader (
268     unsigned char *data, unsigned int *length,
269     unsigned char *tag, unsigned char *sy,
270     int cycle, unsigned int dropped, unsigned int max_length )
271 {
272     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
273     debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, "XMIT NONE: CY=%04u, TSP=%011llu (%04u)\n",
274                 cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) );
275
276     /* Our node ID can change after a bus reset, so it is best to fetch
277     * our node ID for each packet. */
278     packet->sid = m_handler->getLocalNodeId() & 0x3f;
279
280     packet->dbs = m_dimension;
281     packet->fn = 0;
282     packet->qpc = 0;
283     packet->sph = 0;
284     packet->reserved = 0;
285     packet->dbc = m_dbc;
286     packet->eoh1 = 2;
287     packet->fmt = IEC61883_FMT_AMDTP;
288
289     *tag = IEC61883_TAG_WITH_CIP;
290     *sy = 0;
291
292     m_dbc += fillNoDataPacketHeader ( packet, length );
293     return eCRV_OK;
294 }
295
296 enum StreamProcessor::eChildReturnValue
297 AmdtpTransmitStreamProcessor::generateSilentPacketData (
298     unsigned char *data, unsigned int *length,
299     unsigned char *tag, unsigned char *sy,
300     int cycle, unsigned int dropped, unsigned int max_length )
301 {
302     return eCRV_OK; // no need to do anything
303 }
304
305 unsigned int AmdtpTransmitStreamProcessor::fillDataPacketHeader (
306     struct iec61883_packet *packet, unsigned int* length,
307     uint32_t ts )
308 {
309
310     packet->fdf = m_fdf;
311
312     // convert the timestamp to SYT format
313     uint16_t timestamp_SYT = TICKS_TO_SYT ( ts );
314     packet->syt = ntohs ( timestamp_SYT );
315
316     *length = m_syt_interval*sizeof ( quadlet_t ) *m_dimension + 8;
317
318     return m_syt_interval;
319 }
320
321 unsigned int AmdtpTransmitStreamProcessor::fillNoDataPacketHeader (
322     struct iec61883_packet *packet, unsigned int* length )
323 {
324
325     // no-data packets have syt=0xFFFF
326     // and have the usual amount of events as dummy data (?)
327     packet->fdf = IEC61883_FDF_NODATA;
328     packet->syt = 0xffff;
329
330     // FIXME: either make this a setting or choose
331     bool send_payload=true;
332     if ( send_payload )
333     {
334         // this means no-data packets with payload (DICE doesn't like that)
335         *length = 2*sizeof ( quadlet_t ) + m_syt_interval * m_dimension * sizeof ( quadlet_t );
336         return m_syt_interval;
337     }
338     else
339     {
340         // dbc is not incremented
341         // this means no-data packets without payload
342         *length = 2*sizeof ( quadlet_t );
343         return 0;
344     }
345 }
346
347 unsigned int
348 AmdtpTransmitStreamProcessor::getNominalPacketsNeeded(unsigned int nframes)
349 {
350     unsigned int nominal_frames_per_second = m_manager->getNominalRate();
351     uint64_t nominal_ticks_per_frame = TICKS_PER_SECOND / nominal_frames_per_second;
352     uint64_t nominal_ticks = nominal_ticks_per_frame * nframes;
353     uint64_t nominal_packets = nominal_ticks / TICKS_PER_CYCLE;
354     return nominal_packets;
355 }
356
357 unsigned int
358 AmdtpTransmitStreamProcessor::getPacketsPerPeriod()
359 {
360     return getNominalPacketsNeeded(m_manager->getPeriodSize());
361 }
362
363 bool AmdtpTransmitStreamProcessor::prepareChild()
364 {
365     debugOutput ( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this );
366     switch ( m_manager->getNominalRate() )
367     {
368         case 32000:
369             m_syt_interval = 8;
370             m_fdf = IEC61883_FDF_SFC_32KHZ;
371             break;
372         case 44100:
373             m_syt_interval = 8;
374             m_fdf = IEC61883_FDF_SFC_44K1HZ;
375             break;
376         default:
377         case 48000:
378             m_syt_interval = 8;
379             m_fdf = IEC61883_FDF_SFC_48KHZ;
380             break;
381         case 88200:
382             m_syt_interval = 16;
383             m_fdf = IEC61883_FDF_SFC_88K2HZ;
384             break;
385         case 96000:
386             m_syt_interval = 16;
387             m_fdf = IEC61883_FDF_SFC_96KHZ;
388             break;
389         case 176400:
390             m_syt_interval = 32;
391             m_fdf = IEC61883_FDF_SFC_176K4HZ;
392             break;
393         case 192000:
394             m_syt_interval = 32;
395             m_fdf = IEC61883_FDF_SFC_192KHZ;
396             break;
397     }
398
399     iec61883_cip_init (
400         &m_cip_status,
401         IEC61883_FMT_AMDTP,
402         m_fdf,
403         m_manager->getNominalRate(),
404         m_dimension,
405         m_syt_interval );
406
407     for ( PortVectorIterator it = m_Ports.begin();
408             it != m_Ports.end();
409             ++it )
410     {
411         if ( ( *it )->getPortType() == Port::E_Midi )
412         {
413             // we use a timing unit of 10ns
414             // this makes sure that for the max syt interval
415             // we don't have rounding, and keeps the numbers low
416             // we have 1 slot every 8 events
417             // we have syt_interval events per packet
418             // => syt_interval/8 slots per packet
419             // packet rate is 8000pkt/sec => interval=125us
420             // so the slot interval is (1/8000)/(syt_interval/8)
421             // or: 1/(1000 * syt_interval) sec
422             // which is 1e9/(1000*syt_interval) nsec
423             // or 100000/syt_interval 'units'
424             // the event interval is fixed to 320us = 32000 'units'
425             if ( ! ( *it )->useRateControl ( true, ( 100000/m_syt_interval ),32000, false ) )
426             {
427                 debugFatal ( "Could not set signal type to PeriodSignalling" );
428                 return false;
429             }
430             break;
431         }
432     }
433
434     debugOutput ( DEBUG_LEVEL_VERBOSE, "Prepared for:\n" );
435     debugOutput ( DEBUG_LEVEL_VERBOSE, " Samplerate: %d, FDF: %d, DBS: %d, SYT: %d\n",
436                 m_manager->getNominalRate(), m_fdf, m_dimension, m_syt_interval );
437     debugOutput ( DEBUG_LEVEL_VERBOSE, " PeriodSize: %d, NbBuffers: %d\n",
438                 m_manager->getPeriodSize(), m_manager->getNbBuffers() );
439     debugOutput ( DEBUG_LEVEL_VERBOSE, " Port: %d, Channel: %d\n",
440                 m_port,m_channel );
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.