qt: playlist: use item title if available
[vlc.git] / modules / codec / faad.c
blob5df25ea17bfcd6d7a692b35fb4970a28b6c335c2
1 /*****************************************************************************
2 * faad.c: AAC decoder using libfaad2
3 *****************************************************************************
4 * Copyright (C) 2001, 2003 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7 * Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * NOTA BENE: this module requires the linking against a library which is
26 * known to require licensing under the GNU General Public License version 2
27 * (or later). Therefore, the result of compiling this module will normally
28 * be subject to the terms of that later license.
29 *****************************************************************************/
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_input_item.h>
39 #include <vlc_codec.h>
40 #include <vlc_cpu.h>
41 #include <vlc_aout.h>
43 #include <neaacdec.h>
44 #include "../packetizer/mpeg4audio.h"
46 /*****************************************************************************
47 * Module descriptor
48 *****************************************************************************/
49 static int Open( vlc_object_t * );
50 static void Close( vlc_object_t * );
52 vlc_module_begin ()
53 set_description( N_("AAC audio decoder (using libfaad2)") )
54 set_capability( "audio decoder", 100 )
55 set_category( CAT_INPUT )
56 set_subcategory( SUBCAT_INPUT_ACODEC )
57 set_callbacks( Open, Close )
58 vlc_module_end ()
60 /****************************************************************************
61 * Local prototypes
62 ****************************************************************************/
63 static int DecodeBlock( decoder_t *, block_t * );
64 static void Flush( decoder_t * );
65 static void DoReordering( uint32_t *, uint32_t *, int, int, uint8_t * );
67 typedef struct
69 /* faad handler */
70 NeAACDecHandle *hfaad;
72 /* samples */
73 date_t date;
74 vlc_tick_t i_last_length;
76 /* temporary buffer */
77 block_t *p_block;
79 /* Channel positions of the current stream (for re-ordering) */
80 uint32_t pi_channel_positions[MPEG4_ASC_MAX_INDEXEDPOS];
82 bool b_sbr, b_ps, b_discontinuity;
83 } decoder_sys_t;
85 #if MPEG4_ASC_MAX_INDEXEDPOS != LFE_CHANNEL
86 #error MPEG4_ASC_MAX_INDEXEDPOS != LFE_CHANNEL
87 #endif
89 #define FAAD_CHANNEL_ID_COUNT (LFE_CHANNEL + 1)
90 static const uint32_t pi_tovlcmapping[FAAD_CHANNEL_ID_COUNT] =
92 [UNKNOWN_CHANNEL] = 0,
93 [FRONT_CHANNEL_CENTER] = AOUT_CHAN_CENTER,
94 [FRONT_CHANNEL_LEFT] = AOUT_CHAN_LEFT,
95 [FRONT_CHANNEL_RIGHT] = AOUT_CHAN_RIGHT,
96 [SIDE_CHANNEL_LEFT] = AOUT_CHAN_MIDDLELEFT,
97 [SIDE_CHANNEL_RIGHT] = AOUT_CHAN_MIDDLERIGHT,
98 [BACK_CHANNEL_LEFT] = AOUT_CHAN_REARLEFT,
99 [BACK_CHANNEL_RIGHT] = AOUT_CHAN_REARRIGHT,
100 [BACK_CHANNEL_CENTER] = AOUT_CHAN_REARCENTER,
101 [LFE_CHANNEL] = AOUT_CHAN_LFE
104 /*****************************************************************************
105 * OpenDecoder: probe the decoder and return score
106 *****************************************************************************/
107 static int Open( vlc_object_t *p_this )
109 decoder_t *p_dec = (decoder_t*)p_this;
110 decoder_sys_t *p_sys;
111 NeAACDecConfiguration *cfg;
113 if( p_dec->fmt_in.i_codec != VLC_CODEC_MP4A ||
114 p_dec->fmt_in.i_profile == AAC_PROFILE_ELD ||
115 (p_dec->fmt_in.i_extra > 1 &&
116 (GetWBE(p_dec->fmt_in.p_extra) & 0xffe0) == 0xf8e0)) /* ELD AOT */
118 return VLC_EGENERIC;
121 /* Allocate the memory needed to store the decoder's structure */
122 if( ( p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) ) ) == NULL )
123 return VLC_ENOMEM;
125 /* Open a faad context */
126 if( ( p_sys->hfaad = NeAACDecOpen() ) == NULL )
128 msg_Err( p_dec, "cannot initialize faad" );
129 free( p_sys );
130 return VLC_EGENERIC;
133 /* Misc init */
134 p_dec->fmt_out.audio.channel_type = p_dec->fmt_in.audio.channel_type;
136 if( p_dec->fmt_in.i_extra > 0 )
138 /* We have a decoder config so init the handle */
139 unsigned long i_rate;
140 unsigned char i_channels;
142 if( NeAACDecInit2( p_sys->hfaad, p_dec->fmt_in.p_extra,
143 p_dec->fmt_in.i_extra,
144 &i_rate, &i_channels ) < 0 ||
145 i_channels >= MPEG4_ASC_MAX_INDEXEDPOS )
147 msg_Err( p_dec, "Failed to initialize faad using extra data" );
148 NeAACDecClose( p_sys->hfaad );
149 free( p_sys );
150 return VLC_EGENERIC;
153 p_dec->fmt_out.audio.i_rate = i_rate;
154 p_dec->fmt_out.audio.i_channels = i_channels;
155 p_dec->fmt_out.audio.i_physical_channels
156 = mpeg4_asc_channelsbyindex[i_channels];
157 date_Init( &p_sys->date, i_rate, 1 );
159 else
161 p_dec->fmt_out.audio.i_physical_channels = 0;
162 /* Will be initalised from first frame */
163 p_dec->fmt_out.audio.i_rate = 0;
164 p_dec->fmt_out.audio.i_channels = 0;
165 date_Set( &p_sys->date, VLC_TICK_INVALID );
168 p_dec->fmt_out.i_codec = HAVE_FPU ? VLC_CODEC_FL32 : VLC_CODEC_S16N;
169 p_dec->fmt_out.audio.i_chan_mode = p_dec->fmt_in.audio.i_chan_mode;
171 /* Set the faad config */
172 cfg = NeAACDecGetCurrentConfiguration( p_sys->hfaad );
173 if( p_dec->fmt_in.audio.i_rate )
174 cfg->defSampleRate = p_dec->fmt_in.audio.i_rate;
175 cfg->outputFormat = HAVE_FPU ? FAAD_FMT_FLOAT : FAAD_FMT_16BIT;
176 NeAACDecSetConfiguration( p_sys->hfaad, cfg );
178 p_sys->i_last_length = 0;
180 /* buffer */
181 p_sys->p_block = NULL;
183 p_sys->b_discontinuity =
184 p_sys->b_sbr = p_sys->b_ps = false;
186 p_dec->pf_decode = DecodeBlock;
187 p_dec->pf_flush = Flush;
188 return VLC_SUCCESS;
191 /*****************************************************************************
192 * FlushBuffer:
193 *****************************************************************************/
194 static void FlushBuffer( decoder_sys_t *p_sys, size_t i_used )
196 block_t *p_block = p_sys->p_block;
197 if( p_block )
199 if( i_used < p_block->i_buffer )
201 /* Drop padding */
202 for( ; i_used < p_block->i_buffer; i_used++ )
203 if( p_block->p_buffer[i_used] != 0x00 )
204 break;
206 p_block->i_buffer -= i_used;
207 p_block->p_buffer += i_used;
209 else p_block->i_buffer = 0;
210 if( p_block->i_buffer == 0 )
212 block_Release( p_block );
213 p_sys->p_block = NULL;
218 /*****************************************************************************
219 * Flush:
220 *****************************************************************************/
221 static void Flush( decoder_t *p_dec )
223 decoder_sys_t *p_sys = p_dec->p_sys;
225 date_Set( &p_sys->date, VLC_TICK_INVALID );
226 FlushBuffer( p_sys, SIZE_MAX );
229 /*****************************************************************************
230 * DecodeBlock:
231 *****************************************************************************/
232 static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
234 decoder_sys_t *p_sys = p_dec->p_sys;
236 if( !p_block ) /* No Drain */
237 return VLCDEC_SUCCESS;
239 if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
241 Flush( p_dec );
242 if( p_block->i_flags & (BLOCK_FLAG_CORRUPTED) )
244 block_Release( p_block );
245 return VLCDEC_SUCCESS;
249 /* Remove ADTS header if we have decoder specific config */
250 if( p_dec->fmt_in.i_extra && p_block->i_buffer > 7 )
252 if( p_block->p_buffer[0] == 0xff &&
253 ( p_block->p_buffer[1] & 0xf0 ) == 0xf0 ) /* syncword */
254 { /* ADTS header present */
255 size_t i_header_size; /* 7 bytes (+ 2 bytes for crc) */
256 i_header_size = 7 + ( ( p_block->p_buffer[1] & 0x01 ) ? 0 : 2 );
257 /* FIXME: multiple blocks per frame */
258 if( p_block->i_buffer > i_header_size )
260 p_block->p_buffer += i_header_size;
261 p_block->i_buffer -= i_header_size;
266 const vlc_tick_t i_pts = p_block->i_pts;
268 /* Append block as temporary buffer */
269 if( p_sys->p_block == NULL )
271 p_sys->p_block = p_block;
273 else
275 p_sys->p_block->p_next = p_block;
276 block_t *p_prev = p_sys->p_block;
277 p_sys->p_block = block_ChainGather( p_sys->p_block );
278 if( p_sys->p_block == NULL )
279 block_ChainRelease( p_prev );
282 /* !Warn: do not use p_block beyond this point */
284 if( p_dec->fmt_out.audio.i_rate == 0 )
286 unsigned long i_rate = 0;
287 unsigned char i_channels;
289 /* Init from DecoderConfig */
290 if( p_dec->fmt_in.i_extra > 0 &&
291 NeAACDecInit2( p_sys->hfaad, p_dec->fmt_in.p_extra,
292 p_dec->fmt_in.i_extra, &i_rate, &i_channels ) != 0 )
294 /* Failed, will try from data */
295 i_rate = 0;
298 if( i_rate == 0 && p_sys->p_block && p_sys->p_block->i_buffer )
300 /* Init faad with the first frame */
301 long i_read = NeAACDecInit( p_sys->hfaad,
302 p_sys->p_block->p_buffer, p_sys->p_block->i_buffer,
303 &i_rate, &i_channels );
304 if( i_read < 0 || (size_t) i_read > p_sys->p_block->i_buffer )
305 i_rate = 0;
306 else
307 FlushBuffer( p_sys, i_read );
310 if( i_rate == 0 )
312 /* Can not init decoder at all for now */
313 FlushBuffer( p_sys, SIZE_MAX );
314 return VLCDEC_SUCCESS;
317 /* Decoder Initialized */
318 p_dec->fmt_out.audio.i_rate = i_rate;
319 p_dec->fmt_out.audio.i_channels = i_channels;
320 p_dec->fmt_out.audio.i_physical_channels
321 = mpeg4_asc_channelsbyindex[i_channels];
322 date_Init( &p_sys->date, i_rate, 1 );
325 if( i_pts != VLC_TICK_INVALID && i_pts != date_Get( &p_sys->date ) )
327 if( p_sys->i_last_length == 0 ||
328 /* We need to be permissive and rebase dts when it's really way off */
329 llabs( i_pts - date_Get( &p_sys->date ) ) > p_sys->i_last_length * 3 / 2 )
330 date_Set( &p_sys->date, i_pts );
332 else if( date_Get( &p_sys->date ) == VLC_TICK_INVALID )
334 /* We've just started the stream, wait for the first PTS. */
335 FlushBuffer( p_sys, SIZE_MAX );
336 return VLCDEC_SUCCESS;
339 /* Decode all data */
340 while( p_sys->p_block && p_sys->p_block->i_buffer > 0 )
342 void *samples;
343 NeAACDecFrameInfo frame;
344 block_t *p_out = NULL;
346 samples = NeAACDecDecode( p_sys->hfaad, &frame,
347 p_sys->p_block->p_buffer,
348 p_sys->p_block->i_buffer );
350 if( frame.error > 0 )
352 msg_Warn( p_dec, "%s", NeAACDecGetErrorMessage( frame.error ) );
354 if( frame.error == 21 || frame.error == 12 )
357 * Once an "Unexpected channel configuration change"
358 * or a "Invalid number of channels" error
359 * occurs, it will occurs afterwards, and we got no sound.
360 * Reinitialization of the decoder is required.
362 unsigned long i_rate;
363 unsigned char i_channels;
364 NeAACDecHandle *hfaad;
365 NeAACDecConfiguration *cfg,*oldcfg;
367 oldcfg = NeAACDecGetCurrentConfiguration( p_sys->hfaad );
368 hfaad = NeAACDecOpen();
369 cfg = NeAACDecGetCurrentConfiguration( hfaad );
370 if( oldcfg->defSampleRate )
371 cfg->defSampleRate = oldcfg->defSampleRate;
372 cfg->defObjectType = oldcfg->defObjectType;
373 cfg->outputFormat = oldcfg->outputFormat;
374 NeAACDecSetConfiguration( hfaad, cfg );
376 if( NeAACDecInit( hfaad,
377 p_sys->p_block->p_buffer,
378 p_sys->p_block->i_buffer,
379 &i_rate,&i_channels ) < 0 )
381 /* reinitialization failed */
382 NeAACDecClose( hfaad );
383 NeAACDecSetConfiguration( p_sys->hfaad, oldcfg );
385 else
387 NeAACDecClose( p_sys->hfaad );
388 p_sys->hfaad = hfaad;
389 p_dec->fmt_out.audio.i_rate = i_rate;
390 p_dec->fmt_out.audio.i_channels = i_channels;
391 p_dec->fmt_out.audio.i_physical_channels
392 = mpeg4_asc_channelsbyindex[i_channels];
393 date_Init( &p_sys->date, i_rate, 1 );
397 Flush( p_dec );
398 p_sys->b_discontinuity = true;
400 continue;
403 if( frame.channels == 0 || frame.channels >= 64 )
405 msg_Warn( p_dec, "invalid channels count: %i", frame.channels );
406 if( frame.channels == 0 )
407 p_sys->b_discontinuity = true;
408 FlushBuffer( p_sys, frame.bytesconsumed ? frame.bytesconsumed : SIZE_MAX );
409 continue;
412 if( frame.samples == 0 )
414 msg_Warn( p_dec, "decoded zero sample" );
415 FlushBuffer( p_sys, frame.bytesconsumed ? frame.bytesconsumed : SIZE_MAX );
416 continue;
419 /* We decoded a valid frame */
420 if( p_dec->fmt_out.audio.i_rate != frame.samplerate )
422 date_Init( &p_sys->date, frame.samplerate, 1 );
423 date_Set( &p_sys->date, i_pts );
426 p_dec->fmt_out.audio.i_rate = frame.samplerate;
428 /* Adjust stream info when dealing with SBR/PS */
429 bool b_sbr = (frame.sbr == 1) || (frame.sbr == 2);
430 if( p_sys->b_sbr != b_sbr || p_sys->b_ps != frame.ps )
432 const char *psz_ext = (b_sbr && frame.ps) ? "SBR+PS" :
433 b_sbr ? "SBR" : "PS";
435 msg_Dbg( p_dec, "AAC %s (channels: %u, samplerate: %lu)",
436 psz_ext, frame.channels, frame.samplerate );
438 if( !p_dec->p_description )
439 p_dec->p_description = vlc_meta_New();
440 if( p_dec->p_description )
441 vlc_meta_AddExtra( p_dec->p_description, _("AAC extension"), psz_ext );
443 p_sys->b_sbr = b_sbr;
444 p_sys->b_ps = frame.ps;
447 #ifndef FAAD2_VIDEOLAN_PATCHED
448 /* PS Enabled FAAD PCA bug hotfix (contribs has patch) */
449 if( frame.channels == 8 )
451 const uint8_t psbugconfig[3][8] = { { 2, 3, 2, 3, 2, 3, 6, 7 }, /* fdk 7.1 (4 Front) */
452 { 2, 3, 2, 3, 2, 3, 4, 5 }, /* 7.1 */
453 { 1, 2, 3, 4, 5, 6, 7, 9 } };/* fixed */
454 for( size_t i=0; i<2; i++ )
456 if( !memcmp( frame.channel_position, psbugconfig[i], 8 ) )
458 msg_Warn( p_dec, "Unpatched FAAD2 library with PS Bug. Trying to workaround !" );
459 memcpy( frame.channel_position, psbugconfig[2], 8 );
460 break;
465 /* Hotfix channels misdetection/repetition for FDK 7.1 */
466 struct
468 const uint8_t chans;
469 const uint8_t faulty[8];
470 const uint8_t fixed[8];
471 } const channel_repeat_fixes[] = {
472 { 7, { 2, 3, 2, 3, 2, 3, 6 }, { 1, 2, 3, 6, 7, 8, 9 } }, /* 3F 3R LFE #18273 */
473 { 8, { 1, 2, 3, 6, 7, 6, 7, 9 }, { 1, 2, 3, 6, 7, 4, 5, 9 } }, /* FDK encoded 7.1 */
476 for( size_t i=0; i<ARRAY_SIZE(channel_repeat_fixes); i++ )
478 if( channel_repeat_fixes[i].chans == frame.channels &&
479 !memcmp( frame.channel_position, channel_repeat_fixes[i].faulty,
480 channel_repeat_fixes[i].chans ) )
482 msg_Warn( p_dec, "Patching for Front channel repeat bug" );
483 memcpy( frame.channel_position, channel_repeat_fixes[i].fixed,
484 channel_repeat_fixes[i].chans );
485 break;
488 #endif
489 /* Handle > 1 local pair 5.1 setups.
490 In case of more than 1 channel pair per area, faad will have repeats
491 in channels sequence. We need to remap to available surround channels.
492 Front > Middle > Rear:
493 In case of 4 middle, it maps to 2F 2M if no previous front.
494 In case of 4 rear, it maps to 2M 2R if no previous rear.
496 unsigned i_faadused = 0;
497 for( unsigned i=0; i<frame.channels; i++ )
498 if( frame.channel_position[i] > 0 )
499 i_faadused |= 1 << frame.channel_position[i];
501 for( size_t i=3; i<frame.channels; i++ )
503 if( frame.channel_position[i - 3] == frame.channel_position[i - 1] &&
504 frame.channel_position[i - 2] == frame.channel_position[i] &&
505 frame.channel_position[i - 1] >= SIDE_CHANNEL_LEFT &&
506 frame.channel_position[i - 1] <= BACK_CHANNEL_CENTER &&
507 frame.channel_position[i - 1] >= SIDE_CHANNEL_LEFT &&
508 frame.channel_position[i - 1] <= BACK_CHANNEL_CENTER )
510 if( ( (1 << (frame.channel_position[i - 3] - 2)) & i_faadused ) == 0 &&
511 ( (1 << (frame.channel_position[i - 2] - 2)) & i_faadused ) == 0 )
513 frame.channel_position[i - 3] -= 2;
514 frame.channel_position[i - 2] -= 2;
515 i_faadused |= 1 << frame.channel_position[i - 3];
516 i_faadused |= 1 << frame.channel_position[i - 2];
521 /* Convert frame.channel_position to our own channel values */
522 p_dec->fmt_out.audio.i_physical_channels = 0;
524 uint8_t pi_neworder_table[64] = {0};
525 uint32_t pi_faad_channels_positions[64 + 1] = {0};
527 bool b_reorder = false;
528 if (p_dec->fmt_out.audio.channel_type == AUDIO_CHANNEL_TYPE_BITMAP)
530 for( size_t i = 0; i < frame.channels; i++ )
532 unsigned pos = frame.channel_position[i];
533 if( likely(pos < FAAD_CHANNEL_ID_COUNT) )
535 pi_faad_channels_positions[i] = pi_tovlcmapping[pos];
536 p_dec->fmt_out.audio.i_physical_channels |= pi_faad_channels_positions[i];
538 else pi_faad_channels_positions[i] = 0;
541 else if (p_dec->fmt_out.audio.channel_type == AUDIO_CHANNEL_TYPE_AMBISONICS
542 && frame.channels == 4)
544 pi_faad_channels_positions[0] = AOUT_CHAN_REARCENTER;
545 pi_faad_channels_positions[1] = AOUT_CHAN_LEFT;
546 pi_faad_channels_positions[2] = AOUT_CHAN_RIGHT;
547 pi_faad_channels_positions[3] = AOUT_CHAN_CENTER;
548 p_dec->fmt_out.audio.i_physical_channels =
549 AOUT_CHAN_CENTER | AOUT_CHAN_LEFT
550 | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER;
553 b_reorder = aout_CheckChannelReorder( pi_faad_channels_positions, NULL,
554 p_dec->fmt_out.audio.i_physical_channels, pi_neworder_table );
556 p_dec->fmt_out.audio.i_channels = vlc_popcount(p_dec->fmt_out.audio.i_physical_channels);
558 if( !decoder_UpdateAudioFormat( p_dec ) && p_dec->fmt_out.audio.i_channels > 0 )
559 p_out = decoder_NewAudioBuffer( p_dec, frame.samples / p_dec->fmt_out.audio.i_channels );
561 if( p_out )
563 p_out->i_pts = date_Get( &p_sys->date );
564 p_out->i_length = date_Increment( &p_sys->date,
565 frame.samples / frame.channels )
566 - p_out->i_pts;
567 p_sys->i_last_length = p_out->i_length;
568 if ( p_dec->fmt_out.audio.channel_type == AUDIO_CHANNEL_TYPE_BITMAP )
570 /* Don't kill speakers if some weird mapping does not gets 1:1 */
571 if( vlc_popcount(p_dec->fmt_out.audio.i_physical_channels) != frame.channels )
572 memset( p_out->p_buffer, 0, p_out->i_buffer );
575 /* FIXME: replace when aout_channel_reorder can take samples from a different buffer */
576 if( b_reorder )
577 DoReordering( (uint32_t *)p_out->p_buffer, samples,
578 frame.samples / frame.channels, frame.channels,
579 pi_neworder_table );
580 else
581 memcpy( p_out->p_buffer, samples, p_out->i_buffer );
583 if( p_sys->b_discontinuity )
585 p_out->i_flags |= BLOCK_FLAG_DISCONTINUITY;
586 p_sys->b_discontinuity = false;
589 decoder_QueueAudio( p_dec, p_out );
591 else
593 date_Increment( &p_sys->date, frame.samples / frame.channels );
596 FlushBuffer( p_sys, frame.bytesconsumed ? frame.bytesconsumed : SIZE_MAX );
598 if( p_sys->p_block && p_sys->p_block->i_buffer == 1 )
600 /* Drop byte of padding */
601 FlushBuffer( p_sys, 0 );
605 return VLCDEC_SUCCESS;
608 /*****************************************************************************
609 * Close:
610 *****************************************************************************/
611 static void Close( vlc_object_t *p_this )
613 decoder_t *p_dec = (decoder_t *)p_this;
614 decoder_sys_t *p_sys = p_dec->p_sys;
616 NeAACDecClose( p_sys->hfaad );
617 FlushBuffer( p_sys, SIZE_MAX );
618 free( p_sys );
621 /*****************************************************************************
622 * DoReordering: do some channel re-ordering (the ac3 channel order is
623 * different from the aac one).
624 *****************************************************************************/
625 static void DoReordering( uint32_t *p_out, uint32_t *p_in, int i_samples,
626 int i_nb_channels, uint8_t *pi_chan_positions )
628 #if HAVE_FPU
629 #define CAST_SAMPLE(a) a
630 #else
631 #define CAST_SAMPLE(a) ((uint16_t *)a)
632 #endif
633 /* Do the actual reordering */
634 for( int i = 0; i < i_samples; i++ )
636 for( int j = 0; j < i_nb_channels; j++ )
638 CAST_SAMPLE(p_out)[i * i_nb_channels + pi_chan_positions[j]] =
639 CAST_SAMPLE(p_in)[i * i_nb_channels + j];