root/branches/ppalmers-streaming/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

Revision 721, 23.7 kB (checked in by ppalmers, 13 years ago)

another update

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 bool
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 = 5;
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     debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
132                 "Gen HDR: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
133                 cycle,
134                 transmit_at_cycle, cycles_until_transmit,
135                 transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
136                 presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
137
138     // two different options:
139     // 1) there are not enough frames for one packet
140     //      => determine wether this is a problem, since we might still
141     //         have some time to send it
142     // 2) there are enough packets
143     //      => determine whether we have to send them in this packet
144     if ( fc < ( signed int ) m_syt_interval )
145     {
146         // not enough frames in the buffer,
147
148         // we can still postpone the queueing of the packets
149         // if we are far enough ahead of the presentation time
150         if ( cycles_until_presentation <= min_cycles_before_presentation )
151         {
152             debugOutput ( DEBUG_LEVEL_VERBOSE,
153                         "Insufficient frames (P): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
154                         fc, cycle, transmit_at_cycle, cycles_until_transmit );
155             // we are too late
156             // meaning that we in some sort of xrun state
157             // signal xrun situation ??HERE??
158             m_xruns++;
159             // we send an empty packet on this cycle
160             return false;
161         }
162         else
163         {
164             debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
165                         "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n",
166                         fc, cycle, transmit_at_cycle, cycles_until_transmit );
167             // there is still time left to send the packet
168             // we want the system to give this packet another go
169     //             goto try_packet_again; // UGLY but effective
170             // unfortunatly the try_again doesn't work very well,
171             // so we'll have to either usleep(one cycle) and goto try_block_of_frames
172
173             // or just fill this with an empty packet
174             // if we have to do this too often, the presentation time will
175             // get too close and we're in trouble
176             return false;
177         }
178     }
179     else
180     {
181         // there are enough frames, so check the time they are intended for
182         // all frames have a certain 'time window' in which they can be sent
183         // this corresponds to the range of the timestamp mechanism:
184         // we can send a packet 15 cycles in advance of the 'presentation time'
185         // in theory we can send the packet up till one cycle before the presentation time,
186         // however this is not very smart.
187
188         // There are 3 options:
189         // 1) the frame block is too early
190         //      => send an empty packet
191         // 2) the frame block is within the window
192         //      => send it
193         // 3) the frame block is too late
194         //      => discard (and raise xrun?)
195         //         get next block of frames and repeat
196
197         if ( cycles_until_transmit <= max_cycles_to_transmit_early )
198         {
199             // it's time send the packet
200             m_dbc += fillDataPacketHeader ( packet, length, m_last_timestamp );
201             return true;
202         }
203         else if ( cycles_until_transmit < 0 )
204         {
205             // we are too late
206             debugOutput ( DEBUG_LEVEL_VERBOSE,
207                         "Too late: CY=%04u, TC=%04u, CUT=%04d, TSP=%011llu (%04u)\n",
208                         cycle,
209                         transmit_at_cycle, cycles_until_transmit,
210                         presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
211
212             // however, if we can send this sufficiently before the presentation
213             // time, it could be harmless.
214             // NOTE: dangerous since the device has no way of reporting that it didn't get
215             //       this packet on time.
216             if ( cycles_until_presentation <= min_cycles_before_presentation )
217             {
218                 // we are not that late and can still try to transmit the packet
219                 m_dbc += fillDataPacketHeader ( packet, length, m_last_timestamp );
220                 return true;
221             }
222             else   // definitely too late
223             {
224                 // remove the samples
225                 m_data_buffer->dropFrames ( m_syt_interval );
226                 // signal some xrun situation ??HERE??
227                 m_xruns++;
228                 // try a new block of frames
229                 goto try_block_of_frames; // UGLY but effective
230             }
231         }
232         else
233         {
234             debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
235                         "Too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
236                         cycle,
237                         transmit_at_cycle, cycles_until_transmit,
238                         transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
239                         presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
240 #ifdef DEBUG
241             if ( cycles_until_transmit > max_cycles_to_transmit_early + 1 )
242             {
243                 debugOutput ( DEBUG_LEVEL_VERY_VERBOSE,
244                             "Way too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n",
245                             cycle,
246                             transmit_at_cycle, cycles_until_transmit,
247                             transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ),
248                             presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) );
249             }
250 #endif
251             // we are too early, send only an empty packet
252             return false;
253         }
254     }
255     return true;
256 }
257
258 bool
259 AmdtpTransmitStreamProcessor::generatePacketData (
260     unsigned char *data, unsigned int *length,
261     unsigned char *tag, unsigned char *sy,
262     int cycle, unsigned int dropped, unsigned int max_length )
263 {
264     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
265     if ( m_data_buffer->readFrames ( m_syt_interval, ( char * ) ( data + 8 ) ) )
266     {
267         // process all ports that should be handled on a per-packet base
268         // this is MIDI for AMDTP (due to the need of DBC)
269         if ( !encodePacketPorts ( ( quadlet_t * ) ( data+8 ), m_syt_interval, packet->dbc ) )
270         {
271             debugWarning ( "Problem encoding Packet Ports\n" );
272         }
273         debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, "XMIT DATA: TSP=%011llu (%04u)\n",
274                     cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) );
275         return true;
276     }
277     else
278     {
279         return false;
280     }
281 }
282
283 bool
284 AmdtpTransmitStreamProcessor::generateSilentPacketHeader (
285     unsigned char *data, unsigned int *length,
286     unsigned char *tag, unsigned char *sy,
287     int cycle, unsigned int dropped, unsigned int max_length )
288 {
289     struct iec61883_packet *packet = ( struct iec61883_packet * ) data;
290     debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, "XMIT NONE: CY=%04u, TSP=%011llu (%04u)\n",
291                 cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) );
292
293     /* Our node ID can change after a bus reset, so it is best to fetch
294     * our node ID for each packet. */
295     packet->sid = m_handler->getLocalNodeId() & 0x3f;
296
297     packet->dbs = m_dimension;
298     packet->fn = 0;
299     packet->qpc = 0;
300     packet->sph = 0;
301     packet->reserved = 0;
302     packet->dbc = m_dbc;
303     packet->eoh1 = 2;
304     packet->fmt = IEC61883_FMT_AMDTP;
305
306     *tag = IEC61883_TAG_WITH_CIP;
307     *sy = 0;
308
309     m_dbc += fillNoDataPacketHeader ( packet, length );
310     return true;
311 }
312
313 bool
314 AmdtpTransmitStreamProcessor::generateSilentPacketData (
315     unsigned char *data, unsigned int *length,
316     unsigned char *tag, unsigned char *sy,
317     int cycle, unsigned int dropped, unsigned int max_length )
318 {
319     return true; // no need to do anything
320 }
321
322 unsigned int AmdtpTransmitStreamProcessor::fillDataPacketHeader (
323     struct iec61883_packet *packet, unsigned int* length,
324     uint32_t ts )
325 {
326
327     packet->fdf = m_fdf;
328
329     // convert the timestamp to SYT format
330     uint16_t timestamp_SYT = TICKS_TO_SYT ( ts );
331     packet->syt = ntohs ( timestamp_SYT );
332
333     *length = m_syt_interval*sizeof ( quadlet_t ) *m_dimension + 8;
334
335     return m_syt_interval;
336 }
337
338 unsigned int AmdtpTransmitStreamProcessor::fillNoDataPacketHeader (
339     struct iec61883_packet *packet, unsigned int* length )
340 {
341
342     // no-data packets have syt=0xFFFF
343     // and have the usual amount of events as dummy data (?)
344     packet->fdf = IEC61883_FDF_NODATA;
345     packet->syt = 0xffff;
346
347     // FIXME: either make this a setting or choose
348     bool send_payload=true;
349     if ( send_payload )
350     {
351         // this means no-data packets with payload (DICE doesn't like that)
352         *length = 2*sizeof ( quadlet_t ) + m_syt_interval * m_dimension * sizeof ( quadlet_t );
353         return m_syt_interval;
354     }
355     else
356     {
357         // dbc is not incremented
358         // this means no-data packets without payload
359         *length = 2*sizeof ( quadlet_t );
360         return 0;
361     }
362 }
363
364 unsigned int
365 AmdtpTransmitStreamProcessor::getPacketsPerPeriod()
366 {
367     return ( m_manager->getPeriodSize() ) /m_syt_interval;
368 }
369
370 bool AmdtpTransmitStreamProcessor::prepareChild()
371 {
372     debugOutput ( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this );
373     switch ( m_manager->getNominalRate() )
374     {
375         case 32000:
376             m_syt_interval = 8;
377             m_fdf = IEC61883_FDF_SFC_32KHZ;
378             break;
379         case 44100:
380             m_syt_interval = 8;
381             m_fdf = IEC61883_FDF_SFC_44K1HZ;
382             break;
383         default:
384         case 48000:
385             m_syt_interval = 8;
386             m_fdf = IEC61883_FDF_SFC_48KHZ;
387             break;
388         case 88200:
389             m_syt_interval = 16;
390             m_fdf = IEC61883_FDF_SFC_88K2HZ;
391             break;
392         case 96000:
393             m_syt_interval = 16;
394             m_fdf = IEC61883_FDF_SFC_96KHZ;
395             break;
396         case 176400:
397             m_syt_interval = 32;
398             m_fdf = IEC61883_FDF_SFC_176K4HZ;
399             break;
400         case 192000:
401             m_syt_interval = 32;
402             m_fdf = IEC61883_FDF_SFC_192KHZ;
403             break;
404     }
405
406     iec61883_cip_init (
407         &m_cip_status,
408         IEC61883_FMT_AMDTP,
409         m_fdf,
410         m_manager->getNominalRate(),
411         m_dimension,
412         m_syt_interval );
413
414     for ( PortVectorIterator it = m_Ports.begin();
415             it != m_Ports.end();
416             ++it )
417     {
418         if ( ( *it )->getPortType() == Port::E_Midi )
419         {
420             // we use a timing unit of 10ns
421             // this makes sure that for the max syt interval
422             // we don't have rounding, and keeps the numbers low
423             // we have 1 slot every 8 events
424             // we have syt_interval events per packet
425             // => syt_interval/8 slots per packet
426             // packet rate is 8000pkt/sec => interval=125us
427             // so the slot interval is (1/8000)/(syt_interval/8)
428             // or: 1/(1000 * syt_interval) sec
429             // which is 1e9/(1000*syt_interval) nsec
430             // or 100000/syt_interval 'units'
431             // the event interval is fixed to 320us = 32000 'units'
432             if ( ! ( *it )->useRateControl ( true, ( 100000/m_syt_interval ),32000, false ) )
433             {
434                 debugFatal ( "Could not set signal type to PeriodSignalling" );
435                 return false;
436             }
437             break;
438         }
439     }
440
441     debugOutput ( DEBUG_LEVEL_VERBOSE, "Prepared for:\n" );
442     debugOutput ( DEBUG_LEVEL_VERBOSE, " Samplerate: %d, FDF: %d, DBS: %d, SYT: %d\n",
443                 m_manager->getNominalRate(), m_fdf, m_dimension, m_syt_interval );
444     debugOutput ( DEBUG_LEVEL_VERBOSE, " PeriodSize: %d, NbBuffers: %d\n",
445                 m_manager->getPeriodSize(), m_manager->getNbBuffers() );
446     debugOutput ( DEBUG_LEVEL_VERBOSE, " Port: %d, Channel: %d\n",
447                 m_port,m_channel );
448     return true;
449 }
450
451 /*
452 * compose the event streams for the packets from the port buffers
453 */
454 bool AmdtpTransmitStreamProcessor::processWriteBlock ( char *data,
455         unsigned int nevents, unsigned int offset )
456 {
457     bool no_problem=true;
458
459     for ( PortVectorIterator it = m_PeriodPorts.begin();
460             it != m_PeriodPorts.end();
461             ++it )
462     {
463
464         if ( ( *it )->isDisabled() ) {continue;};
465
466         //FIXME: make this into a static_cast when not DEBUG?
467
468         AmdtpPortInfo *pinfo=dynamic_cast<AmdtpPortInfo *> ( *it );
469         assert ( pinfo ); // this should not fail!!
470
471         switch ( pinfo->getFormat() )
472         {
473             case AmdtpPortInfo::E_MBLA:
474                 if ( encodePortToMBLAEvents ( static_cast<AmdtpAudioPort *> ( *it ), ( quadlet_t * ) data, offset, nevents ) )
475                 {
476                     debugWarning ( "Could not encode port %s to MBLA events", ( *it )->getName().c_str() );
477                     no_problem=false;
478                 }
479                 break;
480             case AmdtpPortInfo::E_SPDIF: // still unimplemented
481                 break;
482             default: // ignore
483                 break;
484         }
485     }
486     return no_problem;
487 }
488
489 bool AmdtpTransmitStreamProcessor::transmitSilenceBlock ( char *data,
490         unsigned int nevents, unsigned int offset )
491 {
492     bool problem = false;
493     for ( PortVectorIterator it = m_PeriodPorts.begin();
494             it != m_PeriodPorts.end();
495             ++it )
496     {
497         //FIXME: make this into a static_cast when not DEBUG?
498         AmdtpPortInfo *pinfo=dynamic_cast<AmdtpPortInfo *> ( *it );
499         assert ( pinfo ); // this should not fail!!
500
501         switch ( pinfo->getFormat() )
502         {
503             case AmdtpPortInfo::E_MBLA:
504                 if ( encodeSilencePortToMBLAEvents ( static_cast<AmdtpAudioPort *> ( *it ), ( quadlet_t * ) data, offset, nevents ) )
505                 {
506                     debugWarning ( "Could not encode port %s to MBLA events", ( *it )->getName().c_str() );
507                     problem = true;
508                 }
509                 break;
510             case AmdtpPortInfo::E_SPDIF: // still unimplemented
511                 break;
512             default: // ignore
513                 break;
514         }
515     }
516     return problem;
517 }
518
519 /**
520 * @brief decode a packet for the packet-based ports
521 *
522 * @param data Packet data
523 * @param nevents number of events in data (including events of other ports & port types)
524 * @param dbc DataBlockCount value for this packet
525 * @return true if all successfull
526 */
527 bool AmdtpTransmitStreamProcessor::encodePacketPorts ( quadlet_t *data, unsigned int nevents, unsigned int dbc )
528 {
529     bool ok=true;
530     quadlet_t byte;
531
532     quadlet_t *target_event=NULL;
533     unsigned int j;
534
535     for ( PortVectorIterator it = m_PacketPorts.begin();
536             it != m_PacketPorts.end();
537             ++it )
538     {
539
540 #ifdef DEBUG
541         AmdtpPortInfo *pinfo=dynamic_cast<AmdtpPortInfo *> ( *it );
542         assert ( pinfo ); // this should not fail!!
543
544         // the only packet type of events for AMDTP is MIDI in mbla
545         assert ( pinfo->getFormat() ==AmdtpPortInfo::E_Midi );
546 #endif
547
548         AmdtpMidiPort *mp=static_cast<AmdtpMidiPort *> ( *it );
549
550         // we encode this directly (no function call) due to the high frequency
551         /* idea:
552         spec says: current_midi_port=(dbc+j)%8;
553         => if we start at (dbc+stream->location-1)%8,
554         we'll start at the right event for the midi port.
555         => if we increment j with 8, we stay at the right event.
556         */
557         // FIXME: as we know in advance how big a packet is (syt_interval) we can
558         //        predict how much loops will be present here
559         // first prefill the buffer with NO_DATA's on all time muxed channels
560
561         for ( j = ( dbc & 0x07 ) +mp->getLocation(); j < nevents; j += 8 )
562         {
563
564             quadlet_t tmpval;
565
566             target_event= ( quadlet_t * ) ( data + ( ( j * m_dimension ) + mp->getPosition() ) );
567
568             if ( mp->canRead() )   // we can send a byte
569             {
570                 mp->readEvent ( &byte );
571                 byte &= 0xFF;
572                 tmpval=htonl (
573                         IEC61883_AM824_SET_LABEL ( ( byte ) <<16,
574                                                     IEC61883_AM824_LABEL_MIDI_1X ) );
575
576                 debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "MIDI port %s, pos=%d, loc=%d, dbc=%d, nevents=%d, dim=%d\n",
577                             mp->getName().c_str(), mp->getPosition(), mp->getLocation(), dbc, nevents, m_dimension );
578                 debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "base=%p, target=%p, value=%08X\n",
579                             data, target_event, tmpval );
580
581             }
582             else
583             {
584                 // can't send a byte, either because there is no byte,
585                 // or because this would exceed the maximum rate
586                 tmpval=htonl (
587                         IEC61883_AM824_SET_LABEL ( 0,IEC61883_AM824_LABEL_MIDI_NO_DATA ) );
588             }
589
590             *target_event=tmpval;
591         }
592
593     }
594     return ok;
595 }
596
597
598 int AmdtpTransmitStreamProcessor::encodePortToMBLAEvents ( AmdtpAudioPort *p, quadlet_t *data,
599         unsigned int offset, unsigned int nevents )
600 {
601     unsigned int j=0;
602
603     quadlet_t *target_event;
604
605     target_event= ( quadlet_t * ) ( data + p->getPosition() );
606
607     switch ( p->getDataType() )
608     {
609         default:
610         case Port::E_Int24:
611         {
612             quadlet_t *buffer= ( quadlet_t * ) ( p->getBufferAddress() );
613
614             assert ( nevents + offset <= p->getBufferSize() );
615
616             buffer+=offset;
617
618             for ( j = 0; j < nevents; j += 1 )   // decode max nsamples
619             {
620                 *target_event = htonl ( ( * ( buffer ) & 0x00FFFFFF ) | 0x40000000 );
621                 buffer++;
622                 target_event += m_dimension;
623             }
624         }
625         break;
626         case Port::E_Float:
627         {
628             const float multiplier = ( float ) ( 0x7FFFFF00 );
629             float *buffer= ( float * ) ( p->getBufferAddress() );
630
631             assert ( nevents + offset <= p->getBufferSize() );
632
633             buffer+=offset;
634
635             for ( j = 0; j < nevents; j += 1 )   // decode max nsamples
636             {
637
638                 // don't care for overflow
639                 float v = *buffer * multiplier;  // v: -231 .. 231
640                 unsigned int tmp = ( ( int ) v );
641                 *target_event = htonl ( ( tmp >> 8 ) | 0x40000000 );
642
643                 buffer++;
644                 target_event += m_dimension;
645             }
646         }
647         break;
648     }
649
650     return 0;
651 }
652 int AmdtpTransmitStreamProcessor::encodeSilencePortToMBLAEvents ( AmdtpAudioPort *p, quadlet_t *data,
653         unsigned int offset, unsigned int nevents )
654 {
655     unsigned int j=0;
656
657     quadlet_t *target_event;
658
659     target_event= ( quadlet_t * ) ( data + p->getPosition() );
660
661     switch ( p->getDataType() )
662     {
663         default:
664         case Port::E_Int24:
665         case Port::E_Float:
666         {
667             for ( j = 0; j < nevents; j += 1 )   // decode max nsamples
668             {
669                 *target_event = htonl ( 0x40000000 );
670                 target_event += m_dimension;
671             }
672         }
673         break;
674     }
675
676     return 0;
677 }
678
679 } // end of namespace Streaming
Note: See TracBrowser for help on using the browser.