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