1 /*****************************************************************************
2 * waveout.c : Windows waveOut plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: waveout.c,v 1.19 2003/02/20 16:07:38 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <string.h> /* strerror() */
28 #include <stdlib.h> /* calloc(), malloc(), free() */
32 #include "aout_internal.h"
37 #define FRAME_SIZE 1024 /* The size is in samples, not in bytes */
40 /*****************************************************************************
42 *****************************************************************************/
44 # define DWORD_PTR DWORD
47 #ifndef WAVE_FORMAT_IEEE_FLOAT
48 # define WAVE_FORMAT_IEEE_FLOAT 0x0003
51 #ifndef WAVE_FORMAT_DOLBY_AC3_SPDIF
52 # define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092
55 #ifndef WAVE_FORMAT_EXTENSIBLE
56 #define WAVE_FORMAT_EXTENSIBLE 0xFFFE
59 #ifndef SPEAKER_FRONT_LEFT
60 # define SPEAKER_FRONT_LEFT 0x1
61 # define SPEAKER_FRONT_RIGHT 0x2
62 # define SPEAKER_FRONT_CENTER 0x4
63 # define SPEAKER_LOW_FREQUENCY 0x8
64 # define SPEAKER_BACK_LEFT 0x10
65 # define SPEAKER_BACK_RIGHT 0x20
66 # define SPEAKER_FRONT_LEFT_OF_CENTER 0x40
67 # define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
68 # define SPEAKER_BACK_CENTER 0x100
69 # define SPEAKER_SIDE_LEFT 0x200
70 # define SPEAKER_SIDE_RIGHT 0x400
71 # define SPEAKER_TOP_CENTER 0x800
72 # define SPEAKER_TOP_FRONT_LEFT 0x1000
73 # define SPEAKER_TOP_FRONT_CENTER 0x2000
74 # define SPEAKER_TOP_FRONT_RIGHT 0x4000
75 # define SPEAKER_TOP_BACK_LEFT 0x8000
76 # define SPEAKER_TOP_BACK_CENTER 0x10000
77 # define SPEAKER_TOP_BACK_RIGHT 0x20000
78 # define SPEAKER_RESERVED 0x80000000
81 #ifndef _WAVEFORMATEXTENSIBLE_
85 WORD wValidBitsPerSample; /* bits of precision */
86 WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */
87 WORD wReserved; /* If neither applies, set to zero. */
89 DWORD dwChannelMask; /* which channels are */
90 /* present in stream */
92 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
96 #ifndef KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
97 DEFINE_GUID( KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, WAVE_FORMAT_IEEE_FLOAT, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 );
99 #ifndef KSDATAFORMAT_SUBTYPE_PCM
100 DEFINE_GUID( KSDATAFORMAT_SUBTYPE_PCM, WAVE_FORMAT_PCM, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 );
102 #ifndef KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF
103 DEFINE_GUID( KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF, WAVE_FORMAT_DOLBY_AC3_SPDIF, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 );
106 /*****************************************************************************
108 *****************************************************************************/
109 static int Open ( vlc_object_t * );
110 static void Close ( vlc_object_t * );
111 static void Play ( aout_instance_t * );
113 /* local functions */
114 static void Probe ( aout_instance_t * );
115 static int OpenWaveOut ( aout_instance_t *, int, int, int, int, vlc_bool_t );
116 static int OpenWaveOutPCM( aout_instance_t *, int*, int, int, int, vlc_bool_t );
117 static void CheckReordering( aout_instance_t *, int );
118 static int PlayWaveOut ( aout_instance_t *, HWAVEOUT, WAVEHDR *,
121 static void CALLBACK WaveOutCallback ( HWAVEOUT, UINT, DWORD, DWORD, DWORD );
123 static void InterleaveFloat32( float *, int *, int );
124 static void InterleaveS16( int16_t *, int *, int );
126 /*****************************************************************************
128 *****************************************************************************/
130 set_description( _("Win32 waveOut extension module") );
131 set_capability( "audio output", 50 );
132 set_callbacks( Open, Close );
135 /*****************************************************************************
136 * aout_sys_t: waveOut audio output method descriptor
137 *****************************************************************************
138 * This structure is part of the audio output thread descriptor.
139 * It describes the waveOut specific properties of an audio device.
140 *****************************************************************************/
143 HWAVEOUT h_waveout; /* handle to waveout instance */
145 WAVEFORMATEXTENSIBLE waveformat; /* audio format */
147 WAVEHDR waveheader[FRAMES_NUM];
151 byte_t *p_silence_buffer; /* buffer we use to play silence */
153 vlc_bool_t b_chan_reorder; /* do we need channel reordering */
157 static const uint32_t pi_channels_in[] =
158 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
159 AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
160 AOUT_CHAN_CENTER, AOUT_CHAN_LFE };
161 static const uint32_t pi_channels_out[] =
162 { SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT,
163 SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT,
164 SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY };
165 static const uint32_t pi_channels_ordered[] =
166 { SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER,
167 SPEAKER_LOW_FREQUENCY,
168 SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT };
170 /*****************************************************************************
171 * Open: open the audio device
172 *****************************************************************************
173 * This function opens and setups Win32 waveOut
174 *****************************************************************************/
175 static int Open( vlc_object_t *p_this )
177 aout_instance_t *p_aout = (aout_instance_t *)p_this;
181 /* Allocate structure */
182 p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) );
184 if( p_aout->output.p_sys == NULL )
186 msg_Err( p_aout, "out of memory" );
190 p_aout->output.pf_play = Play;
191 p_aout->output.p_sys->pi_chan_table = NULL;
192 p_aout->b_die = VLC_FALSE;
194 if( var_Type( p_aout, "audio-device" ) == 0 )
199 if( var_Get( p_aout, "audio-device", &val ) < 0 )
201 /* Probe() has failed. */
202 free( p_aout->output.p_sys );
206 /* Open the device */
207 if( !strcmp( val.psz_string, N_("A/52 over S/PDIF") ) )
209 p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');
210 free( val.psz_string );
212 if( OpenWaveOut( p_aout, VLC_FOURCC('s','p','d','i'),
213 p_aout->output.output.i_physical_channels,
214 aout_FormatNbChannels( &p_aout->output.output ),
215 p_aout->output.output.i_rate, VLC_FALSE )
218 msg_Err( p_aout, "cannot open waveout audio device" );
219 free( p_aout->output.p_sys );
223 /* Calculate the frame size in bytes */
224 p_aout->output.i_nb_samples = A52_FRAME_NB;
225 p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
226 p_aout->output.output.i_frame_length = A52_FRAME_NB;
227 p_aout->output.p_sys->i_buffer_size =
228 p_aout->output.output.i_bytes_per_frame;
230 aout_VolumeNoneInit( p_aout );
234 if( !strcmp( val.psz_string, N_("5.1") ) )
236 p_aout->output.output.i_physical_channels
237 = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
238 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
241 else if( !strcmp( val.psz_string, N_("2 Front 2 Rear") ) )
243 p_aout->output.output.i_physical_channels
244 = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
245 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
247 else if( !strcmp( val.psz_string, "Mono" ) )
249 p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
253 p_aout->output.output.i_physical_channels
254 = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
256 free( val.psz_string );
258 if( OpenWaveOutPCM( p_aout, &p_aout->output.output.i_format,
259 p_aout->output.output.i_physical_channels,
260 aout_FormatNbChannels( &p_aout->output.output ),
261 p_aout->output.output.i_rate, VLC_FALSE )
264 msg_Err( p_aout, "cannot open waveout audio device" );
265 free( p_aout->output.p_sys );
269 /* Calculate the frame size in bytes */
270 p_aout->output.i_nb_samples = FRAME_SIZE;
271 aout_FormatPrepare( &p_aout->output.output );
272 p_aout->output.p_sys->i_buffer_size = FRAME_SIZE *
273 p_aout->output.output.i_bytes_per_frame;
275 aout_VolumeSoftInit( p_aout );
279 waveOutReset( p_aout->output.p_sys->h_waveout );
281 /* Allocate silence buffer */
282 p_aout->output.p_sys->p_silence_buffer =
283 malloc( p_aout->output.p_sys->i_buffer_size );
284 if( p_aout->output.p_sys->p_silence_buffer == NULL )
286 free( p_aout->output.p_sys );
287 msg_Err( p_aout, "out of memory" );
291 /* Zero the buffer. WinCE doesn't have calloc(). */
292 memset( p_aout->output.p_sys->p_silence_buffer, 0,
293 p_aout->output.p_sys->i_buffer_size );
295 /* We need to kick off the playback in order to have the callback properly
297 for( i = 0; i < FRAMES_NUM; i++ )
299 p_aout->output.p_sys->waveheader[i].dwFlags = WHDR_DONE;
301 PlayWaveOut( p_aout, p_aout->output.p_sys->h_waveout,
302 &p_aout->output.p_sys->waveheader[0], NULL );
307 /*****************************************************************************
308 * Probe: probe the audio device for available formats and channels
309 *****************************************************************************/
310 static void Probe( aout_instance_t * p_aout )
314 unsigned int i_physical_channels;
316 var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
318 /* Test for 5.1 support */
319 i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
320 AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT |
321 AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE;
322 if( p_aout->output.output.i_physical_channels == i_physical_channels )
324 if( OpenWaveOutPCM( p_aout, &i_format,
325 i_physical_channels, 6,
326 p_aout->output.output.i_rate, VLC_TRUE )
329 val.psz_string = N_("5.1");
330 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
331 msg_Dbg( p_aout, "device supports 5.1 channels" );
335 /* Test for 2 Front 2 Rear support */
336 i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
337 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
338 if( ( p_aout->output.output.i_physical_channels & i_physical_channels )
339 == i_physical_channels )
341 if( OpenWaveOutPCM( p_aout, &i_format,
342 i_physical_channels, 4,
343 p_aout->output.output.i_rate, VLC_TRUE )
346 val.psz_string = N_("2 Front 2 Rear");
347 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
348 msg_Dbg( p_aout, "device supports 4 channels" );
352 /* Test for stereo support */
353 i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
354 if( OpenWaveOutPCM( p_aout, &i_format,
355 i_physical_channels, 2,
356 p_aout->output.output.i_rate, VLC_TRUE )
359 val.psz_string = N_("Stereo");
360 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
361 var_Set( p_aout, "audio-device", val );
362 msg_Dbg( p_aout, "device supports 2 channels" );
365 /* Test for mono support */
366 i_physical_channels = AOUT_CHAN_CENTER;
367 if( OpenWaveOutPCM( p_aout, &i_format,
368 i_physical_channels, 1,
369 p_aout->output.output.i_rate, VLC_TRUE )
372 val.psz_string = N_("Mono");
373 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
374 msg_Dbg( p_aout, "device supports 1 channel" );
377 /* Test for SPDIF support */
378 if ( AOUT_FMT_NON_LINEAR( &p_aout->output.output ) )
380 if( OpenWaveOut( p_aout, VLC_FOURCC('s','p','d','i'),
381 p_aout->output.output.i_physical_channels,
382 aout_FormatNbChannels( &p_aout->output.output ),
383 p_aout->output.output.i_rate, VLC_TRUE )
386 msg_Dbg( p_aout, "device supports A/52 over S/PDIF" );
387 val.psz_string = N_("A/52 over S/PDIF");
388 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
389 if( config_GetInt( p_aout, "spdif" ) )
390 var_Set( p_aout, "audio-device", val );
394 var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL );
396 val.b_bool = VLC_TRUE;
397 var_Set( p_aout, "intf-change", val );
400 /*****************************************************************************
401 * Play: play a sound buffer
402 *****************************************************************************
403 * This doesn't actually play the buffer. This just stores the buffer so it
404 * can be played by the callback thread.
405 *****************************************************************************/
406 static void Play( aout_instance_t *p_aout )
410 /*****************************************************************************
411 * Close: close the audio device
412 *****************************************************************************/
413 static void Close( vlc_object_t *p_this )
415 aout_instance_t *p_aout = (aout_instance_t *)p_this;
417 /* Before calling waveOutClose we must reset the device */
418 p_aout->b_die = VLC_TRUE;
420 /* Wait for the waveout buffers to be freed */
424 vlc_bool_t b_not_done = VLC_FALSE;
426 for( i = 0; i < FRAMES_NUM; i++ )
428 if( !(p_aout->output.p_sys->waveheader[i].dwFlags & WHDR_DONE) )
429 b_not_done = VLC_TRUE;
438 waveOutReset( p_aout->output.p_sys->h_waveout );
440 /* Close the device */
441 if( waveOutClose( p_aout->output.p_sys->h_waveout ) != MMSYSERR_NOERROR )
443 msg_Err( p_aout, "waveOutClose failed" );
446 free( p_aout->output.p_sys->p_silence_buffer );
447 if( p_aout->output.p_sys->pi_chan_table )
448 free( p_aout->output.p_sys->pi_chan_table );
449 free( p_aout->output.p_sys );
452 /*****************************************************************************
453 * OpenWaveOut: open the waveout sound device
454 ****************************************************************************/
455 static int OpenWaveOut( aout_instance_t *p_aout, int i_format,
456 int i_channels, int i_nb_channels, int i_rate,
462 /* Set sound format */
464 #define waveformat p_aout->output.p_sys->waveformat
466 waveformat.dwChannelMask = 0;
467 for( i = 0; i < sizeof(pi_channels_in)/sizeof(uint32_t); i++ )
469 if( i_channels & pi_channels_in[i] )
470 waveformat.dwChannelMask |= pi_channels_out[i];
475 case VLC_FOURCC('s','p','d','i'):
477 /* To prevent channel re-ordering */
478 waveformat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
479 waveformat.Format.wBitsPerSample = 16;
480 waveformat.Samples.wValidBitsPerSample =
481 waveformat.Format.wBitsPerSample;
482 waveformat.Format.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF;
483 waveformat.SubFormat = KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF;
486 case VLC_FOURCC('f','l','3','2'):
487 waveformat.Format.wBitsPerSample = sizeof(float) * 8;
488 waveformat.Samples.wValidBitsPerSample =
489 waveformat.Format.wBitsPerSample;
490 waveformat.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
491 waveformat.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
494 case VLC_FOURCC('s','1','6','l'):
495 waveformat.Format.wBitsPerSample = 16;
496 waveformat.Samples.wValidBitsPerSample =
497 waveformat.Format.wBitsPerSample;
498 waveformat.Format.wFormatTag = WAVE_FORMAT_PCM;
499 waveformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
503 waveformat.Format.nChannels = i_nb_channels;
504 waveformat.Format.nSamplesPerSec = i_rate;
505 waveformat.Format.nBlockAlign =
506 waveformat.Format.wBitsPerSample / 8 * i_nb_channels;
507 waveformat.Format.nAvgBytesPerSec =
508 waveformat.Format.nSamplesPerSec * waveformat.Format.nBlockAlign;
510 /* Only use the new WAVE_FORMAT_EXTENSIBLE format for multichannel audio */
511 if( i_nb_channels <= 2 )
513 waveformat.Format.cbSize = 0;
517 waveformat.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
518 waveformat.Format.cbSize =
519 sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
522 /* Open the device */
523 result = waveOutOpen( &p_aout->output.p_sys->h_waveout, WAVE_MAPPER,
524 (WAVEFORMATEX *)&waveformat,
525 (DWORD_PTR)WaveOutCallback, (DWORD_PTR)p_aout,
526 CALLBACK_FUNCTION | (b_probe?WAVE_FORMAT_QUERY:0) );
527 if( result == WAVERR_BADFORMAT )
529 msg_Warn( p_aout, "waveOutOpen failed WAVERR_BADFORMAT" );
532 if( result == MMSYSERR_ALLOCATED )
534 msg_Warn( p_aout, "waveOutOpen failed WAVERR_ALLOCATED" );
537 if( result != MMSYSERR_NOERROR )
539 msg_Warn( p_aout, "waveOutOpen failed" );
543 CheckReordering( p_aout, i_nb_channels );
551 /*****************************************************************************
552 * OpenWaveOutPCM: open a PCM waveout sound device
553 ****************************************************************************/
554 static int OpenWaveOutPCM( aout_instance_t *p_aout, int *i_format,
555 int i_channels, int i_nb_channels, int i_rate,
558 if( OpenWaveOut( p_aout, VLC_FOURCC('f','l','3','2'),
559 i_channels, i_nb_channels, i_rate, b_probe )
562 if ( OpenWaveOut( p_aout, VLC_FOURCC('s','1','6','l'),
563 i_channels, i_nb_channels, i_rate, b_probe )
570 *i_format = VLC_FOURCC('s','1','6','l');
576 *i_format = VLC_FOURCC('f','l','3','2');
581 /*****************************************************************************
582 * CheckReordering: Check if we need to do some channel re-ordering (the ac3
583 * channel order is different from the one chosen by
585 *****************************************************************************/
586 static void CheckReordering( aout_instance_t *p_aout, int i_nb_channels )
590 #define waveformat p_aout->output.p_sys->waveformat
591 #define pi_chan_table p_aout->output.p_sys->pi_chan_table
593 p_aout->output.p_sys->b_chan_reorder = VLC_FALSE;
595 pi_chan_table = malloc( i_nb_channels * sizeof(int) );
602 i < (int)(sizeof(pi_channels_out)/sizeof(uint32_t)); i++ )
604 if( waveformat.dwChannelMask & pi_channels_out[i] )
607 pi_channels_out[i] != pi_channels_ordered[k]; k++ )
609 if( waveformat.dwChannelMask & pi_channels_ordered[k] )
615 pi_chan_table[j] = l;
621 for( i = 0; i < i_nb_channels; i++ )
623 if( pi_chan_table[i] != i )
625 p_aout->output.p_sys->b_chan_reorder = VLC_TRUE;
629 if( p_aout->output.p_sys->b_chan_reorder )
631 msg_Dbg( p_aout, "channel reordering needed" );
638 /*****************************************************************************
639 * PlayWaveOut: play a buffer through the WaveOut device
640 *****************************************************************************/
641 static int PlayWaveOut( aout_instance_t *p_aout, HWAVEOUT h_waveout,
642 WAVEHDR *p_waveheader, aout_buffer_t *p_buffer )
646 /* Prepare the buffer */
647 if( p_buffer != NULL )
648 p_waveheader->lpData = p_buffer->p_buffer;
650 /* Use silence buffer instead */
651 p_waveheader->lpData = p_aout->output.p_sys->p_silence_buffer;
653 p_waveheader->dwUser = (DWORD_PTR)p_buffer;
654 p_waveheader->dwBufferLength = p_aout->output.p_sys->i_buffer_size;
655 p_waveheader->dwFlags = 0;
657 result = waveOutPrepareHeader( h_waveout, p_waveheader, sizeof(WAVEHDR) );
658 if( result != MMSYSERR_NOERROR )
660 msg_Err( p_aout, "waveOutPrepareHeader failed" );
664 /* Send the buffer to the waveOut queue */
665 result = waveOutWrite( h_waveout, p_waveheader, sizeof(WAVEHDR) );
666 if( result != MMSYSERR_NOERROR )
668 msg_Err( p_aout, "waveOutWrite failed" );
675 /*****************************************************************************
676 * WaveOutCallback: what to do once WaveOut has played its sound samples
677 *****************************************************************************/
678 static void CALLBACK WaveOutCallback( HWAVEOUT h_waveout, UINT uMsg,
680 DWORD dwParam1, DWORD dwParam2 )
682 aout_instance_t *p_aout = (aout_instance_t *)_p_aout;
683 WAVEHDR *p_waveheader = (WAVEHDR *)dwParam1;
684 aout_buffer_t *p_buffer = NULL;
686 int i, i_queued_frames = 0;
688 if( uMsg != WOM_DONE ) return;
690 /* Unprepare and free the buffer which has just been played */
691 waveOutUnprepareHeader( h_waveout, p_waveheader, sizeof(WAVEHDR) );
692 if( p_waveheader->dwUser )
693 aout_BufferFree( (aout_buffer_t *)p_waveheader->dwUser );
695 if( p_aout->b_die ) return;
697 /* We don't want any resampling when using S/PDIF */
698 b_sleek = p_aout->output.output.i_format == VLC_FOURCC('s','p','d','i');
700 /* Find out the current latency */
701 for( i = 0; i < FRAMES_NUM; i++ )
703 /* Check if frame buf is available */
704 if( !(p_aout->output.p_sys->waveheader[i].dwFlags & WHDR_DONE) )
710 /* Try to fill in as many frame buffers as possible */
711 for( i = 0; i < FRAMES_NUM; i++ )
713 /* Check if frame buf is available */
714 if( p_aout->output.p_sys->waveheader[i].dwFlags & WHDR_DONE )
716 /* Take into account the latency */
717 p_buffer = aout_OutputNextBuffer( p_aout,
718 mdate() + 1000000 * i_queued_frames /
719 p_aout->output.output.i_rate * p_aout->output.i_nb_samples,
722 if( !p_buffer && i_queued_frames )
724 /* We aren't late so no need to play a blank sample */
728 /* Do the channel reordering here */
729 if( p_buffer && p_aout->output.p_sys->b_chan_reorder )
731 if( p_aout->output.output.i_format ==
732 VLC_FOURCC('s','1','6','l') )
733 InterleaveS16( (int16_t *)p_buffer->p_buffer,
734 p_aout->output.p_sys->pi_chan_table,
735 aout_FormatNbChannels( &p_aout->output.output ) );
737 InterleaveFloat32( (float *)p_buffer->p_buffer,
738 p_aout->output.p_sys->pi_chan_table,
739 aout_FormatNbChannels( &p_aout->output.output ) );
742 PlayWaveOut( p_aout, h_waveout,
743 &p_aout->output.p_sys->waveheader[i] , p_buffer );
750 /*****************************************************************************
751 * InterleaveFloat32/S16: change the channel order to the Microsoft one.
752 *****************************************************************************/
753 static void InterleaveFloat32( float *p_buf, int *pi_chan_table,
759 for( i = 0; i < FRAME_SIZE; i++ )
761 for( j = 0; j < i_nb_channels; j++ )
763 p_tmp[pi_chan_table[j]] = p_buf[i*i_nb_channels + j];
766 memcpy( &p_buf[i*i_nb_channels], p_tmp,
767 i_nb_channels * sizeof(float) );
771 static void InterleaveS16( int16_t *p_buf, int *pi_chan_table,
777 for( i = 0; i < FRAME_SIZE; i++ )
779 for( j = 0; j < i_nb_channels; j++ )
781 p_tmp[pi_chan_table[j]] = p_buf[i*i_nb_channels + j];
784 memcpy( &p_buf[i*i_nb_channels], p_tmp,
785 i_nb_channels * sizeof(int16_t) );