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

Revision 750, 23.0 kB (checked in by ppalmers, 13 years ago)

Code refactoring. Tries to simplify things and tries to put all code where it belongs.

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