1 /*****************************************************************************
2 * lpcm.c: lpcm decoder/packetizer module
3 *****************************************************************************
4 * Copyright (C) 1999-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Henri Fallon <henri@videolan.org>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Gildas Bazin <gbazin@videolan.org>
11 * Lauren Aimar <fenrir _AT_ videolan _DOT_ org >
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_codec.h>
41 /*****************************************************************************
43 *****************************************************************************/
44 static int OpenDecoder ( vlc_object_t * );
45 static int OpenPacketizer( vlc_object_t * );
46 static void CloseCommon ( vlc_object_t * );
50 set_category( CAT_INPUT )
51 set_subcategory( SUBCAT_INPUT_ACODEC )
52 set_description( N_("Linear PCM audio decoder") )
53 set_capability( "decoder", 100 )
54 set_callbacks( OpenDecoder, CloseCommon )
57 set_description( N_("Linear PCM audio packetizer") )
58 set_capability( "packetizer", 100 )
59 set_callbacks( OpenPacketizer, CloseCommon )
64 /*****************************************************************************
65 * decoder_sys_t : lpcm decoder descriptor
66 *****************************************************************************/
78 unsigned i_header_size;
84 * - frame number (8 bits)
85 * - unknown (16 bits) == 0x0003 ?
87 * - current frame (4 bits)
89 * - frequency (2 bits) 0 == 48 kHz, 1 == 32 kHz, 2 == ?, 3 == ?
91 * - number of channels - 1 (3 bits) 1 == 2 channels
92 * - start code (8 bits) == 0x80
94 * LPCM DVD-A header (http://dvd-audio.sourceforge.net/spec/aob.shtml)
95 * - continuity counter (8 bits, clipped to 0x00-0x1f)
96 * - header size (16 bits)
97 * - byte pointer to start of first audio frame.
98 * - unknown (8bits, 0x10 for stereo, 0x00 for surround)
99 * - sample size (4+4 bits)
100 * - samplerate (4+4 bits)
102 * - group assignment (8 bits)
104 * - padding(variable)
108 * - number of channels (4 bits)
109 * - frequency (4 bits)
110 * - bits per sample (2 bits)
114 #define LPCM_VOB_HEADER_LEN (6)
115 #define LPCM_AOB_HEADER_LEN (11)
116 #define LPCM_BD_HEADER_LEN (4)
129 unsigned pi_position[6];
132 /*****************************************************************************
134 *****************************************************************************/
135 static void *DecodeFrame ( decoder_t *, block_t ** );
138 static int VobHeader( unsigned *pi_rate,
139 unsigned *pi_channels, unsigned *pi_original_channels,
141 const uint8_t *p_header );
142 static void VobExtract( aout_buffer_t *, block_t *, unsigned i_bits );
144 static int AobHeader( unsigned *pi_rate,
145 unsigned *pi_channels, unsigned *pi_layout,
147 unsigned *pi_padding,
149 const uint8_t *p_header );
150 static void AobExtract( aout_buffer_t *, block_t *, unsigned i_bits, aob_group_t p_group[2] );
152 static int BdHeader( unsigned *pi_rate,
153 unsigned *pi_channels, unsigned *pi_original_channels,
155 const uint8_t *p_header );
156 static void BdExtract( aout_buffer_t *, block_t * );
159 /*****************************************************************************
161 *****************************************************************************/
162 static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
164 decoder_t *p_dec = (decoder_t*)p_this;
165 decoder_sys_t *p_sys;
169 switch( p_dec->fmt_in.i_codec )
172 case VLC_CODEC_DVD_LPCM:
174 i_header_size = LPCM_VOB_HEADER_LEN;
177 case VLC_CODEC_DVDA_LPCM:
179 i_header_size = LPCM_AOB_HEADER_LEN;
182 case VLC_CODEC_BD_LPCM:
184 i_header_size = LPCM_BD_HEADER_LEN;
190 /* Allocate the memory needed to store the decoder's structure */
191 if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL )
195 p_sys->b_packetizer = b_packetizer;
196 date_Set( &p_sys->end_date, 0 );
197 p_sys->i_type = i_type;
198 p_sys->i_header_size = i_header_size;
200 /* Set output properties */
201 p_dec->fmt_out.i_cat = AUDIO_ES;
208 p_dec->fmt_out.i_codec = VLC_CODEC_DVD_LPCM;
211 p_dec->fmt_out.i_codec = VLC_CODEC_DVDA_LPCM;
216 p_dec->fmt_out.i_codec = VLC_CODEC_BD_LPCM;
222 switch( p_dec->fmt_out.audio.i_bitspersample )
226 p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
227 p_dec->fmt_out.audio.i_bitspersample = 24;
230 p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
231 p_dec->fmt_out.audio.i_bitspersample = 16;
237 p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
239 p_dec->pf_packetize = (block_t *(*)(decoder_t *, block_t **))
244 static int OpenDecoder( vlc_object_t *p_this )
246 return OpenCommon( p_this, false );
248 static int OpenPacketizer( vlc_object_t *p_this )
250 return OpenCommon( p_this, true );
253 /*****************************************************************************
254 * DecodeFrame: decodes an lpcm frame.
255 ****************************************************************************
256 * Beware, this function must be fed with complete frames (PES packet).
257 *****************************************************************************/
258 static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
260 decoder_sys_t *p_sys = p_dec->p_sys;
262 unsigned int i_rate = 0, i_original_channels = 0, i_channels = 0, i_bits = 0;
265 if( !pp_block || !*pp_block ) return NULL;
268 *pp_block = NULL; /* So the packet doesn't get re-sent */
270 /* Date management */
271 if( p_block->i_pts > 0 &&
272 p_block->i_pts != date_Get( &p_sys->end_date ) )
274 date_Set( &p_sys->end_date, p_block->i_pts );
277 if( !date_Get( &p_sys->end_date ) )
279 /* We've just started the stream, wait for the first PTS. */
280 block_Release( p_block );
284 if( p_block->i_buffer <= p_sys->i_header_size )
286 msg_Err(p_dec, "frame is too short");
287 block_Release( p_block );
292 unsigned i_padding = 0;
293 aob_group_t p_aob_group[2];
294 switch( p_sys->i_type )
297 i_ret = VobHeader( &i_rate, &i_channels, &i_original_channels, &i_bits,
301 i_ret = AobHeader( &i_rate, &i_channels, &i_original_channels, &i_bits, &i_padding,
306 i_ret = BdHeader( &i_rate, &i_channels, &i_original_channels, &i_bits,
313 if( i_ret || p_block->i_buffer <= p_sys->i_header_size + i_padding )
315 msg_Warn( p_dec, "no frame sync or too small frame" );
316 block_Release( p_block );
320 /* Set output properties */
321 if( p_dec->fmt_out.audio.i_rate != i_rate )
323 date_Init( &p_sys->end_date, i_rate, 1 );
324 date_Set( &p_sys->end_date, p_block->i_pts );
326 p_dec->fmt_out.audio.i_rate = i_rate;
327 p_dec->fmt_out.audio.i_channels = i_channels;
328 p_dec->fmt_out.audio.i_original_channels = i_original_channels;
329 p_dec->fmt_out.audio.i_physical_channels = i_original_channels & AOUT_CHAN_PHYSMASK;
331 i_frame_length = (p_block->i_buffer - p_sys->i_header_size - i_padding) / i_channels * 8 / i_bits;
333 if( p_sys->b_packetizer )
335 p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
337 date_Increment( &p_sys->end_date, i_frame_length ) -
340 /* Just pass on the incoming frame */
348 p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
349 p_dec->fmt_out.audio.i_bitspersample = 16;
353 p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
354 p_dec->fmt_out.audio.i_bitspersample = 24;
358 aout_buffer_t *p_aout_buffer;
359 p_aout_buffer = decoder_NewAudioBuffer( p_dec, i_frame_length );
363 p_aout_buffer->start_date = date_Get( &p_sys->end_date );
364 p_aout_buffer->end_date =
365 date_Increment( &p_sys->end_date, i_frame_length );
367 p_block->p_buffer += p_sys->i_header_size + i_padding;
368 p_block->i_buffer -= p_sys->i_header_size + i_padding;
370 switch( p_sys->i_type )
373 VobExtract( p_aout_buffer, p_block, i_bits );
376 AobExtract( p_aout_buffer, p_block, i_bits, p_aob_group );
381 BdExtract( p_aout_buffer, p_block );
385 block_Release( p_block );
386 return p_aout_buffer;
390 /*****************************************************************************
391 * CloseCommon : lpcm decoder destruction
392 *****************************************************************************/
393 static void CloseCommon( vlc_object_t *p_this )
395 decoder_t *p_dec = (decoder_t*)p_this;
396 free( p_dec->p_sys );
399 /*****************************************************************************
401 *****************************************************************************/
402 static int VobHeader( unsigned *pi_rate,
403 unsigned *pi_channels, unsigned *pi_original_channels,
405 const uint8_t *p_header )
407 const uint8_t i_header = p_header[4];
409 switch( (i_header >> 4) & 0x3 )
425 *pi_channels = (i_header & 0x7) + 1;
426 switch( *pi_channels - 1 )
429 *pi_original_channels = AOUT_CHAN_CENTER;
432 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
435 /* This is unsure. */
436 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE;
439 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
440 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
443 /* This is unsure. */
444 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
445 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
449 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
450 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
451 | AOUT_CHAN_CENTER | AOUT_CHAN_LFE;
454 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
455 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
456 | AOUT_CHAN_CENTER | AOUT_CHAN_MIDDLELEFT
457 | AOUT_CHAN_MIDDLERIGHT;
460 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
461 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
462 | AOUT_CHAN_CENTER | AOUT_CHAN_MIDDLELEFT
463 | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE;
467 switch( (i_header >> 6) & 0x3 )
481 /* Check frame sync and drop it. */
482 if( p_header[5] != 0x80 )
487 static const unsigned p_aob_group1[21][6] = {
488 { AOUT_CHAN_CENTER, 0 },
489 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
490 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
491 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
492 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
493 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
494 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
495 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
496 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
497 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
498 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
499 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
500 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, 0 },
501 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
502 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
503 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
504 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
505 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, 0 },
506 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
507 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
508 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
510 static const unsigned p_aob_group2[21][6] = {
513 { AOUT_CHAN_REARCENTER, 0 },
514 { AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
515 { AOUT_CHAN_LFE, 0 },
516 { AOUT_CHAN_LFE, AOUT_CHAN_REARCENTER, 0 },
517 { AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
518 { AOUT_CHAN_CENTER, 0 },
519 { AOUT_CHAN_CENTER, AOUT_CHAN_REARCENTER, 0 },
520 { AOUT_CHAN_CENTER, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
521 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 },
522 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, AOUT_CHAN_REARCENTER, 0 },
523 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
524 { AOUT_CHAN_REARCENTER, 0 },
525 { AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
526 { AOUT_CHAN_LFE, 0 },
527 { AOUT_CHAN_LFE, AOUT_CHAN_REARCENTER, 0 },
528 { AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, 0 },
529 { AOUT_CHAN_LFE, 0 },
530 { AOUT_CHAN_CENTER, 0 },
531 { AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 },
534 static int AobHeader( unsigned *pi_rate,
535 unsigned *pi_channels, unsigned *pi_layout,
537 unsigned *pi_padding,
539 const uint8_t *p_header )
541 const unsigned i_header_size = GetWBE( &p_header[1] );
542 if( i_header_size + 3 < LPCM_AOB_HEADER_LEN )
545 *pi_padding = 3+i_header_size - LPCM_AOB_HEADER_LEN;
547 const int i_index_size_g1 = (p_header[6] >> 4) & 0x0f;
548 const int i_index_size_g2 = (p_header[6] ) & 0x0f;
549 const int i_index_rate_g1 = (p_header[7] >> 4) & 0x0f;
550 const int i_index_rate_g2 = (p_header[7] ) & 0x0f;
551 const int i_assignment = p_header[9];
554 if( i_index_size_g1 > 0x02 ||
555 ( i_index_size_g2 != 0x0f && i_index_size_g2 > 0x02 ) )
557 if( (i_index_rate_g1 & 0x07) > 0x02 ||
558 ( i_index_rate_g2 != 0x0f && (i_index_rate_g1 & 0x07) > 0x02 ) )
560 if( i_assignment > 20 )
564 *pi_bits = 16 + 4 * i_index_size_g1;
565 if( i_index_rate_g1 & 0x08 )
566 *pi_rate = 44100 << (i_index_rate_g1 & 0x07);
568 *pi_rate = 48000 << (i_index_rate_g1 & 0x07);
572 unsigned i_channels1 = 0;
573 unsigned i_layout1 = 0;
574 for( int i = 0; p_aob_group1[i_assignment][i] != 0; i++ )
577 i_layout1 |= p_aob_group1[i_assignment][i];
580 unsigned i_channels2 = 0;
581 unsigned i_layout2 = 0;
582 if( i_index_size_g2 != 0x0f && i_index_rate_g2 != 0x0f )
584 for( int i = 0; p_aob_group2[i_assignment][i] != 0; i++ )
587 i_layout2 |= p_aob_group2[i_assignment][i];
589 assert( (i_layout1 & i_layout2) == 0 );
591 /* It is enabled only when presents and compatible wih group1 */
592 const bool b_group2_used = i_index_size_g1 == i_index_size_g2 &&
593 i_index_rate_g1 == i_index_rate_g2;
596 *pi_channels = i_channels1 + ( b_group2_used ? i_channels2 : 0 );
597 *pi_layout = i_layout1 | ( b_group2_used ? i_layout2 : 0 );
600 for( unsigned i = 0; i < 2; i++ )
602 const unsigned *p_aob = i == 0 ? p_aob_group1[i_assignment] :
603 p_aob_group2[i_assignment];
604 g[i].i_channels = i == 0 ? i_channels1 :
607 g[i].b_used = i == 0 || b_group2_used;
610 for( unsigned j = 0; j < g[i].i_channels; j++ )
612 g[i].pi_position[j] = 0;
613 for( int k = 0; pi_vlc_chan_order_wg4[k] != 0; k++ )
615 const unsigned i_channel = pi_vlc_chan_order_wg4[k];
616 if( i_channel == p_aob[j] )
618 if( (*pi_layout) & i_channel )
619 g[i].pi_position[j]++;
626 static int BdHeader( unsigned *pi_rate,
627 unsigned *pi_channels, unsigned *pi_original_channels,
629 const uint8_t *p_header )
631 const uint32_t h = GetDWBE( p_header );
632 switch( ( h & 0xf000) >> 12 )
636 *pi_original_channels = AOUT_CHAN_CENTER;
640 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
644 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER;
648 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER;
652 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
653 AOUT_CHAN_REARCENTER;
657 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
658 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
662 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
663 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
667 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
668 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
673 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
674 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
675 AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT;
679 *pi_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
680 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
681 AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT |
688 switch( (h >> 6) & 0x03 )
693 case 2: /* 20 bits but samples are stored on 24 bits */
694 case 3: /* 24 bits */
700 switch( (h >> 8) & 0x0f )
717 static void VobExtract( aout_buffer_t *p_aout_buffer, block_t *p_block,
720 uint8_t *p_out = p_aout_buffer->p_buffer;
722 /* 20/24 bits LPCM use special packing */
725 while( p_block->i_buffer / 12 )
728 p_out[0] = p_block->p_buffer[0];
729 p_out[1] = p_block->p_buffer[1];
730 p_out[2] = p_block->p_buffer[8];
732 p_out[3] = p_block->p_buffer[2];
733 p_out[4] = p_block->p_buffer[3];
734 p_out[5] = p_block->p_buffer[9];
736 p_out[6] = p_block->p_buffer[4];
737 p_out[7] = p_block->p_buffer[5];
738 p_out[8] = p_block->p_buffer[10];
740 p_out[9] = p_block->p_buffer[6];
741 p_out[10] = p_block->p_buffer[7];
742 p_out[11] = p_block->p_buffer[11];
744 p_block->i_buffer -= 12;
745 p_block->p_buffer += 12;
749 else if( i_bits == 20 )
751 while( p_block->i_buffer / 10 )
754 p_out[0] = p_block->p_buffer[0];
755 p_out[1] = p_block->p_buffer[1];
756 p_out[2] = p_block->p_buffer[8] & 0xF0;
758 p_out[3] = p_block->p_buffer[2];
759 p_out[4] = p_block->p_buffer[3];
760 p_out[5] = p_block->p_buffer[8] << 4;
762 p_out[6] = p_block->p_buffer[4];
763 p_out[7] = p_block->p_buffer[5];
764 p_out[8] = p_block->p_buffer[9] & 0xF0;
766 p_out[9] = p_block->p_buffer[6];
767 p_out[10] = p_block->p_buffer[7];
768 p_out[11] = p_block->p_buffer[9] << 4;
770 p_block->i_buffer -= 10;
771 p_block->p_buffer += 10;
777 assert( i_bits == 16 );
778 memcpy( p_out, p_block->p_buffer, p_block->i_buffer );
781 static void AobExtract( aout_buffer_t *p_aout_buffer,
782 block_t *p_block, unsigned i_bits, aob_group_t p_group[2] )
784 const unsigned i_channels = p_group[0].i_channels +
785 ( p_group[1].b_used ? p_group[1].i_channels : 0 );
786 uint8_t *p_out = p_aout_buffer->p_buffer;
788 while( p_block->i_buffer > 0 )
790 for( int i = 0; i < 2; i++ )
792 const aob_group_t *g = &p_group[1-i];
793 const unsigned int i_group_size = 2 * g->i_channels * i_bits / 8;
795 if( p_block->i_buffer < i_group_size )
797 p_block->i_buffer = 0;
800 for( unsigned n = 0; n < 2; n++ )
802 for( unsigned j = 0; j < g->i_channels && g->b_used; j++ )
804 const int i_src = n * g->i_channels + j;
805 const int i_dst = n * i_channels + g->pi_position[j];
809 p_out[3*i_dst+0] = p_block->p_buffer[2*i_src+0];
810 p_out[3*i_dst+1] = p_block->p_buffer[2*i_src+1];
811 p_out[3*i_dst+2] = p_block->p_buffer[4*g->i_channels+i_src];
813 else if( i_bits == 20 )
815 p_out[3*i_dst+0] = p_block->p_buffer[2*i_src+0];
816 p_out[3*i_dst+1] = p_block->p_buffer[2*i_src+1];
818 p_out[3*i_dst+2] = (p_block->p_buffer[4*g->i_channels+i_src] ) & 0xf0;
820 p_out[3*i_dst+2] = (p_block->p_buffer[4*g->i_channels+i_src] << 4) & 0xf0;
824 assert( i_bits == 16 );
825 p_out[2*i_dst+0] = p_block->p_buffer[2*i_src+0];
826 p_out[2*i_dst+1] = p_block->p_buffer[2*i_src+1];
831 p_block->i_buffer -= i_group_size;
832 p_block->p_buffer += i_group_size;
835 p_out += (i_bits == 16 ? 2 : 3) * i_channels * 2;
839 static void BdExtract( aout_buffer_t *p_aout_buffer, block_t *p_block )
841 memcpy( p_aout_buffer->p_buffer, p_block->p_buffer, p_block->i_buffer );