]> git.sesse.net Git - vlc/blob - src/audio_output/common.c
a5ea4e4be21e9e941c97e7077423d29d598675da
[vlc] / src / audio_output / common.c
1 /*****************************************************************************
2  * common.c : audio output management of common data structures
3  *****************************************************************************
4  * Copyright (C) 2002-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
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 2 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, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <assert.h>
32
33 #include <vlc_common.h>
34 #include <vlc_aout.h>
35 #include "aout_internal.h"
36
37 /*
38  * Instances management (internal and external)
39  */
40
41 #define AOUT_ASSERT_FIFO_LOCKED aout_assert_fifo_locked(p_aout, p_fifo)
42 static inline void aout_assert_fifo_locked( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
43 {
44 #ifndef NDEBUG
45     if( p_fifo == &p_aout->output.fifo )
46         vlc_assert_locked( &p_aout->output_fifo_lock );
47     else
48     {
49         int i;
50         for( i = 0; i < p_aout->i_nb_inputs; i++ )
51         {
52             if( p_fifo == &p_aout->pp_inputs[i]->fifo)
53             {
54                 vlc_assert_locked( &p_aout->input_fifos_lock );
55                 break;
56             }
57         }
58         if( i == p_aout->i_nb_inputs )
59             vlc_assert_locked( &p_aout->mixer_lock );
60     }
61 #else
62     (void)p_aout;
63     (void)p_fifo;
64 #endif
65 }
66
67 /* Local functions */
68 static void aout_Destructor( vlc_object_t * p_this );
69
70 /*****************************************************************************
71  * aout_New: initialize aout structure
72  *****************************************************************************/
73 aout_instance_t * __aout_New( vlc_object_t * p_parent )
74 {
75     aout_instance_t * p_aout;
76     vlc_value_t val;
77
78     /* Allocate descriptor. */
79     p_aout = vlc_object_create( p_parent, VLC_OBJECT_AOUT );
80     if( p_aout == NULL )
81     {
82         return NULL;
83     }
84
85     /* Initialize members. */
86     vlc_mutex_init( &p_aout->input_fifos_lock );
87     vlc_mutex_init( &p_aout->mixer_lock );
88     vlc_mutex_init( &p_aout->output_fifo_lock );
89     p_aout->i_nb_inputs = 0;
90     p_aout->mixer.f_multiplier = 1.0;
91     p_aout->mixer.b_error = 1;
92     p_aout->output.b_error = 1;
93     p_aout->output.b_starving = 1;
94
95     var_Create( p_aout, "intf-change", VLC_VAR_BOOL );
96     val.b_bool = true;
97     var_Set( p_aout, "intf-change", val );
98
99     vlc_object_set_destructor( p_aout, aout_Destructor );
100
101     return p_aout;
102 }
103
104 /*****************************************************************************
105  * aout_Destructor: destroy aout structure
106  *****************************************************************************/
107 static void aout_Destructor( vlc_object_t * p_this )
108 {
109     aout_instance_t * p_aout = (aout_instance_t *)p_this;
110     vlc_mutex_destroy( &p_aout->input_fifos_lock );
111     vlc_mutex_destroy( &p_aout->mixer_lock );
112     vlc_mutex_destroy( &p_aout->output_fifo_lock );
113 }
114
115
116 /*
117  * Formats management (internal and external)
118  */
119
120 /*****************************************************************************
121  * aout_FormatNbChannels : return the number of channels
122  *****************************************************************************/
123 unsigned int aout_FormatNbChannels( const audio_sample_format_t * p_format )
124 {
125     static const uint32_t pi_channels[] =
126         { AOUT_CHAN_CENTER, AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
127           AOUT_CHAN_REARCENTER, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
128           AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, AOUT_CHAN_LFE };
129     unsigned int i_nb = 0, i;
130
131     for ( i = 0; i < sizeof(pi_channels)/sizeof(uint32_t); i++ )
132     {
133         if ( p_format->i_physical_channels & pi_channels[i] ) i_nb++;
134     }
135
136     return i_nb;
137 }
138
139 /*****************************************************************************
140  * aout_BitsPerSample : get the number of bits per sample
141  *****************************************************************************/
142 unsigned int aout_BitsPerSample( vlc_fourcc_t i_format )
143 {
144     switch( i_format )
145     {
146     case VLC_FOURCC('u','8',' ',' '):
147     case VLC_FOURCC('s','8',' ',' '):
148         return 8;
149
150     case VLC_FOURCC('u','1','6','l'):
151     case VLC_FOURCC('s','1','6','l'):
152     case VLC_FOURCC('u','1','6','b'):
153     case VLC_FOURCC('s','1','6','b'):
154         return 16;
155
156     case VLC_FOURCC('u','2','4','l'):
157     case VLC_FOURCC('s','2','4','l'):
158     case VLC_FOURCC('u','2','4','b'):
159     case VLC_FOURCC('s','2','4','b'):
160         return 24;
161
162     case VLC_FOURCC('s','3','2','l'):
163     case VLC_FOURCC('s','3','2','b'):
164     case VLC_FOURCC('f','l','3','2'):
165     case VLC_FOURCC('f','i','3','2'):
166         return 32;
167
168     case VLC_FOURCC('f','l','6','4'):
169         return 64;
170
171     default:
172         /* For these formats the caller has to indicate the parameters
173          * by hand. */
174         return 0;
175     }
176 }
177
178 /*****************************************************************************
179  * aout_FormatPrepare : compute the number of bytes per frame & frame length
180  *****************************************************************************/
181 void aout_FormatPrepare( audio_sample_format_t * p_format )
182 {
183     p_format->i_bitspersample = aout_BitsPerSample( p_format->i_format );
184     if( p_format->i_bitspersample > 0 )
185     {
186         p_format->i_bytes_per_frame = ( p_format->i_bitspersample / 8 )
187                                     * aout_FormatNbChannels( p_format );
188         p_format->i_frame_length = 1;
189     }
190 }
191
192 /*****************************************************************************
193  * aout_FormatPrintChannels : print a channel in a human-readable form
194  *****************************************************************************/
195 const char * aout_FormatPrintChannels( const audio_sample_format_t * p_format )
196 {
197     switch ( p_format->i_physical_channels & AOUT_CHAN_PHYSMASK )
198     {
199     case AOUT_CHAN_CENTER:
200         if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
201               || (p_format->i_original_channels
202                    & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
203             return "Mono";
204         else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
205             return "Left";
206         return "Right";
207     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
208         if ( p_format->i_original_channels & AOUT_CHAN_REVERSESTEREO )
209         {
210             if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
211                 return "Dolby/Reverse";
212             return "Stereo/Reverse";
213         }
214         else
215         {
216             if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
217                 return "Dolby";
218             else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
219                 return "Dual-mono";
220             else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
221                 return "Stereo/Mono";
222             else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
223                 return "Stereo/Left";
224             else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
225                 return "Stereo/Right";
226             return "Stereo";
227         }
228     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
229         return "3F";
230     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
231         return "2F1R";
232     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
233           | AOUT_CHAN_REARCENTER:
234         return "3F1R";
235     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
236           | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
237         return "2F2R";
238     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
239           | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
240         return "3F2R";
241
242     case AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
243         if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
244               || (p_format->i_original_channels
245                    & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
246             return "Mono/LFE";
247         else if ( p_format->i_original_channels & AOUT_CHAN_LEFT )
248             return "Left/LFE";
249         return "Right/LFE";
250     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE:
251         if ( p_format->i_original_channels & AOUT_CHAN_DOLBYSTEREO )
252             return "Dolby/LFE";
253         else if ( p_format->i_original_channels & AOUT_CHAN_DUALMONO )
254             return "Dual-mono/LFE";
255         else if ( p_format->i_original_channels == AOUT_CHAN_CENTER )
256             return "Mono/LFE";
257         else if ( !(p_format->i_original_channels & AOUT_CHAN_RIGHT) )
258             return "Stereo/Left/LFE";
259         else if ( !(p_format->i_original_channels & AOUT_CHAN_LEFT) )
260             return "Stereo/Right/LFE";
261          return "Stereo/LFE";
262     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE:
263         return "3F/LFE";
264     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER
265           | AOUT_CHAN_LFE:
266         return "2F1R/LFE";
267     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
268           | AOUT_CHAN_REARCENTER | AOUT_CHAN_LFE:
269         return "3F1R/LFE";
270     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
271           | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
272         return "2F2R/LFE";
273     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
274           | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE:
275         return "3F2R/LFE";
276     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
277           | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
278           | AOUT_CHAN_MIDDLERIGHT:
279         return "3F2M2R";
280     case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
281           | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
282           | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE:
283         return "3F2M2R/LFE";
284     }
285
286     return "ERROR";
287 }
288
289 /*****************************************************************************
290  * aout_FormatPrint : print a format in a human-readable form
291  *****************************************************************************/
292 void aout_FormatPrint( aout_instance_t * p_aout, const char * psz_text,
293                        const audio_sample_format_t * p_format )
294 {
295     msg_Dbg( p_aout, "%s '%4.4s' %d Hz %s frame=%d samples/%d bytes", psz_text,
296              (char *)&p_format->i_format, p_format->i_rate,
297              aout_FormatPrintChannels( p_format ),
298              p_format->i_frame_length, p_format->i_bytes_per_frame );
299 }
300
301 /*****************************************************************************
302  * aout_FormatsPrint : print two formats in a human-readable form
303  *****************************************************************************/
304 void aout_FormatsPrint( aout_instance_t * p_aout, const char * psz_text,
305                         const audio_sample_format_t * p_format1,
306                         const audio_sample_format_t * p_format2 )
307 {
308     msg_Dbg( p_aout, "%s '%4.4s'->'%4.4s' %d Hz->%d Hz %s->%s",
309              psz_text,
310              (char *)&p_format1->i_format, (char *)&p_format2->i_format,
311              p_format1->i_rate, p_format2->i_rate,
312              aout_FormatPrintChannels( p_format1 ),
313              aout_FormatPrintChannels( p_format2 ) );
314 }
315
316
317 /*
318  * FIFO management (internal) - please understand that solving race conditions
319  * is _your_ job, ie. in the audio output you should own the mixer lock
320  * before calling any of these functions.
321  */
322
323 /*****************************************************************************
324  * aout_FifoInit : initialize the members of a FIFO
325  *****************************************************************************/
326 void aout_FifoInit( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
327                     uint32_t i_rate )
328 {
329     AOUT_ASSERT_FIFO_LOCKED;
330
331     if( i_rate == 0 )
332     {
333         msg_Err( p_aout, "initialising fifo with zero divider" );
334     }
335
336     p_fifo->p_first = NULL;
337     p_fifo->pp_last = &p_fifo->p_first;
338     aout_DateInit( &p_fifo->end_date, i_rate );
339 }
340
341 /*****************************************************************************
342  * aout_FifoPush : push a packet into the FIFO
343  *****************************************************************************/
344 void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
345                     aout_buffer_t * p_buffer )
346 {
347     (void)p_aout;
348     AOUT_ASSERT_FIFO_LOCKED;
349
350     *p_fifo->pp_last = p_buffer;
351     p_fifo->pp_last = &p_buffer->p_next;
352     *p_fifo->pp_last = NULL;
353     /* Enforce the continuity of the stream. */
354     if ( aout_DateGet( &p_fifo->end_date ) )
355     {
356         p_buffer->start_date = aout_DateGet( &p_fifo->end_date );
357         p_buffer->end_date = aout_DateIncrement( &p_fifo->end_date,
358                                                  p_buffer->i_nb_samples );
359     }
360     else
361     {
362         aout_DateSet( &p_fifo->end_date, p_buffer->end_date );
363     }
364 }
365
366 /*****************************************************************************
367  * aout_FifoSet : set end_date and trash all buffers (because they aren't
368  * properly dated)
369  *****************************************************************************/
370 void aout_FifoSet( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
371                    mtime_t date )
372 {
373     aout_buffer_t * p_buffer;
374     (void)p_aout;
375     AOUT_ASSERT_FIFO_LOCKED;
376
377     aout_DateSet( &p_fifo->end_date, date );
378     p_buffer = p_fifo->p_first;
379     while ( p_buffer != NULL )
380     {
381         aout_buffer_t * p_next = p_buffer->p_next;
382         aout_BufferFree( p_buffer );
383         p_buffer = p_next;
384     }
385     p_fifo->p_first = NULL;
386     p_fifo->pp_last = &p_fifo->p_first;
387 }
388
389 /*****************************************************************************
390  * aout_FifoMoveDates : Move forwards or backwards all dates in the FIFO
391  *****************************************************************************/
392 void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
393                          mtime_t difference )
394 {
395     aout_buffer_t * p_buffer;
396     (void)p_aout;
397     AOUT_ASSERT_FIFO_LOCKED;
398
399     aout_DateMove( &p_fifo->end_date, difference );
400     p_buffer = p_fifo->p_first;
401     while ( p_buffer != NULL )
402     {
403         p_buffer->start_date += difference;
404         p_buffer->end_date += difference;
405         p_buffer = p_buffer->p_next;
406     }
407 }
408
409 /*****************************************************************************
410  * aout_FifoNextStart : return the current end_date
411  *****************************************************************************/
412 mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
413 {
414     (void)p_aout;
415     AOUT_ASSERT_FIFO_LOCKED;
416     return aout_DateGet( &p_fifo->end_date );
417 }
418
419 /*****************************************************************************
420  * aout_FifoFirstDate : return the playing date of the first buffer in the
421  * FIFO
422  *****************************************************************************/
423 mtime_t aout_FifoFirstDate( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
424 {
425     (void)p_aout;
426     AOUT_ASSERT_FIFO_LOCKED;
427     return p_fifo->p_first ?  p_fifo->p_first->start_date : 0;
428 }
429
430 /*****************************************************************************
431  * aout_FifoPop : get the next buffer out of the FIFO
432  *****************************************************************************/
433 aout_buffer_t * aout_FifoPop( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
434 {
435     aout_buffer_t * p_buffer;
436     (void)p_aout;
437     AOUT_ASSERT_FIFO_LOCKED;
438
439     p_buffer = p_fifo->p_first;
440     if ( p_buffer == NULL ) return NULL;
441     p_fifo->p_first = p_buffer->p_next;
442     if ( p_fifo->p_first == NULL )
443     {
444         p_fifo->pp_last = &p_fifo->p_first;
445     }
446
447     return p_buffer;
448 }
449
450 /*****************************************************************************
451  * aout_FifoDestroy : destroy a FIFO and its buffers
452  *****************************************************************************/
453 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
454 {
455     aout_buffer_t * p_buffer;
456     (void)p_aout;
457     AOUT_ASSERT_FIFO_LOCKED;
458
459     p_buffer = p_fifo->p_first;
460     while ( p_buffer != NULL )
461     {
462         aout_buffer_t * p_next = p_buffer->p_next;
463         aout_BufferFree( p_buffer );
464         p_buffer = p_next;
465     }
466
467     p_fifo->p_first = NULL;
468     p_fifo->pp_last = &p_fifo->p_first;
469 }
470
471
472 /*
473  * Date management (internal and external)
474  */
475
476 /*****************************************************************************
477  * aout_DateInit : set the divider of an audio_date_t
478  *****************************************************************************/
479 void aout_DateInit( audio_date_t * p_date, uint32_t i_divider )
480 {
481     p_date->date = 0;
482     p_date->i_divider = i_divider;
483     p_date->i_remainder = 0;
484 }
485
486 /*****************************************************************************
487  * aout_DateSet : set the date of an audio_date_t
488  *****************************************************************************/
489 void aout_DateSet( audio_date_t * p_date, mtime_t new_date )
490 {
491     p_date->date = new_date;
492     p_date->i_remainder = 0;
493 }
494
495 /*****************************************************************************
496  * aout_DateMove : move forwards or backwards the date of an audio_date_t
497  *****************************************************************************/
498 void aout_DateMove( audio_date_t * p_date, mtime_t difference )
499 {
500     p_date->date += difference;
501 }
502
503 /*****************************************************************************
504  * aout_DateGet : get the date of an audio_date_t
505  *****************************************************************************/
506 mtime_t aout_DateGet( const audio_date_t * p_date )
507 {
508     return p_date->date;
509 }
510
511 /*****************************************************************************
512  * aout_DateIncrement : increment the date and return the result, taking
513  * into account rounding errors
514  *****************************************************************************/
515 mtime_t aout_DateIncrement( audio_date_t * p_date, uint32_t i_nb_samples )
516 {
517     mtime_t i_dividend = (mtime_t)i_nb_samples * 1000000;
518     p_date->date += i_dividend / p_date->i_divider;
519     p_date->i_remainder += (int)(i_dividend % p_date->i_divider);
520     if ( p_date->i_remainder >= p_date->i_divider )
521     {
522         /* This is Bresenham algorithm. */
523         p_date->date++;
524         p_date->i_remainder -= p_date->i_divider;
525     }
526     return p_date->date;
527 }
528
529 /*****************************************************************************
530  * aout_CheckChannelReorder : Check if we need to do some channel re-ordering
531  *****************************************************************************/
532 int aout_CheckChannelReorder( const uint32_t *pi_chan_order_in,
533                               const uint32_t *pi_chan_order_out,
534                               uint32_t i_channel_mask,
535                               int i_channels, int *pi_chan_table )
536 {
537     bool b_chan_reorder = false;
538     int i, j, k, l;
539
540     if( i_channels > AOUT_CHAN_MAX )
541         return false;
542
543     if( pi_chan_order_in == NULL )
544         pi_chan_order_in = pi_vlc_chan_order_wg4;
545     if( pi_chan_order_out == NULL )
546         pi_chan_order_out = pi_vlc_chan_order_wg4;
547
548     for( i = 0, j = 0; pi_chan_order_in[i]; i++ )
549     {
550         if( !(i_channel_mask & pi_chan_order_in[i]) ) continue;
551
552         for( k = 0, l = 0; pi_chan_order_in[i] != pi_chan_order_out[k]; k++ )
553         {
554             if( i_channel_mask & pi_chan_order_out[k] ) l++;
555         }
556
557         pi_chan_table[j++] = l;
558     }
559
560     for( i = 0; i < i_channels; i++ )
561     {
562         if( pi_chan_table[i] != i ) b_chan_reorder = true;
563     }
564
565     return b_chan_reorder;
566 }
567
568 /*****************************************************************************
569  * aout_ChannelReorder :
570  *****************************************************************************/
571 void aout_ChannelReorder( uint8_t *p_buf, int i_buffer,
572                           int i_channels, const int *pi_chan_table,
573                           int i_bits_per_sample )
574 {
575     uint8_t p_tmp[AOUT_CHAN_MAX * 4];
576     int i, j;
577
578     if( i_bits_per_sample == 8 )
579     {
580         for( i = 0; i < i_buffer / i_channels; i++ )
581         {
582             for( j = 0; j < i_channels; j++ )
583             {
584                 p_tmp[pi_chan_table[j]] = p_buf[j];
585             }
586
587             memcpy( p_buf, p_tmp, i_channels );
588             p_buf += i_channels;
589         }
590     }
591     else if( i_bits_per_sample == 16 )
592     {
593         for( i = 0; i < i_buffer / i_channels / 2; i++ )
594         {
595             for( j = 0; j < i_channels; j++ )
596             {
597                 p_tmp[2 * pi_chan_table[j]]     = p_buf[2 * j];
598                 p_tmp[2 * pi_chan_table[j] + 1] = p_buf[2 * j + 1];
599             }
600
601             memcpy( p_buf, p_tmp, 2 * i_channels );
602             p_buf += 2 * i_channels;
603         }
604     }
605     else if( i_bits_per_sample == 24 )
606     {
607         for( i = 0; i < i_buffer / i_channels / 3; i++ )
608         {
609             for( j = 0; j < i_channels; j++ )
610             {
611                 p_tmp[3 * pi_chan_table[j]]     = p_buf[3 * j];
612                 p_tmp[3 * pi_chan_table[j] + 1] = p_buf[3 * j + 1];
613                 p_tmp[3 * pi_chan_table[j] + 2] = p_buf[3 * j + 2];
614             }
615
616             memcpy( p_buf, p_tmp, 3 * i_channels );
617             p_buf += 3 * i_channels;
618         }
619     }
620     else if( i_bits_per_sample == 32 )
621     {
622         for( i = 0; i < i_buffer / i_channels / 4; i++ )
623         {
624             for( j = 0; j < i_channels; j++ )
625             {
626                 p_tmp[4 * pi_chan_table[j]]     = p_buf[4 * j];
627                 p_tmp[4 * pi_chan_table[j] + 1] = p_buf[4 * j + 1];
628                 p_tmp[4 * pi_chan_table[j] + 2] = p_buf[4 * j + 2];
629                 p_tmp[4 * pi_chan_table[j] + 3] = p_buf[4 * j + 3];
630             }
631
632             memcpy( p_buf, p_tmp, 4 * i_channels );
633             p_buf += 4 * i_channels;
634         }
635     }
636 }