when wrapping around the audio output fifo.
* Lots of simplifications in the audio output, got rid of b_stereo.
INTERFACE := main interface intf_msg intf_playlist intf_eject
INPUT := input input_ext-dec input_ext-intf input_dec input_programs input_clock mpeg_system
VIDEO_OUTPUT := video_output video_text vout_pictures vout_subpictures
-AUDIO_OUTPUT := audio_output aout_common aout_ext-dec aout_spdif
+AUDIO_OUTPUT := audio_output aout_ext-dec aout_pcm aout_spdif
MISC := mtime modules configuration netutils iso_lang
C_OBJ := $(INTERFACE:%=src/interface/%.o) \
* audio_output.h : audio output thread interface
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: audio_output.h,v 1.42 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: audio_output.h,v 1.43 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Cyril Deguet <asmax@via.ecp.fr>
{
/* The remainder is used to keep track of the fractional part of the
* index. */
- long l_remainder;
+ int i_r;
/*
* The increment structure is initialized with the result of an euclidean
* division :
*
- * l_euclidean_numerator l_euclidean_remainder
- * ----------------------- = l_euclidean_integer + -----------------------
- * l_euclidean_denominator l_euclidean_denominator
+ * i_x i_b
+ * ----- = i_a + -----
+ * i_y i_c
*
*/
- long l_euclidean_integer;
- long l_euclidean_remainder;
- long l_euclidean_denominator;
+ int i_a, i_b, i_c;
} aout_increment_t;
*****************************************************************************/
typedef struct aout_fifo_s
{
- /* See the fifo types below */
- int i_type;
+ /* See the fifo formats below */
+ int i_format;
+ int i_channels;
+ int i_rate;
+ int i_frame_size;
+
boolean_t b_die;
int i_fifo; /* Just to keep track of the fifo index */
- int i_channels;
- boolean_t b_stereo;
- long l_rate;
-
vlc_mutex_t data_lock;
vlc_cond_t data_wait;
- long l_frame_size;
void * buffer;
mtime_t * date;
+
/* The start frame is the first frame in the buffer that contains decoded
* audio data. It it also the first frame in the current timestamped frame
* area, ie the first dated frame in the decoded part of the buffer. :-p */
- long l_start_frame;
+ int i_start_frame;
boolean_t b_start_frame;
/* The next frame is the end frame of the current timestamped frame area,
* ie the first dated frame after the start frame. */
- long l_next_frame;
+ int i_next_frame;
boolean_t b_next_frame;
/* The end frame is the first frame, after the start frame, that doesn't
* contain decoded audio data. That's why the end frame is the first frame
* where the audio decoder can store its decoded audio frames. */
- long l_end_frame;
+ int i_end_frame;
- long l_unit;
+ /* Current index in p_aout->buffer */
+ int i_unit;
+ /* Max index in p_aout->buffer */
+ int i_unit_limit;
+ /* Structure used to calculate i_unit with a Bresenham algorithm */
aout_increment_t unit_increment;
+
/* The following variable is used to store the number of remaining audio
* units in the current timestamped frame area. */
- long l_units;
+ int i_units;
} aout_fifo_t;
#define AOUT_FIFO_ISEMPTY( fifo ) \
- ( (fifo).l_end_frame == (fifo).l_start_frame )
+ ( (fifo).i_end_frame == (fifo).i_start_frame )
#define AOUT_FIFO_ISFULL( fifo ) \
- ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
+ ( ((((fifo).i_end_frame + 1) - (fifo).i_start_frame) & AOUT_FIFO_SIZE) == 0 )
+
+#define AOUT_FIFO_INC( i_index ) \
+ ( ((i_index) + 1) & AOUT_FIFO_SIZE )
-#define AOUT_EMPTY_FIFO 0
-#define AOUT_ADEC_MONO_FIFO 1
-#define AOUT_ADEC_STEREO_FIFO 2
-#define AOUT_ADEC_SPDIF_FIFO 3
+/* List of known fifo formats */
+#define AOUT_FIFO_NONE 0
+#define AOUT_FIFO_PCM 1
+#define AOUT_FIFO_SPDIF 2
/*****************************************************************************
* aout_thread_t : audio output thread descriptor
struct module_s * p_module;
int ( *pf_open ) ( p_aout_thread_t );
int ( *pf_setformat ) ( p_aout_thread_t );
- long ( *pf_getbufinfo ) ( p_aout_thread_t, long );
+ int ( *pf_getbufinfo ) ( p_aout_thread_t, int );
void ( *pf_play ) ( p_aout_thread_t, byte_t *, int );
void ( *pf_close ) ( p_aout_thread_t );
/* The size of the audio output buffer is kept in audio units, as this is
* the only unit that is common with every audio decoder and audio fifo */
- long l_units;
- long l_msleep;
+ int i_units;
+ int i_msleep;
/* date is the moment where the first audio unit of the output buffer
* will be played */
/* The current volume */
int i_volume;
int i_savedvolume;
- /* Format of the audio output samples */
+
+ /* Format of the audio output samples, number of channels, and
+ * rate and gain (in Hz) of the audio output sound */
int i_format;
- /* Number of channels */
int i_channels;
- /* Mono or Stereo sound */
- boolean_t b_stereo;
- /* Rate and gain of the audio output sound (in Hz) */
- long l_rate;
- long l_gain;
+ int i_rate;
+
+ /* Latency of the audio output plugin, in bytes */
int i_latency;
/* there might be some useful private structure, such as audio_buf_info
void aout_InitBank ( void );
void aout_EndBank ( void );
-aout_thread_t * aout_CreateThread ( int *pi_status, int i_channels,
- long l_rate );
+aout_thread_t * aout_CreateThread ( int *, int, int );
void aout_DestroyThread ( aout_thread_t *, int * );
-aout_fifo_t * aout_CreateFifo ( int, int, long, long, long, void * );
+aout_fifo_t * aout_CreateFifo ( int, int, int, int, void * );
void aout_DestroyFifo ( aout_fifo_t *p_fifo );
void aout_FreeFifo ( aout_fifo_t *p_fifo );
#else
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: common.h,v 1.77 2002/02/24 21:36:20 jobi Exp $
+ * $Id: common.h,v 1.78 2002/02/24 22:06:50 sam Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
struct pgrm_descriptor_s *,
mtime_t );
- struct aout_fifo_s * ( * aout_CreateFifo )
- ( int, int, long, long, long, void * );
+ struct aout_fifo_s * ( * aout_CreateFifo ) ( int, int, int, int, void * );
void ( * aout_DestroyFifo ) ( struct aout_fifo_s * );
struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, u32, int );
-/* include/defs.h.in. Generated automatically from configure.in by autoheader. */
+/* include/defs.h.in. Generated automatically from configure.in by autoheader 2.13. */
/* Define if using alloca.c. */
#undef C_ALLOCA
* modules.h : Module management functions.
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: modules.h,v 1.42 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: modules.h,v 1.43 2002/02/24 22:06:50 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
{
int ( * pf_open ) ( struct aout_thread_s * );
int ( * pf_setformat ) ( struct aout_thread_s * );
- long ( * pf_getbufinfo ) ( struct aout_thread_s *, long );
+ int ( * pf_getbufinfo ) ( struct aout_thread_s *, int );
void ( * pf_play ) ( struct aout_thread_s *, byte_t *, int );
void ( * pf_close ) ( struct aout_thread_s * );
} aout;
* (http://liba52.sf.net/).
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: a52.c,v 1.4 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: a52.c,v 1.5 2002/02/24 22:06:50 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
int i;
if( ( p_a52_adec->p_aout_fifo != NULL ) &&
- ( p_a52_adec->p_aout_fifo->l_rate != p_a52_adec->sample_rate ) )
+ ( p_a52_adec->p_aout_fifo->i_rate != p_a52_adec->sample_rate ) )
{
/* Make sure the output thread leaves the NextFrame() function */
vlc_mutex_lock (&(p_a52_adec->p_aout_fifo->data_lock));
/* Creating the audio output fifo if not created yet */
if (p_a52_adec->p_aout_fifo == NULL )
{
- p_a52_adec->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO,
+ p_a52_adec->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM,
p_a52_adec->i_channels,
- p_a52_adec->sample_rate, 0,
+ p_a52_adec->sample_rate,
AC3DEC_FRAME_SIZE * p_a52_adec->i_channels,
NULL );
/* Set the Presentation Time Stamp */
CurrentPTS( &p_a52_adec->bit_stream,
&p_a52_adec->p_aout_fifo->date[
- p_a52_adec->p_aout_fifo->l_end_frame],
+ p_a52_adec->p_aout_fifo->i_end_frame],
NULL );
if( !p_a52_adec->p_aout_fifo->date[
- p_a52_adec->p_aout_fifo->l_end_frame] )
+ p_a52_adec->p_aout_fifo->i_end_frame] )
{
p_a52_adec->p_aout_fifo->date[
- p_a52_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
+ p_a52_adec->p_aout_fifo->i_end_frame] = LAST_MDATE;
}
p_buffer = ((byte_t *)p_a52_adec->p_aout_fifo->buffer) +
- ( p_a52_adec->p_aout_fifo->l_end_frame * AC3DEC_FRAME_SIZE *
+ ( p_a52_adec->p_aout_fifo->i_end_frame * AC3DEC_FRAME_SIZE *
p_a52_adec->i_channels * sizeof(s16) );
/* FIXME */
vlc_mutex_lock( &p_a52_adec->p_aout_fifo->data_lock );
- p_a52_adec->p_aout_fifo->l_end_frame =
- (p_a52_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+ p_a52_adec->p_aout_fifo->i_end_frame =
+ (p_a52_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_a52_adec->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_a52_adec->p_aout_fifo->data_lock);
* ac3_adec.c: ac3 decoder module main file
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: ac3_adec.c,v 1.21 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: ac3_adec.c,v 1.22 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Lespinasse <walken@zoy.org>
*
}
if( ( p_ac3thread->p_aout_fifo != NULL ) &&
- ( p_ac3thread->p_aout_fifo->l_rate != sync_info.sample_rate ) )
+ ( p_ac3thread->p_aout_fifo->i_rate != sync_info.sample_rate ) )
{
/* Make sure the output thread leaves the NextFrame() function */
vlc_mutex_lock (&(p_ac3thread->p_aout_fifo->data_lock));
/* Creating the audio output fifo if not created yet */
if (p_ac3thread->p_aout_fifo == NULL ) {
- p_ac3thread->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO,
- 2, sync_info.sample_rate, 0, AC3DEC_FRAME_SIZE, NULL );
+ p_ac3thread->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM, 2,
+ sync_info.sample_rate, AC3DEC_FRAME_SIZE, NULL );
if ( p_ac3thread->p_aout_fifo == NULL )
{
free( IMDCT->w_1 );
}
CurrentPTS( &p_ac3thread->ac3_decoder->bit_stream,
- &p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->l_end_frame],
+ &p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->i_end_frame],
NULL );
- if( !p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->l_end_frame] )
+ if( !p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->i_end_frame] )
{
p_ac3thread->p_aout_fifo->date[
- p_ac3thread->p_aout_fifo->l_end_frame] =
+ p_ac3thread->p_aout_fifo->i_end_frame] =
LAST_MDATE;
}
buffer = ((s16 *)p_ac3thread->p_aout_fifo->buffer) +
- (p_ac3thread->p_aout_fifo->l_end_frame * AC3DEC_FRAME_SIZE);
+ (p_ac3thread->p_aout_fifo->i_end_frame * AC3DEC_FRAME_SIZE);
if (ac3_decode_frame (p_ac3thread->ac3_decoder, buffer))
{
}
vlc_mutex_lock (&p_ac3thread->p_aout_fifo->data_lock);
- p_ac3thread->p_aout_fifo->l_end_frame =
- (p_ac3thread->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+ p_ac3thread->p_aout_fifo->i_end_frame =
+ (p_ac3thread->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_ac3thread->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_ac3thread->p_aout_fifo->data_lock);
* ac3_spdif.c: ac3 pass-through to external decoder with enabled soundcard
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: ac3_spdif.c,v 1.15 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: ac3_spdif.c,v 1.16 2002/02/24 22:06:50 sam Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Juha Yrjola <jyrjola@cc.hut.fi>
/* if we're late here the output won't have to play the frame */
if( i_current_pts > mdate() )
{
- p_spdif->p_aout_fifo->date[p_spdif->p_aout_fifo->l_end_frame] =
+ p_spdif->p_aout_fifo->date[p_spdif->p_aout_fifo->i_end_frame] =
i_current_pts;
/* Write in the first free packet of aout fifo */
p_spdif->p_iec = ((u8*)(p_spdif->p_aout_fifo->buffer) +
- (p_spdif->p_aout_fifo->l_end_frame * SPDIF_FRAME_SIZE ));
+ (p_spdif->p_aout_fifo->i_end_frame * SPDIF_FRAME_SIZE ));
/* Build burst to be sent to hardware decoder */
ac3_iec958_build_burst( p_spdif );
vlc_mutex_lock (&p_spdif->p_aout_fifo->data_lock);
- p_spdif->p_aout_fifo->l_end_frame =
- (p_spdif->p_aout_fifo->l_end_frame + 1 ) & AOUT_FIFO_SIZE;
+ p_spdif->p_aout_fifo->i_end_frame =
+ (p_spdif->p_aout_fifo->i_end_frame + 1 ) & AOUT_FIFO_SIZE;
vlc_mutex_unlock (&p_spdif->p_aout_fifo->data_lock);
}
}
/* Creating the audio output fifo */
- p_spdif->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_SPDIF_FIFO, 1,
+ p_spdif->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_SPDIF, 1,
p_spdif->ac3_info.i_sample_rate,
- 0, SPDIF_FRAME_SIZE, NULL );
+ SPDIF_FRAME_SIZE, NULL );
if( p_spdif->p_aout_fifo == NULL )
{
* aout_alsa.c : Alsa functions library
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
- * $Id: aout_alsa.c,v 1.27 2002/02/19 00:50:19 sam Exp $
+ * $Id: aout_alsa.c,v 1.28 2002/02/24 22:06:50 sam Exp $
*
* Authors: Henri Fallon <henri@videolan.org> - Original Author
* Jeffrey Baker <jwbaker@acm.org> - Port to ALSA 1.0 API
}
i_rv = snd_pcm_hw_params_set_rate_near( p_aout->p_sys->p_alsa_handle, p_hw,
- p_aout->l_rate, 0 );
+ p_aout->i_rate, 0 );
if( i_rv < 0 )
{
intf_ErrMsg( "aout error: unable to set sample rate" );
* of data to play, it switches to the "underrun" status. It has to
* be flushed and re-prepared
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static long aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
snd_pcm_status_t *p_status;
int i_alsa_get_status_returns;
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
}
p_aout->p_sys->stream =
- arts_play_stream( p_aout->l_rate, 16, p_aout->i_channels, "vlc" );
+ arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
return( 0 );
}
/*****************************************************************************
* aout_GetBufInfo: buffer status query
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
/* arbitrary value that should be changed */
- return( l_buffer_limit );
+ return( i_buffer_limit );
}
/*****************************************************************************
* aout_beos.cpp: BeOS audio output
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: aout_beos.cpp,v 1.22 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_beos.cpp,v 1.23 2002/02/24 22:06:50 sam Exp $
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
BPushGameSound * p_sound;
gs_audio_format * p_format;
void * p_buffer;
- long i_buffer_size;
- long i_buffer_pos;
+ int i_buffer_size;
+ int i_buffer_pos;
} aout_sys_t;
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
/*****************************************************************************
* aout_GetBufInfo: buffer status query
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
/* Each value is 4 bytes long (stereo signed 16 bits) */
- long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
+ int i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
i_hard_pos = p_aout->p_sys->i_buffer_pos - i_hard_pos;
if( i_hard_pos < 0 )
*****************************************************************************/
static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
{
- long i_newbuf_pos;
+ int i_newbuf_pos;
if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
> p_aout->p_sys->i_buffer_size )
* aout_directx.c: Windows DirectX audio output method
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: aout_directx.c,v 1.19 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_directx.c,v 1.20 2002/02/24 22:06:50 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
HINSTANCE hdsound_dll; /* handle of the opened dsound dll */
- long l_buffer_size; /* secondary sound buffer size */
- long l_write_position; /* next write position for the buffer */
+ int i_buffer_size; /* secondary sound buffer size */
+ int i_write_position; /* next write position for the buffer */
volatile boolean_t b_buffer_underflown; /* buffer underflow detection */
- volatile long l_data_played_from_beginning; /* for underflow detection */
- volatile long l_data_written_from_beginning; /* for underflow detection */
+ volatile int i_data_played_from_beginning; /* for underflow detection */
+ volatile int i_data_written_from_beginning; /* for underflow detection */
vlc_mutex_t buffer_lock; /* audio buffer lock */
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
p_aout->p_sys->p_dsbuffer = NULL;
p_aout->p_sys->p_dsnotify = NULL;
p_aout->p_sys->b_notification_thread_die = 0;
- p_aout->p_sys->l_data_written_from_beginning = 0;
- p_aout->p_sys->l_data_played_from_beginning = 0;
+ p_aout->p_sys->i_data_written_from_beginning = 0;
+ p_aout->p_sys->i_data_played_from_beginning = 0;
vlc_mutex_init( &p_aout->p_sys->buffer_lock );
{
HRESULT dsresult;
WAVEFORMATEX *p_waveformat;
- unsigned long i_size_struct;
+ unsigned int i_size_struct;
intf_WarnMsg( 3, "aout: DirectX aout_SetFormat ");
{
/* Here we'll change the format */
p_waveformat->nChannels = 2;
- p_waveformat->nSamplesPerSec = (p_aout->l_rate < 44100) ? 44100
- : p_aout->l_rate;
+ p_waveformat->nSamplesPerSec = (p_aout->i_rate < 44100) ? 44100
+ : p_aout->i_rate;
p_waveformat->wBitsPerSample = 16;
p_waveformat->nBlockAlign = p_waveformat->wBitsPerSample / 8 *
p_waveformat->nChannels;
* returns the number of bytes in the audio buffer that have not yet been
* sent to the sound device.
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
- long l_play_position, l_notused, l_result;
+ int i_play_position, i_notused, i_result;
HRESULT dsresult;
if( p_aout->p_sys->b_buffer_underflown )
{
intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo underflow");
- return( l_buffer_limit );
+ return( i_buffer_limit );
}
dsresult = IDirectSoundBuffer_GetCurrentPosition(p_aout->p_sys->p_dsbuffer,
- &l_play_position, &l_notused);
+ &i_play_position, &i_notused);
if( dsresult != DS_OK )
{
intf_WarnMsg(3,"aout: DirectX aout_GetBufInfo cannot get current pos");
- return( l_buffer_limit );
+ return( i_buffer_limit );
}
- l_result = (p_aout->p_sys->l_write_position >= l_play_position) ?
- (p_aout->p_sys->l_write_position - l_play_position)
- : (p_aout->p_sys->l_buffer_size - l_play_position
- + p_aout->p_sys->l_write_position);
+ i_result = (p_aout->p_sys->i_write_position >= i_play_position) ?
+ (p_aout->p_sys->i_write_position - i_play_position)
+ : (p_aout->p_sys->i_buffer_size - i_play_position
+ + p_aout->p_sys->i_write_position);
#if 0
- intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo: %li", l_result);
+ intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo: %i", i_result);
#endif
- return l_result;
+ return i_result;
}
/*****************************************************************************
static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
{
VOID *p_write_position, *p_start_buffer;
- long l_bytes1, l_bytes2, l_play_position;
+ int i_bytes1, i_bytes2, i_play_position;
HRESULT dsresult;
/* protect buffer access (because of DirectSoundThread) */
* as soon as possible. This is why we query the play position */
dsresult = IDirectSoundBuffer_GetCurrentPosition(
p_aout->p_sys->p_dsbuffer,
- &l_play_position,
- &p_aout->p_sys->l_write_position );
+ &i_play_position,
+ &p_aout->p_sys->i_write_position );
if( dsresult != DS_OK )
{
intf_WarnMsg( 3, "aout: aout_Play can'get buffer position");
- p_aout->p_sys->l_write_position = 0;
+ p_aout->p_sys->i_write_position = 0;
}
intf_WarnMsg( 3, "aout: aout_Play underflow");
/* reinitialise the underflow detection counters */
p_aout->p_sys->b_buffer_underflown = 0;
- p_aout->p_sys->l_data_written_from_beginning = 0;
+ p_aout->p_sys->i_data_written_from_beginning = 0;
-#define WRITE_P p_aout->p_sys->l_write_position
-#define PLAY_P l_play_position
-#define BUF_SIZE p_aout->p_sys->l_buffer_size
- p_aout->p_sys->l_data_played_from_beginning = -(WRITE_P %(BUF_SIZE/2));
+#define WRITE_P p_aout->p_sys->i_write_position
+#define PLAY_P i_play_position
+#define BUF_SIZE p_aout->p_sys->i_buffer_size
+ p_aout->p_sys->i_data_played_from_beginning = -(WRITE_P %(BUF_SIZE/2));
if( PLAY_P < BUF_SIZE/2 && WRITE_P > BUF_SIZE/2 )
{
- p_aout->p_sys->l_data_played_from_beginning -= (BUF_SIZE/2);
+ p_aout->p_sys->i_data_played_from_beginning -= (BUF_SIZE/2);
}
if( PLAY_P > BUF_SIZE/2 && WRITE_P < BUF_SIZE/2 )
{
- p_aout->p_sys->l_data_played_from_beginning -= (BUF_SIZE/2);
+ p_aout->p_sys->i_data_played_from_beginning -= (BUF_SIZE/2);
}
#undef WRITE_P
#undef PLAY_P
/* Before copying anything, we have to lock the buffer */
dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
- p_aout->p_sys->l_write_position, /* Offset of lock start */
+ p_aout->p_sys->i_write_position, /* Offset of lock start */
i_size, /* Number of bytes to lock */
&p_write_position, /* Address of lock start */
- &l_bytes1, /* Count of bytes locked before wrap around */
+ &i_bytes1, /* Count of bytes locked before wrap around */
&p_start_buffer, /* Buffer adress (if wrap around) */
- &l_bytes2, /* Count of bytes after wrap around */
+ &i_bytes2, /* Count of bytes after wrap around */
0); /* Flags */
if( dsresult == DSERR_BUFFERLOST )
{
IDirectSoundBuffer_Restore( p_aout->p_sys->p_dsbuffer );
dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
- p_aout->p_sys->l_write_position,
+ p_aout->p_sys->i_write_position,
i_size,
&p_write_position,
- &l_bytes1,
+ &i_bytes1,
&p_start_buffer,
- &l_bytes2,
+ &i_bytes2,
0);
}
}
/* Now do the actual memcpy (two memcpy because the buffer is circular) */
- memcpy( p_write_position, buffer, l_bytes1 );
+ memcpy( p_write_position, buffer, i_bytes1 );
if( p_start_buffer != NULL )
{
- memcpy( p_start_buffer, buffer + l_bytes1, l_bytes2 );
+ memcpy( p_start_buffer, buffer + i_bytes1, i_bytes2 );
}
/* Now the data has been copied, unlock the buffer */
IDirectSoundBuffer_Unlock( p_aout->p_sys->p_dsbuffer,
- p_write_position, l_bytes1, p_start_buffer, l_bytes2 );
+ p_write_position, i_bytes1, p_start_buffer, i_bytes2 );
/* Update the write position index of the buffer*/
- p_aout->p_sys->l_write_position += i_size;
- p_aout->p_sys->l_write_position %= p_aout->p_sys->l_buffer_size;
- p_aout->p_sys->l_data_written_from_beginning += i_size;
+ p_aout->p_sys->i_write_position += i_size;
+ p_aout->p_sys->i_write_position %= p_aout->p_sys->i_buffer_size;
+ p_aout->p_sys->i_data_written_from_beginning += i_size;
vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
memset(&waveformat, 0, sizeof(WAVEFORMATEX));
waveformat.wFormatTag = WAVE_FORMAT_PCM;
waveformat.nChannels = p_aout->i_channels;
- waveformat.nSamplesPerSec = p_aout->l_rate;
+ waveformat.nSamplesPerSec = p_aout->i_rate;
waveformat.wBitsPerSample = 16;
waveformat.nBlockAlign = waveformat.wBitsPerSample / 8 *
waveformat.nChannels;
memset(&dsbcaps, 0, sizeof(DSBCAPS));
dsbcaps.dwSize = sizeof(DSBCAPS);
IDirectSoundBuffer_GetCaps( p_aout->p_sys->p_dsbuffer, &dsbcaps );
- p_aout->p_sys->l_buffer_size = dsbcaps.dwBufferBytes;
- p_aout->p_sys->l_write_position = 0;
+ p_aout->p_sys->i_buffer_size = dsbcaps.dwBufferBytes;
+ p_aout->p_sys->i_write_position = 0;
- intf_WarnMsg( 3, "aout: DirectX DirectxCreateSecondaryBuffer: %li",
- p_aout->p_sys->l_buffer_size);
+ intf_WarnMsg( 3, "aout: DirectX DirectxCreateSecondaryBuffer: %i",
+ p_aout->p_sys->i_buffer_size);
/* Now the secondary buffer is created, we need to setup its position
* notification */
{
HANDLE notification_events[2];
VOID *p_write_position, *p_start_buffer;
- long l_bytes1, l_bytes2;
+ int i_bytes1, i_bytes2;
HRESULT dsresult;
- long l_buffer_size, l_play_position, l_data_in_buffer;
+ int i_buffer_size, i_play_position, i_data_in_buffer;
notification_events[0]=p_aout->p_sys->notification_events[0].hEventNotify;
notification_events[1]=p_aout->p_sys->notification_events[1].hEventNotify;
while( !p_aout->p_sys->b_notification_thread_die )
{
/* wait for the position notification */
- l_play_position = WaitForMultipleObjects( 2, notification_events,
+ i_play_position = WaitForMultipleObjects( 2, notification_events,
0, INFINITE );
vlc_mutex_lock( &p_aout->p_sys->buffer_lock );
}
/* check for buffer underflow (bodge for wrap around) */
- l_buffer_size = p_aout->p_sys->l_buffer_size;
- l_play_position = (l_play_position - WAIT_OBJECT_0) * l_buffer_size/2;
- p_aout->p_sys->l_data_played_from_beginning += (l_buffer_size/2);
- l_data_in_buffer = p_aout->p_sys->l_data_written_from_beginning -
- p_aout->p_sys->l_data_played_from_beginning;
+ i_buffer_size = p_aout->p_sys->i_buffer_size;
+ i_play_position = (i_play_position - WAIT_OBJECT_0) * i_buffer_size/2;
+ p_aout->p_sys->i_data_played_from_beginning += (i_buffer_size/2);
+ i_data_in_buffer = p_aout->p_sys->i_data_written_from_beginning -
+ p_aout->p_sys->i_data_played_from_beginning;
/* detect wrap-around */
- if( l_data_in_buffer < (-l_buffer_size/2) )
+ if( i_data_in_buffer < (-i_buffer_size/2) )
{
- intf_WarnMsg(3,"aout: DirectSoundThread wrap around: %li", l_data_in_buffer);
- l_data_in_buffer += l_buffer_size;
+ intf_WarnMsg(3,"aout: DirectSoundThread wrap around: %i", i_data_in_buffer);
+ i_data_in_buffer += i_buffer_size;
}
/* detect underflow */
- if( l_data_in_buffer <= 0 )
+ if( i_data_in_buffer <= 0 )
{
- intf_WarnMsg(3,"aout: DirectSoundThread underflow: %li", l_data_in_buffer);
+ intf_WarnMsg(3,"aout: DirectSoundThread underflow: %li", i_data_in_buffer);
p_aout->p_sys->b_buffer_underflown = 1;
- p_aout->p_sys->l_write_position =
- (l_play_position + l_buffer_size/2) % l_buffer_size;
- l_data_in_buffer = l_buffer_size / 2;
- p_aout->p_sys->l_data_played_from_beginning -= (l_buffer_size/2);
+ p_aout->p_sys->i_write_position =
+ (i_play_position + i_buffer_size/2) % i_buffer_size;
+ i_data_in_buffer = i_buffer_size / 2;
+ p_aout->p_sys->i_data_played_from_beginning -= (i_buffer_size/2);
}
/* Before copying anything, we have to lock the buffer */
dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
- p_aout->p_sys->l_write_position, /* Offset of lock start */
- l_buffer_size - l_data_in_buffer, /* Number of bytes */
+ p_aout->p_sys->i_write_position, /* Offset of lock start */
+ i_buffer_size - i_data_in_buffer, /* Number of bytes */
&p_write_position, /* Address of lock start */
- &l_bytes1, /* Count of bytes locked before wrap around */
+ &i_bytes1, /* Count of bytes locked before wrap around */
&p_start_buffer, /* Buffer adress (if wrap around) */
- &l_bytes2, /* Count of bytes after wrap around */
+ &i_bytes2, /* Count of bytes after wrap around */
0); /* Flags */
if( dsresult == DSERR_BUFFERLOST )
{
IDirectSoundBuffer_Restore( p_aout->p_sys->p_dsbuffer );
dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
- p_aout->p_sys->l_write_position,
- l_buffer_size - l_data_in_buffer,
+ p_aout->p_sys->i_write_position,
+ i_buffer_size - i_data_in_buffer,
&p_write_position,
- &l_bytes1,
+ &i_bytes1,
&p_start_buffer,
- &l_bytes2,
+ &i_bytes2,
0);
}
if( dsresult != DS_OK )
}
/* Now do the actual memcpy (two because the buffer is circular) */
- memset( p_write_position, 0, l_bytes1 );
+ memset( p_write_position, 0, i_bytes1 );
if( p_start_buffer != NULL )
{
- memset( p_start_buffer, 0, l_bytes2 );
+ memset( p_start_buffer, 0, i_bytes2 );
}
/* Now the data has been copied, unlock the buffer */
IDirectSoundBuffer_Unlock( p_aout->p_sys->p_dsbuffer,
- p_write_position, l_bytes1, p_start_buffer, l_bytes2 );
+ p_write_position, i_bytes1, p_start_buffer, i_bytes2 );
vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
* aout_dsp.c : dsp functions library
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: aout_dsp.c,v 1.22 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_dsp.c,v 1.23 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
static int aout_SetFormat( aout_thread_t *p_aout )
{
int i_format;
- long l_rate;
- boolean_t b_stereo = p_aout->b_stereo;
+ int i_rate;
+ boolean_t b_stereo;
/* Reset the DSP device */
if( ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
}
/* Set the number of channels */
+ b_stereo = ( p_aout->i_channels >= 2 );
+
if( ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_STEREO, &b_stereo ) < 0 )
{
intf_ErrMsg( "aout error: can't set number of audio channels (%i)",
return( -1 );
}
- if( b_stereo != p_aout->b_stereo )
+ if( (1 + b_stereo) != p_aout->i_channels )
{
- intf_WarnMsg( 2, "aout warning: number of audio channels not supported"
- " (%i)", p_aout->i_channels );
- p_aout->b_stereo = b_stereo;
+ intf_WarnMsg( 2, "aout warning: %i audio channels not supported",
+ p_aout->i_channels );
p_aout->i_channels = 1 + b_stereo;
}
/* Set the output rate */
- l_rate = p_aout->l_rate;
+ i_rate = p_aout->i_rate;
if( ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_SPEED, &l_rate ) < 0 )
{
- intf_ErrMsg( "aout error: can't set audio output rate (%li)",
- p_aout->l_rate );
+ intf_ErrMsg( "aout error: can't set audio output rate (%i)",
+ p_aout->i_rate );
return( -1 );
}
- if( l_rate != p_aout->l_rate )
+ if( i_rate != p_aout->i_rate )
{
intf_WarnMsg( 1, "aout warning: audio output rate not supported (%li)",
- p_aout->l_rate );
- p_aout->l_rate = l_rate;
+ p_aout->i_rate );
+ p_aout->i_rate = i_rate;
}
return( 0 );
* aout_GetBufInfo: buffer status query
*****************************************************************************
* This function fills in the audio_buf_info structure :
- * - int fragments : number of available fragments (partially usend ones not
- * counted)
+ * - returns : number of available fragments (not partially used ones)
* - int fragstotal : total number of fragments allocated
* - int fragsize : size of a fragment in bytes
* - int bytes : available space in bytes (includes partially used fragments)
* Note! 'bytes' could be more than fragments*fragsize
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_GETOSPACE,
&p_aout->p_sys->audio_buf );
* aout_dummy.c : dummy audio output plugin
*****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN
- * $Id: aout_dummy.c,v 1.19 2002/02/15 13:32:53 sam Exp $
+ * $Id: aout_dummy.c,v 1.20 2002/02/24 22:06:50 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
/*****************************************************************************
* aout_GetBufInfo: returns available bytes in buffer
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
- return( sizeof(s16) * l_buffer_limit + 1 ); /* value big enough to sleep */
+ return( sizeof(s16) * i_buffer_limit + 1 ); /* value big enough to sleep */
}
/*****************************************************************************
* aout_esd.c : Esound functions library
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
- * $Id: aout_esd.c,v 1.20 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_esd.c,v 1.21 2002/02/24 22:06:50 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
}
/* Initialize some variables */
- p_aout->l_rate = esd_audio_rate; /* We use actual esd rate value, not
- * initial value */
+ p_aout->i_rate = esd_audio_rate; /* We use actual esd rate value, not
+ * initial value */
i_bits = ESD_BITS16;
i_mode = ESD_STREAM;
* and try to open /dev/dsp if there's no EsounD */
if ( (p_aout->p_sys->i_fd
= esd_play_stream_fallback(p_aout->p_sys->esd_format,
- p_aout->l_rate, NULL, "vlc")) < 0 )
+ p_aout->i_rate, NULL, "vlc")) < 0 )
{
intf_ErrMsg( "aout error: can't open esound socket"
" (format 0x%08x at %ld Hz)",
- p_aout->p_sys->esd_format, p_aout->l_rate );
+ p_aout->p_sys->esd_format, p_aout->i_rate );
return( -1 );
}
/*****************************************************************************
* aout_GetBufInfo: buffer status query
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
/* arbitrary value that should be changed */
- return( l_buffer_limit );
+ return( i_buffer_limit );
}
/*****************************************************************************
{
if (p_aout->p_sys->esd_format & ESD_BITS16)
{
- i_amount = (44100 * (ESD_BUF_SIZE + 64)) / p_aout->l_rate;
+ i_amount = (44100 * (ESD_BUF_SIZE + 64)) / p_aout->i_rate;
}
else
{
- i_amount = (44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
+ i_amount = (44100 * (ESD_BUF_SIZE + 128)) / p_aout->i_rate;
}
}
else
{
if (p_aout->p_sys->esd_format & ESD_BITS16)
{
- i_amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
+ i_amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / p_aout->i_rate;
}
else
{
- i_amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / p_aout->l_rate;
+ i_amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / p_aout->i_rate;
}
}
* lpcm_decoder_thread.c: lpcm decoder thread
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: lpcm_adec.c,v 1.12 2002/02/19 00:50:19 sam Exp $
+ * $Id: lpcm_adec.c,v 1.13 2002/02/24 22:06:50 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Henri Fallon <henri@videolan.org>
NULL, NULL);
/* Creating the audio output fifo */
- p_lpcmdec->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO, 2, 48000,
- 0, LPCMDEC_FRAME_SIZE/2, NULL );
+ p_lpcmdec->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM, 2, 48000,
+ LPCMDEC_FRAME_SIZE/2, NULL );
if ( p_lpcmdec->p_aout_fifo == NULL )
{
return( -1 );
byte_t byte1, byte2;
CurrentPTS( &p_lpcmdec->bit_stream,
- &p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame],
+ &p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame],
NULL );
- if( !p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] )
+ if( !p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame] )
{
- p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] =
+ p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame] =
LAST_MDATE;
}
buffer = ((byte_t *)p_lpcmdec->p_aout_fifo->buffer) +
- (p_lpcmdec->p_aout_fifo->l_end_frame * LPCMDEC_FRAME_SIZE);
+ (p_lpcmdec->p_aout_fifo->i_end_frame * LPCMDEC_FRAME_SIZE);
RemoveBits32(&p_lpcmdec->bit_stream);
byte1 = GetBits(&p_lpcmdec->bit_stream, 8) ;
}
vlc_mutex_lock (&p_lpcmdec->p_aout_fifo->data_lock);
- p_lpcmdec->p_aout_fifo->l_end_frame =
- (p_lpcmdec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+ p_lpcmdec->p_aout_fifo->i_end_frame =
+ (p_lpcmdec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_lpcmdec->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_lpcmdec->p_aout_fifo->data_lock);
}
* aout_darwin.c : Darwin audio output plugin
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: aout_macosx.c,v 1.13 2002/02/19 00:50:19 sam Exp $
+ * $Id: aout_macosx.c,v 1.14 2002/02/24 22:06:50 sam Exp $
*
* Authors: Colin Delacroix <colin@zoy.org>
*
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
* not be forced to compute the same value twice
*/
p_aout->p_sys->ui_deviceBufferSize =
- 2 * 2 * sizeof(s16) * ((s64)p_aout->l_rate * AOUT_BUFFER_DURATION) / 1000000;
+ 2 * 2 * sizeof(s16) * ((s64)p_aout->i_rate * AOUT_BUFFER_DURATION) / 1000000;
/* Allocate memory for audio */
p_aout->p_sys->p_Data = NewPtrClear( p_aout->p_sys->ui_deviceBufferSize );
// format.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
// format.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
- format.mSampleRate = p_aout->l_rate;
+ format.mSampleRate = p_aout->i_rate;
format.mChannelsPerFrame = p_aout->i_channels;
err = AudioDeviceSetProperty( p_aout->p_sys->device, 0, 0, false,
/*****************************************************************************
* aout_GetBufInfo: returns available bytes in buffer
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
return( 0 ); // Send data as soon as possible
*
* intf_ErrMsg( "mad_adec: libmad_header samplerate %d", p_libmad_header->samplerate);
*
- * p_mad_adec->p_aout_fifo->l_rate = p_libmad_header->samplerate;
+ * p_mad_adec->p_aout_fifo->i_rate = p_libmad_header->samplerate;
* mad_timer_add(&p_mad_adec->libmad_timer,p_libmad_header->duration);
*
* return MAD_FLOW_CONTINUE;
if (p_mad_adec->p_aout_fifo==NULL)
{
p_mad_adec->p_aout_fifo = aout_CreateFifo(
- AOUT_ADEC_STEREO_FIFO, /* fifo type */
- p_libmad_pcm->channels, /* nr. of channels */
- p_libmad_pcm->samplerate, /* frame rate in Hz ?*/
- 0, /* units */
- ADEC_FRAME_SIZE, /* frame size */
- NULL ); /* buffer */
+ AOUT_FIFO_PCM, /* fifo type */
+ p_libmad_pcm->channels, /* nr. of channels */
+ p_libmad_pcm->samplerate, /* frame rate in Hz ?*/
+ ADEC_FRAME_SIZE, /* frame size */
+ NULL ); /* buffer */
if ( p_mad_adec->p_aout_fifo == NULL )
{
intf_ErrMsg("mad_adec debug: in libmad_output aout fifo created");
}
- if (p_mad_adec->p_aout_fifo->l_rate != p_libmad_pcm->samplerate)
+ if (p_mad_adec->p_aout_fifo->i_rate != p_libmad_pcm->samplerate)
{
intf_ErrMsg( "mad_adec: libmad_output samplerate is changing from [%d] Hz to [%d] Hz, sample size [%d], error_code [%0x]",
- p_mad_adec->p_aout_fifo->l_rate, p_libmad_pcm->samplerate,
+ p_mad_adec->p_aout_fifo->i_rate, p_libmad_pcm->samplerate,
p_libmad_pcm->length, p_mad_adec->libmad_decoder->sync->stream.error);
- p_mad_adec->p_aout_fifo->l_rate = p_libmad_pcm->samplerate;
+ p_mad_adec->p_aout_fifo->i_rate = p_libmad_pcm->samplerate;
}
if( p_mad_adec->i_current_pts )
{
- p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->l_end_frame]
+ p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->i_end_frame]
= p_mad_adec->i_current_pts;
}
else
{
- p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->l_end_frame]
+ p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->i_end_frame]
= LAST_MDATE;
}
mad_timer_add(&p_mad_adec->libmad_timer,p_libmad_header->duration);
- buffer = ((byte_t *)p_mad_adec->p_aout_fifo->buffer) + (p_mad_adec->p_aout_fifo->l_end_frame * MAD_OUTPUT_SIZE);
+ buffer = ((byte_t *)p_mad_adec->p_aout_fifo->buffer) + (p_mad_adec->p_aout_fifo->i_end_frame * MAD_OUTPUT_SIZE);
while (nsamples--)
{
}
vlc_mutex_lock (&p_mad_adec->p_aout_fifo->data_lock);
- p_mad_adec->p_aout_fifo->l_end_frame = (p_mad_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+ p_mad_adec->p_aout_fifo->i_end_frame = (p_mad_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_mad_adec->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_mad_adec->p_aout_fifo->data_lock);
* adec_layer1.c: MPEG Layer I audio decoder
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: adec_layer1.c,v 1.5 2001/12/30 07:09:55 sam Exp $
+ * $Id: adec_layer1.c,v 1.6 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
for ( s = 0 ; s < 12; s++)
{
- s16 * XXX_buf;
-
for (i_sb = 0; i_sb < 32; i_sb++)
{
if (!allocation[i_sb])
}
}
- DCT32 (sample, &p_adec->bank_0);
- XXX_buf = buffer;
- PCM (&p_adec->bank_0, &XXX_buf, 1);
+ DCT32( &p_adec->bank_0, sample );
+ PCM (&p_adec->bank_0, buffer, 1);
buffer += 32;
}
for (s = 0; s < 12; s++)
{
- s16 * XXX_buf;
-
for (i_sb = 0; i_sb < bound; i_sb++)
{
if (!allocation_0[i_sb])
}
}
- DCT32 (sample_0, &p_adec->bank_0);
- XXX_buf = buffer;
- PCM (&p_adec->bank_0, &XXX_buf, 2);
- DCT32 (sample_1, &p_adec->bank_1);
- XXX_buf = buffer+1;
- PCM (&p_adec->bank_1, &XXX_buf, 2);
+ DCT32( &p_adec->bank_0, sample_0 );
+ PCM (&p_adec->bank_0, buffer, 2);
+ DCT32( &p_adec->bank_1, sample_1 );
+ PCM (&p_adec->bank_1, buffer + 1, 2);
buffer += 64;
}
* adec_layer2.c: MPEG Layer II audio decoder
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: adec_layer2.c,v 1.5 2001/12/30 07:09:55 sam Exp $
+ * $Id: adec_layer2.c,v 1.6 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
{
for (gr1 = 0; gr1 < 4; gr1++)
{
- s16 * XXX_buf;
-
for (sb = 0; sb < sblimit; sb++)
{
int code;
for (s = 0; s < 3; s++)
{
- DCT32 (sample[s], &p_adec->bank_0);
- XXX_buf = buffer;
- PCM (&p_adec->bank_0, &XXX_buf, 2);
+ DCT32( &p_adec->bank_0, sample[s] );
+ PCM( &p_adec->bank_0, buffer, 2 );
/* FIXME: one shouldn't have to do it twice ! */
- DCT32 (sample[s], &p_adec->bank_1);
- XXX_buf = buffer+1;
- PCM (&p_adec->bank_1, &XXX_buf, 2);
+ DCT32( &p_adec->bank_1, sample[s] );
+ PCM( &p_adec->bank_1, buffer + 1, 2 );
buffer += 64;
}
{
for (gr1 = 0; gr1 < 4; gr1++)
{
- s16 * XXX_buf;
-
for (sb = 0; sb < bound; sb++)
{
int code;
for (s = 0; s < 3; s++)
{
- DCT32 (sample_0[s], &p_adec->bank_0);
- XXX_buf = buffer;
- PCM (&p_adec->bank_0, &XXX_buf, 2);
+ DCT32( &p_adec->bank_0, sample_0[s] );
+ PCM( &p_adec->bank_0, buffer, 2 );
- DCT32 (sample_1[s], &p_adec->bank_1);
- XXX_buf = buffer+1;
- PCM (&p_adec->bank_1, &XXX_buf, 2);
+ DCT32( &p_adec->bank_1, sample_1[s] );
+ PCM( &p_adec->bank_1, buffer + 1, 2 );
buffer += 64;
}
* adec_math.c: Inverse Discrete Cosine Transform and Pulse Code Modulation
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: adec_math.c,v 1.1 2001/11/13 12:09:18 henri Exp $
+ * $Id: adec_math.c,v 1.2 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
* See fastdct.ps, and fast.tar.gz for a (Fortran :) implementation.
*****************************************************************************/
-void DCT32(float *x, adec_bank_t *b)
+void DCT32( adec_bank_t *b, float *x )
{
/* cosine coefficients */
static const float c2 = .70710678118655;
* Compute 32 PCM samples with a convolution product
*****************************************************************************/
-void PCM(adec_bank_t *b, s16 **pcm, int jump)
+void PCM(adec_bank_t *b, s16 *p_pcm, int jump)
{
/* scale factor */
#define F -32768
if ((tmp += *f++ * *v) > 32767)
{
/* ceiling saturation */
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
/* floor saturation */
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
v += 15;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 15;
}
break;
tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767)
{
- **pcm = 0x7FFF;
+ *p_pcm = 0x7FFF;
}
else if (tmp < -32768)
{
- **pcm = 0x8000;
+ *p_pcm = 0x8000;
}
else
{
- **pcm = (s16)tmp;
+ *p_pcm = (s16)tmp;
}
- *pcm += jump;
+ p_pcm += jump;
v += 31;
}
break;
* adec_math.h : PCM and DCT
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: adec_math.h,v 1.1 2001/11/13 12:09:18 henri Exp $
+ * $Id: adec_math.h,v 1.2 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
*
/*****************************************************************************
* Prototypes
*****************************************************************************/
-void DCT32(float *x, adec_bank_t *b);
-void PCM(adec_bank_t *b, s16 **pcm, int jump);
+void DCT32 ( adec_bank_t *, float * );
+void PCM ( adec_bank_t *, s16 *, int );
* mpeg_adec.c: MPEG audio decoder thread
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: mpeg_adec.c,v 1.20 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: mpeg_adec.c,v 1.21 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
*****************************************************************************/
static void DecodeThread( adec_thread_t * p_adec )
{
- s16 * buffer;
+ s16 *p_buffer;
adec_sync_info_t sync_info;
if( ! adec_SyncFrame (p_adec, &sync_info) )
/* Create the output fifo if it doesn't exist yet */
if( p_adec->p_aout_fifo == NULL )
{
- int fifo_type;
- int channels;
+ int i_channels;
if( p_main->b_stereo )
{
intf_WarnMsg( 4, "adec info: setting stereo output" );
- fifo_type = AOUT_ADEC_STEREO_FIFO;
- channels = 2;
+ i_channels = 2;
}
else if( sync_info.b_stereo )
{
- fifo_type = AOUT_ADEC_STEREO_FIFO;
- channels = 2;
+ i_channels = 2;
}
else
{
- fifo_type = AOUT_ADEC_MONO_FIFO;
- channels = 1;
+ i_channels = 1;
}
- p_adec->p_aout_fifo = aout_CreateFifo( fifo_type, channels,
- sync_info.sample_rate, 0, ADEC_FRAME_SIZE, NULL );
+ p_adec->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM, i_channels,
+ sync_info.sample_rate, ADEC_FRAME_SIZE, NULL );
if( p_adec->p_aout_fifo == NULL)
{
- intf_ErrMsg( "adec error: failed to create Audio Output "
- "Fifo." );
+ intf_ErrMsg( "adec error: failed to create aout fifo" );
p_adec->p_fifo->b_error = 1;
return;
}
p_adec->i_sync = 1;
- buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
- + (p_adec->p_aout_fifo->l_end_frame * ADEC_FRAME_SIZE);
+ p_buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
+ + (p_adec->p_aout_fifo->i_end_frame * ADEC_FRAME_SIZE);
CurrentPTS( &p_adec->bit_stream,
- &p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame],
+ &p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame],
NULL );
- if( !p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] )
+ if( !p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame] )
{
- p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] =
+ p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame] =
LAST_MDATE;
}
- if( adec_DecodeFrame (p_adec, buffer) )
+ if( adec_DecodeFrame (p_adec, p_buffer) )
{
/* Ouch, failed decoding... We'll have to resync */
p_adec->i_sync = 0;
else
{
vlc_mutex_lock (&p_adec->p_aout_fifo->data_lock);
- p_adec->p_aout_fifo->l_end_frame =
- (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+ p_adec->p_aout_fifo->i_end_frame =
+ (p_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_adec->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_adec->p_aout_fifo->data_lock);
}
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
pp.buf.block.frags_min = 1;
pp.format.interleave = 1;
- pp.format.rate = p_aout->l_rate;
+ pp.format.rate = p_aout->i_rate;
pp.format.voices = p_aout->i_channels;
switch( p_aout->i_format )
}
pp.buf.block.frag_size =
- (((s64)p_aout->l_rate * AOUT_BUFFER_DURATION) / 1000000) *
+ (((s64)p_aout->i_rate * AOUT_BUFFER_DURATION) / 1000000) *
p_aout->i_channels * i_bytes_per_sample;
/* set parameters */
* of data to play, it switches to the "underrun" status. It has to
* be flushed and re-prepared
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
int i_ret;
snd_pcm_channel_status_t status;
* aout_sdl.c : audio sdl functions library
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: aout_sdl.c,v 1.26 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: aout_sdl.c,v 1.27 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
static int aout_Open( aout_thread_t *p_aout )
{
SDL_AudioSpec desired;
- int i_channels = p_aout->b_stereo ? 2 : 1;
if( SDL_WasInit( SDL_INIT_AUDIO ) != 0 )
{
p_aout->p_sys->audio_buf = malloc( OVERFLOWLIMIT );
/* Initialize some variables */
- desired.freq = p_aout->l_rate;
/* TODO: write conversion beetween AOUT_FORMAT_DEFAULT
* AND AUDIO* from SDL. */
+ desired.freq = p_aout->i_rate;
desired.format = AUDIO_S16LSB; /* stereo 16 bits */
- desired.channels = i_channels;
+ desired.channels = p_aout->i_channels;
desired.callback = aout_SDLCallback;
desired.userdata = p_aout->p_sys;
desired.samples = 1024;
{
/* TODO: finish and clean this */
SDL_AudioSpec desired;
- int i_stereo = p_aout->b_stereo ? 2 : 1;
/*i_format = p_aout->i_format;*/
- desired.freq = p_aout->l_rate; /* Set the output rate */
+ desired.freq = p_aout->i_rate; /* Set the output rate */
desired.format = AUDIO_S16LSB; /* stereo 16 bits */
- desired.channels = i_stereo;
+ desired.channels = p_aout->i_channels;
desired.callback = aout_SDLCallback;
desired.userdata = p_aout->p_sys;
desired.samples = 2048;
* aout_GetBufInfo: buffer status query
*****************************************************************************
* returns the number of bytes in the audio buffer compared to the size of
- * l_buffer_limit...
+ * i_buffer_limit...
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
- if(l_buffer_limit > p_aout->p_sys->i_audio_end)
+ if(i_buffer_limit > p_aout->p_sys->i_audio_end)
{
/* returning 0 here juste gives awful sound in the speakers :/ */
- return( l_buffer_limit );
+ return( i_buffer_limit );
}
- return( p_aout->p_sys->i_audio_end - l_buffer_limit);
+ return( p_aout->p_sys->i_audio_end - i_buffer_limit);
}
/*****************************************************************************
* waveout.c : Windows waveOut plugin for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: waveout.c,v 1.3 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: waveout.c,v 1.4 2002/02/24 22:06:50 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
*****************************************************************************/
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
-static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
+static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
/* Check if the format has changed */
if( (p_aout->p_sys->waveformat.nChannels != p_aout->i_channels) ||
- (p_aout->p_sys->waveformat.nSamplesPerSec != p_aout->l_rate) )
+ (p_aout->p_sys->waveformat.nSamplesPerSec != p_aout->i_rate) )
{
if( waveOutClose( p_aout->p_sys->h_waveout ) == MMSYSERR_NOERROR )
{
* returns the number of bytes in the audio buffer that have not yet been
* sent to the sound device.
*****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
{
MMTIME mmtime;
!= MMSYSERR_NOERROR || (mmtime.wType != TIME_BYTES) )
{
intf_WarnMsg( 3, "aout: aout_GetBufInfo waveOutGetPosition failed");
- return l_buffer_limit;
+ return i_buffer_limit;
}
/* Set sound format */
p_aout->p_sys->waveformat.wFormatTag = WAVE_FORMAT_PCM;
p_aout->p_sys->waveformat.nChannels = p_aout->i_channels;
- p_aout->p_sys->waveformat.nSamplesPerSec = p_aout->l_rate;
+ p_aout->p_sys->waveformat.nSamplesPerSec = p_aout->i_rate;
p_aout->p_sys->waveformat.wBitsPerSample = 16;
p_aout->p_sys->waveformat.nBlockAlign =
p_aout->p_sys->waveformat.wBitsPerSample / 8 * p_aout->i_channels;
+++ /dev/null
-/*****************************************************************************
- * aout_common.c: generic audio output functions
- *****************************************************************************
- * Copyright (C) 1999-2002 VideoLAN
- * $Id: aout_common.c,v 1.3 2002/02/19 00:50:19 sam Exp $
- *
- * Authors: Michel Kaempf <maxx@via.ecp.fr>
- * Cyril Deguet <asmax@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#include <stdio.h> /* "intf_msg.h" */
-#include <stdlib.h> /* calloc(), malloc(), free() */
-#include <string.h>
-
-#include <videolan/vlc.h>
-
-#include "audio_output.h"
-#include "aout_common.h"
-
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
- mtime_t aout_date );
-
-/*****************************************************************************
- * Functions
- *****************************************************************************/
-
-/* Read data from decoder fifo, and put it in S32_buffer */
-void aout_FillBuffer( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
-{
- long l_buffer = 0;
- long l_buffer_limit, l_units;
-
- switch ( p_fifo->i_type )
- {
- case AOUT_EMPTY_FIFO:
-
- break;
-
- case AOUT_ADEC_MONO_FIFO:
- case AOUT_ADEC_STEREO_FIFO:
-
- l_units = p_aout->l_units;
- while ( l_units > 0 )
- {
- if( !p_fifo->b_next_frame )
- {
- if( NextFrame(p_aout, p_fifo, p_aout->date +
- ((((mtime_t)(l_buffer >> 1)) * 1000000) /
- ((mtime_t)p_aout->l_rate))) )
- {
- break;
- }
- }
- l_buffer_limit = p_aout->l_units << p_aout->b_stereo;
-
- while ( l_buffer < l_buffer_limit )
- {
- if( p_aout->b_stereo )
- {
- p_aout->s32_buffer[l_buffer++] +=
- (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->l_unit] );
- p_aout->s32_buffer[l_buffer++] +=
- (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->l_unit+1] );
- }
- else
- {
- p_aout->s32_buffer[l_buffer++] +=
- (s32)( ((s16 *)p_fifo->buffer)[p_fifo->l_unit] );
- }
-
- UpdateIncrement(&p_fifo->unit_increment, &p_fifo->l_unit);
-
- if( p_fifo->l_unit >= ((AOUT_FIFO_SIZE + 1) *
- (p_fifo->l_frame_size >> p_fifo->b_stereo)) )
- {
- p_fifo->l_unit -= ((AOUT_FIFO_SIZE + 1) *
- (p_fifo->l_frame_size >> p_fifo->b_stereo));
- }
- }
-
- if( p_fifo->l_units > l_units )
- {
- p_fifo->l_units -= l_units;
- break;
- }
- else
- {
- l_units -= p_fifo->l_units;
-
- vlc_mutex_lock( &p_fifo->data_lock );
- p_fifo->l_start_frame = p_fifo->l_next_frame;
- vlc_cond_signal( &p_fifo->data_wait );
- vlc_mutex_unlock( &p_fifo->data_lock );
-
- /* p_fifo->b_start_frame = 1; */
- p_fifo->l_next_frame += 1;
- p_fifo->l_next_frame &= AOUT_FIFO_SIZE;
- p_fifo->b_next_frame = 0;
- }
- }
- break;
-
- default:
-
- intf_ErrMsg("aout error: unknown fifo type (%i)", p_fifo->i_type);
- break;
- }
-}
-
-/* Following functions are local */
-
-static int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
- mtime_t aout_date )
-{
- long l_units, l_rate;
- u64 l_delta;
-
- /* We take the lock */
- vlc_mutex_lock( &p_fifo->data_lock );
-
- /* Are we looking for a dated start frame ? */
- if ( !p_fifo->b_start_frame )
- {
- while ( p_fifo->l_start_frame != p_fifo->l_end_frame )
- {
- if ( p_fifo->date[p_fifo->l_start_frame] != LAST_MDATE )
- {
- p_fifo->b_start_frame = 1;
- p_fifo->l_next_frame = (p_fifo->l_start_frame + 1) &
- AOUT_FIFO_SIZE;
- p_fifo->l_unit = p_fifo->l_start_frame *
- (p_fifo->l_frame_size >> (p_fifo->b_stereo));
- break;
- }
- p_fifo->l_start_frame = (p_fifo->l_start_frame + 1) &
- AOUT_FIFO_SIZE;
- }
-
- if ( p_fifo->l_start_frame == p_fifo->l_end_frame )
- {
- vlc_mutex_unlock( &p_fifo->data_lock );
- return( -1 );
- }
- }
-
- /* We are looking for the next dated frame */
- /* FIXME : is the output fifo full ?? */
- while ( !p_fifo->b_next_frame )
- {
- while ( p_fifo->l_next_frame != p_fifo->l_end_frame )
- {
- if ( p_fifo->date[p_fifo->l_next_frame] != LAST_MDATE )
- {
- p_fifo->b_next_frame = 1;
- break;
- }
- p_fifo->l_next_frame = (p_fifo->l_next_frame + 1) & AOUT_FIFO_SIZE;
- }
-
- while ( p_fifo->l_next_frame == p_fifo->l_end_frame )
- {
- vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
- if ( p_fifo->b_die )
- {
- vlc_mutex_unlock( &p_fifo->data_lock );
- return( -1 );
- }
- }
- }
-
- l_units = ((p_fifo->l_next_frame - p_fifo->l_start_frame) &
- AOUT_FIFO_SIZE) * (p_fifo->l_frame_size >> (p_fifo->b_stereo));
-
- l_delta = aout_date - p_fifo->date[p_fifo->l_start_frame];
-
-/* Resample if delta is too long */
- if( abs(l_delta) > MAX_DELTA )
- {
- l_rate = p_fifo->l_rate + (l_delta / 256);
- }
- else
- {
- l_rate = p_fifo->l_rate;
- }
-
- InitializeIncrement( &p_fifo->unit_increment, l_rate, p_aout->l_rate );
-
- p_fifo->l_units = (((l_units - (p_fifo->l_unit -
- (p_fifo->l_start_frame * (p_fifo->l_frame_size >>
- (p_fifo->b_stereo))))) * p_aout->l_rate) / l_rate) + 1;
-
- /* We release the lock before leaving */
- vlc_mutex_unlock( &p_fifo->data_lock );
- return( 0 );
-}
-
+++ /dev/null
-/*****************************************************************************
- * aout_common.h: audio output inner functions
- *****************************************************************************
- * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: aout_common.h,v 1.9 2002/01/15 11:51:11 asmax Exp $
- *
- * Authors: Michel Kaempf <maxx@via.ecp.fr>
- * Cyril Deguet <asmax@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- *****************************************************************************/
-
-
-/* Biggest difference allowed between scheduled playing date and actual date
- (in microseconds) */
-#define MAX_DELTA 10000
-
-
-/* Creating as many aout_Thread functions as configurations was one solution,
- * examining the different cases in the Thread loop of an unique function was
- * another. I chose the first solution. */
-void aout_U8Thread ( aout_thread_t * p_aout );
-void aout_S8Thread ( aout_thread_t * p_aout );
-void aout_U16Thread ( aout_thread_t * p_aout );
-void aout_S16Thread ( aout_thread_t * p_aout );
-void aout_SpdifThread ( aout_thread_t * p_aout );
-void aout_FillBuffer ( aout_thread_t * p_aout, aout_fifo_t * p_fifo );
-
-
-/* Generic main thread function "aout_XXXThread"
- */
-#define DECLARE_AOUT_THREAD( format, type, buffer_copy ) \
-void aout_##format##Thread( aout_thread_t * p_aout ) \
-{ \
- \
- int i_fifo; \
- long l_buffer, l_buffer_limit, l_bytes; \
- \
- /* As the s32_buffer was created with calloc(), we don't have to set this \
- * memory to zero and we can immediately jump into the thread's loop */ \
- while ( ! p_aout->b_die ) \
- { \
- vlc_mutex_lock( &p_aout->fifos_lock ); \
- \
- for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ ) \
- { \
- if( p_aout->fifo[i_fifo].b_die ) \
- { \
- aout_FreeFifo( &p_aout->fifo[i_fifo] ); \
- } \
- else \
- { \
- aout_FillBuffer( p_aout, &p_aout->fifo[i_fifo] ); \
- } \
- } \
- \
- vlc_mutex_unlock( &p_aout->fifos_lock ); \
- \
- l_buffer_limit = p_aout->l_units << p_aout->b_stereo; \
- \
- for ( l_buffer = 0; l_buffer < l_buffer_limit; l_buffer++ ) \
- { \
- ((type *)p_aout->buffer)[l_buffer] = (type)( buffer_copy * \
- p_aout->i_volume / 256 ); \
- p_aout->s32_buffer[l_buffer] = 0; \
- } \
- \
- l_bytes = p_aout->pf_getbufinfo( p_aout, l_buffer_limit ); \
- \
- p_aout->date = mdate() + ((((mtime_t)((l_bytes + 4 * \
- p_aout->i_latency) / \
- (sizeof(type) << p_aout->b_stereo))) * 1000000) / \
- ((mtime_t)p_aout->l_rate)) + p_main->i_desync; \
- \
- p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer, l_buffer_limit * \
- sizeof(type) ); \
- \
- if ( l_bytes > (l_buffer_limit * sizeof(type)) ) \
- { \
- msleep( p_aout->l_msleep ); \
- } \
- } \
- \
- vlc_mutex_lock( &p_aout->fifos_lock ); \
- \
- for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ ) \
- { \
- aout_FreeFifo( &p_aout->fifo[i_fifo] ); \
- } \
- \
- vlc_mutex_unlock( &p_aout->fifos_lock ); \
- \
-} \
-
-
-/*****************************************************************************
- * InitializeIncrement
- *****************************************************************************/
-static __inline__ void InitializeIncrement( aout_increment_t * p_increment,
- long l_numerator,
- long l_denominator )
-{
- p_increment->l_remainder = -l_denominator;
-
- p_increment->l_euclidean_integer = 0;
- while ( l_numerator >= l_denominator )
- {
- p_increment->l_euclidean_integer++;
- l_numerator -= l_denominator;
- }
-
- p_increment->l_euclidean_remainder = l_numerator;
-
- p_increment->l_euclidean_denominator = l_denominator;
-}
-
-
-/*****************************************************************************
- * UpdateIncrement
- *****************************************************************************/
-static __inline__ void UpdateIncrement( aout_increment_t * p_increment,
- long * p_integer )
-{
- if( (p_increment->l_remainder += p_increment->l_euclidean_remainder) >= 0 )
- {
- *p_integer += p_increment->l_euclidean_integer + 1;
- p_increment->l_remainder -= p_increment->l_euclidean_denominator;
- }
- else
- {
- *p_integer += p_increment->l_euclidean_integer;
- }
-}
-
* aout_ext-dec.c : exported fifo management functions
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: aout_ext-dec.c,v 1.12 2002/02/15 13:32:54 sam Exp $
+ * $Id: aout_ext-dec.c,v 1.13 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Cyril Deguet <asmax@via.ecp.fr>
#include <videolan/vlc.h>
#include "audio_output.h"
-#include "aout_common.h"
/*****************************************************************************
* aout_CreateFifo
*****************************************************************************/
-aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
- long l_units, long l_frame_size,
- void *p_buffer )
+aout_fifo_t * aout_CreateFifo( int i_format, int i_channels, int i_rate,
+ int i_frame_size, void *p_buffer )
{
aout_thread_t *p_aout;
- int i_fifo;
-
- intf_WarnMsg( 3, "aout info: fifo type %d, %d channels, rate %d, "
- "%d units, frame size %d",
- i_type, i_channels, l_rate, l_units, l_frame_size );
+ aout_fifo_t *p_fifo = NULL;
+ int i_index;
/* Spawn an audio output if there is none */
vlc_mutex_lock( &p_aout_bank->lock );
{
intf_WarnMsg( 1, "aout: no aout present, spawning one" );
- p_aout = aout_CreateThread( NULL, i_channels, l_rate );
+ p_aout = aout_CreateThread( NULL, i_channels, i_rate );
/* Everything failed */
if( p_aout == NULL )
}
/* temporary hack to switch output type (mainly for spdif)
* FIXME: to be adapted when several output are available */
- else if( p_aout_bank->pp_aout[0]->fifo[0].i_type != i_type )
+ else if( p_aout_bank->pp_aout[0]->fifo[0].i_format != i_format )
{
intf_WarnMsg( 1, "aout: changing aout type" );
aout_DestroyThread( p_aout_bank->pp_aout[0], NULL );
- p_aout = aout_CreateThread( NULL, i_channels, l_rate );
+ p_aout = aout_CreateThread( NULL, i_channels, i_rate );
/* Everything failed */
if( p_aout == NULL )
}
p_aout_bank->pp_aout[0] = p_aout;
-
}
else
{
/* Take the fifos lock */
vlc_mutex_lock( &p_aout->fifos_lock );
- /* Looking for a free fifo structure */
- for( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+ /* Look for a free fifo structure */
+ for( i_index = 0; i_index < AOUT_MAX_FIFOS; i_index++ )
{
- if( p_aout->fifo[i_fifo].i_type == AOUT_EMPTY_FIFO )
+ if( p_aout->fifo[i_index].i_format == AOUT_FIFO_NONE )
{
- /* Not very clever, but at least we know which fifo it is */
- p_aout->fifo[i_fifo].i_fifo = i_fifo;
+ p_fifo = &p_aout->fifo[i_index];
+ p_fifo->i_fifo = i_index;
break;
}
}
- if( i_fifo == AOUT_MAX_FIFOS )
+ if( p_fifo == NULL )
{
intf_ErrMsg( "aout error: no fifo available" );
vlc_mutex_unlock( &p_aout->fifos_lock );
}
/* Initialize the new fifo structure */
- switch ( p_aout->fifo[i_fifo].i_type = i_type )
+ switch ( p_fifo->i_format = i_format )
{
- case AOUT_ADEC_MONO_FIFO:
- case AOUT_ADEC_STEREO_FIFO:
- case AOUT_ADEC_SPDIF_FIFO:
- p_aout->fifo[i_fifo].b_die = 0;
-
- p_aout->fifo[i_fifo].i_channels = i_channels;
- p_aout->fifo[i_fifo].b_stereo = ( i_channels == 2 );
- p_aout->fifo[i_fifo].l_rate = l_rate;
-
- p_aout->fifo[i_fifo].l_frame_size = l_frame_size;
- /* Allocate the memory needed to store the audio frames. As the
- * fifo is a rotative fifo, we must be able to find out whether
- * the fifo is full or empty, that's why we must in fact allocate
- * memory for (AOUT_FIFO_SIZE+1) audio frames. */
- p_aout->fifo[i_fifo].buffer = malloc( sizeof(s16) *
- ( AOUT_FIFO_SIZE + 1 ) * l_frame_size );
- if ( p_aout->fifo[i_fifo].buffer == NULL )
+ case AOUT_FIFO_PCM:
+ case AOUT_FIFO_SPDIF:
+ p_fifo->b_die = 0;
+
+ p_fifo->i_channels = i_channels;
+ p_fifo->i_rate = i_rate;
+ p_fifo->i_frame_size = i_frame_size;
+
+ p_fifo->i_unit_limit = (AOUT_FIFO_SIZE + 1)
+ * (i_frame_size / i_channels);
+
+ /* Allocate the memory needed to store the audio frames and their
+ * dates. As the fifo is a rotative fifo, we must be able to find
+ * out whether the fifo is full or empty, that's why we must in
+ * fact allocate memory for (AOUT_FIFO_SIZE+1) audio frames. */
+ p_fifo->date = malloc( ( sizeof(s16) * i_frame_size
+ + sizeof(mtime_t) )
+ * ( AOUT_FIFO_SIZE + 1 ) );
+ if ( p_fifo->date == NULL )
{
- intf_ErrMsg( "aout error: cannot create frame buffer" );
- p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
+ intf_ErrMsg( "aout error: cannot create fifo data" );
+ p_fifo->i_format = AOUT_FIFO_NONE;
vlc_mutex_unlock( &p_aout->fifos_lock );
vlc_mutex_unlock( &p_aout_bank->lock );
return( NULL );
}
- /* Allocate the memory needed to store the dates of the frames */
- p_aout->fifo[i_fifo].date =
- malloc( sizeof(mtime_t) * ( AOUT_FIFO_SIZE + 1) );
-
- if ( p_aout->fifo[i_fifo].date == NULL )
- {
- intf_ErrMsg( "aout error: cannot create date buffer");
- free( p_aout->fifo[i_fifo].buffer );
- p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
- vlc_mutex_unlock( &p_aout->fifos_lock );
- vlc_mutex_unlock( &p_aout_bank->lock );
- return( NULL );
- }
+ p_fifo->buffer = (void *)p_fifo->date + sizeof(mtime_t)
+ * ( AOUT_FIFO_SIZE + 1 );
/* Set the fifo's buffer as empty (the first frame that is to be
* played is also the first frame that is not to be played) */
- p_aout->fifo[i_fifo].l_start_frame = 0;
- /* p_aout->fifo[i_fifo].l_next_frame = 0; */
- p_aout->fifo[i_fifo].l_end_frame = 0;
+ p_fifo->i_start_frame = 0;
+ /* p_fifo->i_next_frame = 0; */
+ p_fifo->i_end_frame = 0;
/* Waiting for the audio decoder to compute enough frames to work
* out the fifo's current rate (as soon as the decoder has decoded
* enough frames, the members of the fifo structure that are not
* initialized now will be calculated) */
- p_aout->fifo[i_fifo].b_start_frame = 0;
- p_aout->fifo[i_fifo].b_next_frame = 0;
+ p_fifo->b_start_frame = 0;
+ p_fifo->b_next_frame = 0;
break;
default:
intf_ErrMsg( "aout error: unknown fifo type 0x%x",
- p_aout->fifo[i_fifo].i_type );
- p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
+ p_fifo->i_format );
+ p_fifo->i_format = AOUT_FIFO_NONE;
vlc_mutex_unlock( &p_aout->fifos_lock );
vlc_mutex_unlock( &p_aout_bank->lock );
return( NULL );
vlc_mutex_unlock( &p_aout->fifos_lock );
vlc_mutex_unlock( &p_aout_bank->lock );
- intf_WarnMsg( 2, "aout info: fifo #%i allocated, %i channels, rate %li",
- p_aout->fifo[i_fifo].i_fifo, p_aout->fifo[i_fifo].i_channels,
- p_aout->fifo[i_fifo].l_rate );
+ intf_WarnMsg( 2, "aout info: fifo #%i allocated, %i channels, rate %li, "
+ "frame size %i", p_fifo->i_fifo, p_fifo->i_channels,
+ p_fifo->i_rate, p_fifo->i_frame_size );
/* Return the pointer to the fifo structure */
- return( &p_aout->fifo[i_fifo] );
+ return( p_fifo );
}
/*****************************************************************************
*****************************************************************************/
void aout_FreeFifo( aout_fifo_t * p_fifo )
{
- switch ( p_fifo->i_type )
+ switch ( p_fifo->i_format )
{
- case AOUT_EMPTY_FIFO:
+ case AOUT_FIFO_NONE:
break;
- case AOUT_ADEC_MONO_FIFO:
- case AOUT_ADEC_STEREO_FIFO:
- case AOUT_ADEC_SPDIF_FIFO:
+ case AOUT_FIFO_PCM:
+ case AOUT_FIFO_SPDIF:
- free( p_fifo->buffer );
free( p_fifo->date );
- p_fifo->i_type = AOUT_EMPTY_FIFO;
+ p_fifo->i_format = AOUT_FIFO_NONE;
break;
--- /dev/null
+/*****************************************************************************
+ * aout_pcm.c: PCM audio output functions
+ *****************************************************************************
+ * Copyright (C) 1999-2002 VideoLAN
+ * $Id: aout_pcm.c,v 1.1 2002/02/24 22:06:50 sam Exp $
+ *
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ * Cyril Deguet <asmax@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdio.h> /* "intf_msg.h" */
+#include <stdlib.h> /* calloc(), malloc(), free() */
+#include <string.h>
+
+#include <videolan/vlc.h>
+
+#include "audio_output.h"
+#include "aout_pcm.h"
+
+/* Biggest difference allowed between scheduled playing date and actual date
+ (in microseconds) */
+#define MAX_DELTA 10000
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static void FillBuffer( aout_thread_t * p_aout, aout_fifo_t * p_fifo );
+static int NextFrame ( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
+ mtime_t aout_date );
+
+ /*****************************************************************************
+ * Functions
+ *****************************************************************************/
+void aout_PCMThread( aout_thread_t * p_aout )
+{
+ int i_fifo;
+ int i_buffer, i_buffer_limit, i_bytes;
+
+ /* As the s32_buffer was created with calloc(), we don't have to set this
+ * memory to zero and we can immediately jump into the thread's loop */
+ while ( ! p_aout->b_die )
+ {
+ vlc_mutex_lock( &p_aout->fifos_lock );
+ for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+ {
+ if( p_aout->fifo[i_fifo].b_die )
+ {
+ aout_FreeFifo( &p_aout->fifo[i_fifo] );
+ }
+ else
+ {
+ FillBuffer( p_aout, &p_aout->fifo[i_fifo] );
+ }
+ }
+ vlc_mutex_unlock( &p_aout->fifos_lock );
+
+ i_buffer_limit = p_aout->i_units * p_aout->i_channels;
+
+ switch ( p_aout->i_format )
+ {
+ case AOUT_FMT_U8:
+ for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+ {
+ ((u8*)p_aout->buffer)[i_buffer] = (u8)(
+ (p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS / 256 + 128)
+ * p_aout->i_volume / 256);
+ p_aout->s32_buffer[i_buffer] = 0;
+ }
+ break;
+
+ case AOUT_FMT_S8:
+ for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+ {
+ ((s8*)p_aout->buffer)[i_buffer] = (s8)(
+ p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS / 256
+ * p_aout->i_volume / 256);
+ p_aout->s32_buffer[i_buffer] = 0;
+ }
+ break;
+
+ case AOUT_FMT_U16_LE:
+ case AOUT_FMT_U16_BE:
+ for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+ {
+ ((u16*)p_aout->buffer)[i_buffer] = (u16)(
+ (p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS + 128)
+ * p_aout->i_volume / 256);
+ p_aout->s32_buffer[i_buffer] = 0;
+ }
+ break;
+
+ case AOUT_FMT_S16_LE:
+ case AOUT_FMT_S16_BE:
+ for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+ {
+ ((s16*)p_aout->buffer)[i_buffer] = (s16)(
+ p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS
+ * p_aout->i_volume / 256);
+ p_aout->s32_buffer[i_buffer] = 0;
+ }
+ break;
+ }
+
+ i_bytes = p_aout->pf_getbufinfo( p_aout, i_buffer_limit );
+
+ switch ( p_aout->i_format )
+ {
+ case AOUT_FMT_U8:
+ case AOUT_FMT_S8:
+ p_aout->date = mdate() + ((((mtime_t)((i_bytes + 4 *
+ p_aout->i_latency) / p_aout->i_channels)) * 1000000) /
+ ((mtime_t)p_aout->i_rate)) + p_main->i_desync;
+
+ p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
+ i_buffer_limit );
+ break;
+
+ case AOUT_FMT_U16_LE:
+ case AOUT_FMT_U16_BE:
+ case AOUT_FMT_S16_LE:
+ case AOUT_FMT_S16_BE:
+ p_aout->date = mdate() + ((((mtime_t)((i_bytes + 4 *
+ p_aout->i_latency) / (2 * p_aout->i_channels))) * 1000000) /
+ ((mtime_t)p_aout->i_rate)) + p_main->i_desync;
+
+ p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
+ i_buffer_limit * 2 );
+ break;
+ }
+
+ if ( i_bytes > i_buffer_limit )
+ {
+ msleep( p_aout->i_msleep );
+ }
+ }
+
+ vlc_mutex_lock( &p_aout->fifos_lock );
+ for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+ {
+ aout_FreeFifo( &p_aout->fifo[i_fifo] );
+ }
+ vlc_mutex_unlock( &p_aout->fifos_lock );
+}
+
+/* Following functions are local */
+
+/*****************************************************************************
+ * InitializeIncrement: change i_x/i_y to i_a+i_b/i_c
+ *****************************************************************************/
+static __inline__ void InitializeIncrement( aout_increment_t * p_inc,
+ int i_x, int i_y )
+{
+ p_inc->i_r = -i_y;
+ p_inc->i_a = 0;
+
+ while ( i_x >= i_y )
+ {
+ p_inc->i_a++;
+ i_x -= i_y;
+ }
+
+ p_inc->i_b = i_x;
+ p_inc->i_c = i_y;
+}
+
+/*****************************************************************************
+ * UpdateIncrement
+ *****************************************************************************/
+static __inline__ void UpdateIncrement( aout_increment_t * p_inc,
+ int * pi_integer )
+{
+ if( (p_inc->i_r += p_inc->i_b) >= 0 )
+ {
+ *pi_integer += p_inc->i_a + 1;
+ p_inc->i_r -= p_inc->i_c;
+ }
+ else
+ {
+ *pi_integer += p_inc->i_a;
+ }
+}
+
+/*****************************************************************************
+ * FillBuffer: Read data from decoder fifo, and put it in S32_buffer
+ *****************************************************************************/
+static void FillBuffer( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
+{
+ int i_buffer = 0;
+ int i_buffer_limit, i_units;
+
+ switch ( p_fifo->i_format )
+ {
+ case AOUT_FIFO_PCM:
+
+ i_units = p_aout->i_units;
+
+ /* While there are empty frames in the buffer, fill them */
+ while ( i_units > 0 )
+ {
+ /* If there is no next frame, wait for one */
+ if( !p_fifo->b_next_frame )
+ {
+ if( NextFrame(p_aout, p_fifo, p_aout->date +
+ ((((mtime_t)(i_buffer >> 1)) * 1000000) /
+ ((mtime_t)p_aout->i_rate))) )
+ {
+ break;
+ }
+ }
+
+ i_buffer_limit = p_aout->i_units * p_aout->i_channels;
+
+ while ( i_buffer < i_buffer_limit )
+ {
+ /* FIXME: make this more generic */
+ if( p_aout->i_channels == 2 )
+ {
+ p_aout->s32_buffer[i_buffer++] +=
+ (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->i_unit] );
+ p_aout->s32_buffer[i_buffer++] +=
+ (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->i_unit+1] );
+ }
+ else if( p_aout->i_channels == 1 )
+ {
+ p_aout->s32_buffer[i_buffer++] +=
+ (s32)( ((s16 *)p_fifo->buffer)[p_fifo->i_unit] );
+ }
+ else
+ {
+ intf_ErrMsg( "aout error: unsupported number of channels" );
+ }
+
+ UpdateIncrement(&p_fifo->unit_increment, &p_fifo->i_unit);
+
+ if( p_fifo->i_unit >= p_fifo->i_unit_limit )
+ {
+ p_fifo->i_unit -= p_fifo->i_unit_limit;
+ }
+ }
+
+ if( p_fifo->i_units > i_units )
+ {
+ p_fifo->i_units -= i_units;
+ break;
+ }
+ else
+ {
+ i_units -= p_fifo->i_units;
+
+ vlc_mutex_lock( &p_fifo->data_lock );
+ p_fifo->i_start_frame = p_fifo->i_next_frame;
+ /* p_fifo->b_start_frame = 1; */
+ p_fifo->i_next_frame = AOUT_FIFO_INC( p_fifo->i_next_frame );
+ p_fifo->b_next_frame = 0;
+ vlc_cond_signal( &p_fifo->data_wait );
+ vlc_mutex_unlock( &p_fifo->data_lock );
+
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+static int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
+ mtime_t aout_date )
+{
+ int i_units, i_units_dist, i_rate;
+ u64 i_delta;
+
+ /* We take the lock */
+ vlc_mutex_lock( &p_fifo->data_lock );
+
+ /* Are we looking for a dated start frame ? */
+ if ( !p_fifo->b_start_frame )
+ {
+ while ( p_fifo->i_start_frame != p_fifo->i_end_frame )
+ {
+ if ( p_fifo->date[p_fifo->i_start_frame] != LAST_MDATE )
+ {
+ p_fifo->b_start_frame = 1;
+ p_fifo->i_next_frame = AOUT_FIFO_INC( p_fifo->i_start_frame );
+ p_fifo->i_unit = p_fifo->i_start_frame *
+ (p_fifo->i_frame_size / p_fifo->i_channels);
+ break;
+ }
+ p_fifo->i_start_frame = AOUT_FIFO_INC( p_fifo->i_start_frame );
+ }
+
+ if ( p_fifo->i_start_frame == p_fifo->i_end_frame )
+ {
+ vlc_mutex_unlock( &p_fifo->data_lock );
+ return( -1 );
+ }
+ }
+
+ /* We are looking for the next dated frame */
+ /* FIXME : is the output fifo full ?? -- pretty unlikely given its size */
+ while ( !p_fifo->b_next_frame )
+ {
+ while ( p_fifo->i_next_frame != p_fifo->i_end_frame )
+ {
+ if ( p_fifo->date[p_fifo->i_next_frame] != LAST_MDATE )
+ {
+ p_fifo->b_next_frame = 1;
+ break;
+ }
+ p_fifo->i_next_frame = AOUT_FIFO_INC( p_fifo->i_next_frame );
+ }
+
+ while ( p_fifo->i_next_frame == p_fifo->i_end_frame )
+ {
+ vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
+ if ( p_fifo->b_die )
+ {
+ vlc_mutex_unlock( &p_fifo->data_lock );
+ return( -1 );
+ }
+ }
+ }
+
+ i_units = ((p_fifo->i_next_frame - p_fifo->i_start_frame) & AOUT_FIFO_SIZE)
+ * (p_fifo->i_frame_size / p_fifo->i_channels);
+
+ i_delta = aout_date - p_fifo->date[p_fifo->i_start_frame];
+
+ /* Resample if delta is too long */
+ if( abs(i_delta) > MAX_DELTA )
+ {
+ i_rate = p_fifo->i_rate + (i_delta / 256);
+ }
+ else
+ {
+ i_rate = p_fifo->i_rate;
+ }
+
+ InitializeIncrement( &p_fifo->unit_increment, i_rate, p_aout->i_rate );
+
+ /* Calculate how many units we're going to write */
+ i_units_dist = p_fifo->i_unit - p_fifo->i_start_frame
+ * (p_fifo->i_frame_size / p_fifo->i_channels);
+
+ /* Manage the fifo wrapping */
+ if( i_units_dist > p_fifo->i_unit_limit / 2 )
+ {
+ i_units -= (i_units_dist - p_fifo->i_unit_limit);
+ }
+ else if( i_units_dist < - p_fifo->i_unit_limit / 2 )
+ {
+ i_units -= (i_units_dist + p_fifo->i_unit_limit);
+ }
+ else
+ {
+ i_units -= i_units_dist;
+ }
+
+ p_fifo->i_units = 1 + ( i_units * p_aout->i_rate / i_rate );
+
+ /* We release the lock before leaving */
+ vlc_mutex_unlock( &p_fifo->data_lock );
+ return( 0 );
+}
+
--- /dev/null
+/*****************************************************************************
+ * aout_pcm.h: PCM audio output functions
+ *****************************************************************************
+ * Copyright (C) 1999-2002 VideoLAN
+ * $Id: aout_pcm.h,v 1.1 2002/02/24 22:06:50 sam Exp $
+ *
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ * Cyril Deguet <asmax@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+void aout_PCMThread( aout_thread_t * p_aout );
+
/*****************************************************************************
- * aout_spdif: ac3 passthrough output
+ * aout_spdif.c: AC3 passthrough output
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: aout_spdif.c,v 1.22 2002/02/19 00:50:19 sam Exp $
+ * $Id: aout_spdif.c,v 1.23 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Stéphane Borel <stef@via.ecp.fr>
#include <videolan/vlc.h>
#include "audio_output.h"
-#include "aout_common.h"
+#include "aout_spdif.h"
/*****************************************************************************
* aout_SpdifThread: audio output thread that sends raw spdif data
*****************************************************************************/
void aout_SpdifThread( aout_thread_t * p_aout )
{
- int i_fifo;
- mtime_t m_frame_time = 0;
- mtime_t m_play;
- mtime_t m_old = 0;
+ int i_fifo;
+ mtime_t m_frame_time = 0;
+ mtime_t m_play;
+ mtime_t m_old = 0;
-
- while( !p_aout->b_die )
- {
- for( i_fifo = 0 ; i_fifo < AOUT_MAX_FIFOS ; i_fifo++ )
+ while( !p_aout->b_die )
{
- /* the loop read each fifo so that we can change the stream
- * on the fly but mulitplexing is not handled yet so
- * the sound will be broken is more than one fifo has data */
- /* TODO: write the muliplexer :) */
- if( p_aout->fifo[i_fifo].i_type == AOUT_ADEC_SPDIF_FIFO )
- {
- vlc_mutex_lock( &p_aout->fifo[i_fifo].data_lock );
- if( p_aout->fifo[i_fifo].b_die )
+ for( i_fifo = 0 ; i_fifo < AOUT_MAX_FIFOS ; i_fifo++ )
{
- vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
-
- vlc_mutex_lock( &p_aout->fifos_lock );
- aout_FreeFifo( &p_aout->fifo[i_fifo] );
- vlc_mutex_unlock( &p_aout->fifos_lock );
- }
- else if( !AOUT_FIFO_ISEMPTY( p_aout->fifo[i_fifo] ) )
- {
- /* Copy data from fifo to buffer to release the lock earlier */
- memcpy( p_aout->buffer,
- (byte_t *)p_aout->fifo[i_fifo].buffer
- + p_aout->fifo[i_fifo].l_start_frame
- * SPDIF_FRAME_SIZE,
- SPDIF_FRAME_SIZE );
-
- m_play = p_aout->fifo[i_fifo].date[p_aout->fifo[i_fifo].
- l_start_frame];
-
- p_aout->fifo[i_fifo].l_start_frame =
- (p_aout->fifo[i_fifo].l_start_frame + 1 )
- & AOUT_FIFO_SIZE;
-
- /* Compute the theorical duration of an ac3 frame */
- m_frame_time = 1000000 * AC3_FRAME_SIZE
- / p_aout->fifo[i_fifo].l_rate;
-
- vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
-
- /* play spdif frame to the external decoder
- * the kernel driver will sleep until the
- * dsp buffer is empty enough to accept the data */
- if( m_play > ( mdate() - m_frame_time ) )
- {
- /* check continuity */
- if( (m_play - m_old) != m_frame_time )
+ /* the loop read each fifo so that we can change the stream
+ * on the fly but mulitplexing is not handled yet so
+ * the sound will be broken is more than one fifo has data */
+ /* TODO: write the muliplexer :) */
+ if( p_aout->fifo[i_fifo].i_format == AOUT_FIFO_SPDIF )
{
- mwait( m_play - m_frame_time );
+ vlc_mutex_lock( &p_aout->fifo[i_fifo].data_lock );
+ if( p_aout->fifo[i_fifo].b_die )
+ {
+ vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
+
+ vlc_mutex_lock( &p_aout->fifos_lock );
+ aout_FreeFifo( &p_aout->fifo[i_fifo] );
+ vlc_mutex_unlock( &p_aout->fifos_lock );
+ }
+ else if( !AOUT_FIFO_ISEMPTY( p_aout->fifo[i_fifo] ) )
+ {
+ /* Copy data from fifo to buffer to release the
+ * lock earlier */
+ FAST_MEMCPY( p_aout->buffer,
+ (byte_t *)p_aout->fifo[i_fifo].buffer
+ + p_aout->fifo[i_fifo].i_start_frame
+ * SPDIF_FRAME_SIZE,
+ SPDIF_FRAME_SIZE );
+
+ m_play = p_aout->fifo[i_fifo].date[p_aout->fifo[i_fifo].
+ i_start_frame];
+
+ p_aout->fifo[i_fifo].i_start_frame =
+ (p_aout->fifo[i_fifo].i_start_frame + 1 )
+ & AOUT_FIFO_SIZE;
+
+ /* Compute the theorical duration of an ac3 frame */
+ m_frame_time = 1000000 * AC3_FRAME_SIZE
+ / p_aout->fifo[i_fifo].i_rate;
+
+ vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
+
+ /* play spdif frame to the external decoder
+ * the kernel driver will sleep until the
+ * dsp buffer is empty enough to accept the data */
+ if( m_play > ( mdate() - m_frame_time ) )
+ {
+ /* check continuity */
+ if( (m_play - m_old) != m_frame_time )
+ {
+ mwait( m_play - m_frame_time );
+ }
+ else
+ {
+ mwait( m_play - 2 * m_frame_time );
+ }
+ m_old = m_play;
+
+ p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
+ SPDIF_FRAME_SIZE );
+ }
+ }
+ else
+ {
+ vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
+ msleep( m_frame_time );
+ intf_WarnMsg( 3, "aout warning: empty spdif fifo" );
+ }
}
- else
- {
- mwait( m_play - 2 * m_frame_time );
- }
- m_old = m_play;
-
- p_aout->pf_play( p_aout,
- (byte_t *)p_aout->buffer,
- SPDIF_FRAME_SIZE );
- }
- }
- else
- {
- vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
- msleep( m_frame_time );
- intf_WarnMsg( 3, "aout warning: empty spdif fifo" );
}
- }
}
- }
- vlc_mutex_lock( &p_aout->fifos_lock );
-
- for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
- {
- aout_FreeFifo( &p_aout->fifo[i_fifo] );
- }
-
- vlc_mutex_unlock( &p_aout->fifos_lock );
+ vlc_mutex_lock( &p_aout->fifos_lock );
+ for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+ {
+ aout_FreeFifo( &p_aout->fifo[i_fifo] );
+ }
+ vlc_mutex_unlock( &p_aout->fifos_lock );
- return;
+ return;
}
* audio_output.c : audio output thread
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: audio_output.c,v 1.77 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: audio_output.c,v 1.78 2002/02/24 22:06:50 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Cyril Deguet <asmax@via.ecp.fr>
#endif
#include "audio_output.h"
-#include "aout_common.h"
+
+#include "aout_pcm.h"
+#include "aout_spdif.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int aout_SpawnThread( aout_thread_t * p_aout );
+static int aout_SpawnThread ( aout_thread_t * p_aout );
/*****************************************************************************
* aout_InitBank: initialize the audio output bank.
/*****************************************************************************
* aout_CreateThread: initialize audio thread
*****************************************************************************/
-aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, long l_rate )
+aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, int i_rate )
{
aout_thread_t * p_aout; /* thread descriptor */
#if 0
}
p_aout->i_latency = 0;
- p_aout->l_rate = config_GetIntVariable( AOUT_RATE_VAR );
+ p_aout->i_rate = config_GetIntVariable( AOUT_RATE_VAR );
p_aout->i_channels = config_GetIntVariable( AOUT_MONO_VAR ) ? 1 : 2;
- intf_WarnMsg( 3, "aout info: thread created, channels %d, rate %d",
- p_aout->i_channels, p_aout->l_rate );
-
/* Maybe we should pass this setting in argument */
p_aout->i_format = AOUT_FORMAT_DEFAULT;
p_aout->i_format = AOUT_FMT_AC3;
}
- if( p_aout->l_rate == 0 )
+ if( p_aout->i_rate == 0 )
{
intf_ErrMsg( "aout error: null sample rate" );
free( p_aout );
return( NULL );
}
- /* FIXME: only works for i_channels == 1 or 2 ?? */
- p_aout->b_stereo = ( p_aout->i_channels == 2 ) ? 1 : 0;
-
/* Choose the best module */
p_aout->p_module = module_Need( MODULE_CAPABILITY_AOUT,
config_GetPszVariable( AOUT_METHOD_VAR ),
return( p_aout );
}
-
-/*****************************************************************************
- * Declare the different aout thread functions
- *****************************************************************************/
-DECLARE_AOUT_THREAD( S16, s16, ( p_aout->s32_buffer[l_buffer] /
- AOUT_MAX_FIFOS ) )
-
-DECLARE_AOUT_THREAD( U16, u16, (( p_aout->s32_buffer[l_buffer] /
- AOUT_MAX_FIFOS) + 128) )
-
-DECLARE_AOUT_THREAD( U8, u8, (( p_aout->s32_buffer[l_buffer] /
- AOUT_MAX_FIFOS / 256) + 128 ) )
-
-DECLARE_AOUT_THREAD( S8, s8, ( p_aout->s32_buffer[l_buffer] /
- AOUT_MAX_FIFOS / 256) )
-
-
/*****************************************************************************
* aout_SpawnThread
*****************************************************************************/
static int aout_SpawnThread( aout_thread_t * p_aout )
{
- int i_fifo;
- long l_bytes;
+ int i_index, i_bytes;
void (* pf_aout_thread)( aout_thread_t * ) = NULL;
+ char *psz_format;
/* We want the audio output thread to live */
p_aout->b_die = 0;
/* Initialize the fifos lock */
vlc_mutex_init( &p_aout->fifos_lock );
+
/* Initialize audio fifos : set all fifos as empty and initialize locks */
- for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+ for ( i_index = 0; i_index < AOUT_MAX_FIFOS; i_index++ )
{
- p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
- vlc_mutex_init( &p_aout->fifo[i_fifo].data_lock );
- vlc_cond_init( &p_aout->fifo[i_fifo].data_wait );
+ p_aout->fifo[i_index].i_format = AOUT_FIFO_NONE;
+ vlc_mutex_init( &p_aout->fifo[i_index].data_lock );
+ vlc_cond_init( &p_aout->fifo[i_index].data_wait );
}
/* Compute the size (in audio units) of the audio output buffer. Although
* AOUT_BUFFER_DURATION is given in microseconds, the output rate is given
* in Hz, that's why we need to divide by 10^6 microseconds (1 second) */
- p_aout->l_units = (long)( ((s64)p_aout->l_rate * AOUT_BUFFER_DURATION) / 1000000 );
- p_aout->l_msleep = (long)( ((s64)p_aout->l_units * 1000000) / (s64)p_aout->l_rate );
+ p_aout->i_units = ((s64)p_aout->i_rate * AOUT_BUFFER_DURATION) / 1000000;
+ p_aout->i_msleep = AOUT_BUFFER_DURATION / 4;
/* Make pf_aout_thread point to the right thread function, and compute the
* byte size of the audio output buffer */
- switch ( p_aout->i_channels )
+ switch ( p_aout->i_format )
{
- /* Audio output is mono */
- case 1:
- switch ( p_aout->i_format )
- {
- case AOUT_FMT_U8:
- intf_WarnMsg( 2, "aout info: unsigned 8 bits mono thread" );
- l_bytes = 1 * sizeof(u8) * p_aout->l_units;
- pf_aout_thread = aout_U8Thread;
- break;
-
- case AOUT_FMT_S8:
- intf_WarnMsg( 2, "aout info: signed 8 bits mono thread" );
- l_bytes = 1 * sizeof(s8) * p_aout->l_units;
- pf_aout_thread = aout_S8Thread;
- break;
-
- case AOUT_FMT_U16_LE:
- case AOUT_FMT_U16_BE:
- intf_WarnMsg( 2, "aout info: unsigned 16 bits mono thread" );
- l_bytes = 1 * sizeof(u16) * p_aout->l_units;
- pf_aout_thread = aout_U16Thread;
- break;
-
- case AOUT_FMT_S16_LE:
- case AOUT_FMT_S16_BE:
- intf_WarnMsg( 2, "aout info: signed 16 bits mono thread" );
- l_bytes = 1 * sizeof(s16) * p_aout->l_units;
- pf_aout_thread = aout_S16Thread;
- break;
-
- default:
- intf_ErrMsg( "aout error: unknown audio output format (%i)",
- p_aout->i_format );
- return( -1 );
- }
- break;
-
- /* Audio output is stereo */
- case 2:
- switch ( p_aout->i_format )
- {
case AOUT_FMT_U8:
- intf_WarnMsg( 2, "aout info: unsigned 8 bits stereo thread" );
- l_bytes = 2 * sizeof(u8) * p_aout->l_units;
- pf_aout_thread = aout_U8Thread;
+ pf_aout_thread = aout_PCMThread;
+ psz_format = "unsigned 8 bits";
+ i_bytes = p_aout->i_units * p_aout->i_channels;
break;
case AOUT_FMT_S8:
- intf_WarnMsg( 2, "aout info: signed 8 bits stereo thread" );
- l_bytes = 2 * sizeof(s8) * p_aout->l_units;
- pf_aout_thread = aout_S8Thread;
+ pf_aout_thread = aout_PCMThread;
+ psz_format = "signed 8 bits";
+ i_bytes = p_aout->i_units * p_aout->i_channels;
break;
case AOUT_FMT_U16_LE:
case AOUT_FMT_U16_BE:
- intf_WarnMsg( 2, "aout info: unsigned 16 bits stereo thread" );
- l_bytes = 2 * sizeof(u16) * p_aout->l_units;
- pf_aout_thread = aout_U16Thread;
+ pf_aout_thread = aout_PCMThread;
+ psz_format = "unsigned 16 bits";
+ i_bytes = 2 * p_aout->i_units * p_aout->i_channels;
break;
case AOUT_FMT_S16_LE:
case AOUT_FMT_S16_BE:
- intf_WarnMsg( 2, "aout info: signed 16 bits stereo thread" );
- l_bytes = 2 * sizeof(s16) * p_aout->l_units;
- pf_aout_thread = aout_S16Thread;
+ pf_aout_thread = aout_PCMThread;
+ psz_format = "signed 16 bits";
+ i_bytes = 2 * p_aout->i_units * p_aout->i_channels;
break;
case AOUT_FMT_AC3:
- intf_WarnMsg( 2, "aout info: ac3 pass-through thread" );
- l_bytes = SPDIF_FRAME_SIZE;
pf_aout_thread = aout_SpdifThread;
+ psz_format = "ac3 pass-through";
+ i_bytes = SPDIF_FRAME_SIZE;
break;
default:
intf_ErrMsg( "aout error: unknown audio output format %i",
p_aout->i_format );
return( -1 );
- }
- break;
-
- default:
- intf_ErrMsg( "aout error: unknown number of audio channels (%i)",
- p_aout->i_channels );
- return( -1 );
}
/* Allocate the memory needed by the audio output buffers, and set to zero
* the s32 buffer's memory */
- p_aout->buffer = malloc( l_bytes );
+ p_aout->buffer = malloc( i_bytes );
if ( p_aout->buffer == NULL )
{
intf_ErrMsg( "aout error: cannot create output buffer" );
return( -1 );
}
- p_aout->s32_buffer = (s32 *)calloc( p_aout->l_units,
- sizeof(s32) << ( p_aout->b_stereo ) );
+ p_aout->s32_buffer = (s32 *)calloc( p_aout->i_units,
+ sizeof(s32) * p_aout->i_channels );
if ( p_aout->s32_buffer == NULL )
{
intf_ErrMsg( "aout error: cannot create the s32 output buffer" );
return( -1 );
}
- intf_WarnMsg( 2, "aout info: audio output thread %i spawned", getpid() );
+ intf_WarnMsg( 2, "aout info: %s thread spawned, %i channels, rate %i",
+ psz_format, p_aout->i_channels, p_aout->i_rate );
return( 0 );
}
*****************************************************************************/
void aout_DestroyThread( aout_thread_t * p_aout, int *pi_status )
{
- int i_fifo;
+ int i_index;
/* FIXME: pi_status is not handled correctly: check vout how to do!?? */
free( p_aout->s32_buffer );
/* Destroy the condition and mutex locks */
- for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+ for ( i_index = 0; i_index < AOUT_MAX_FIFOS; i_index++ )
{
- vlc_mutex_destroy( &p_aout->fifo[i_fifo].data_lock );
- vlc_cond_destroy( &p_aout->fifo[i_fifo].data_wait );
+ vlc_mutex_destroy( &p_aout->fifo[i_index].data_lock );
+ vlc_cond_destroy( &p_aout->fifo[i_index].data_wait );
}
vlc_mutex_destroy( &p_aout->fifos_lock );