/* Array of mixer inputs */
aout_mixer_input_t *input;
- /* Mix requested number of samples (mandatory) */
- aout_buffer_t *(*mix)(aout_mixer_t *, unsigned, float);
+ /* Mix buffer (mandatory) */
+ void (*mix)(aout_mixer_t *, aout_buffer_t *, float);
/* Private place holder for the aout_mixer_t module (optional)
*
SOURCES_trivial_mixer = trivial.c
SOURCES_float32_mixer = float32.c
-SOURCES_spdif_mixer = spdif.c
libvlc_LTLIBRARIES += \
libfloat32_mixer_plugin.la \
- libspdif_mixer_plugin.la \
libtrivial_mixer_plugin.la
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int Create ( vlc_object_t * );
-static aout_buffer_t *DoWork( aout_mixer_t *, unsigned, float );
+static int Create( vlc_object_t * );
+static void DoWork( aout_mixer_t *, aout_buffer_t *, float );
/*****************************************************************************
* Module descriptor
set_callbacks( Create, NULL )
vlc_module_end ()
-/*****************************************************************************
- * Create: allocate mixer
- *****************************************************************************/
+/**
+ * Initializes the mixer
+ */
static int Create( vlc_object_t *p_this )
{
aout_mixer_t * p_mixer = (aout_mixer_t *)p_this;
return 0;
}
-/*****************************************************************************
- * ScaleWords: prepare input words for averaging
- *****************************************************************************/
-static void ScaleWords( float * p_out, const float * p_in, size_t i_nb_words,
- float f_multiplier )
-{
- if( f_multiplier == 1.0 )
- {
- vlc_memcpy( p_out, p_in, i_nb_words * sizeof(float) );
- return;
- }
-
- for( size_t i = 0; i < i_nb_words; i++ )
- *p_out++ = *p_in++ * f_multiplier;
-}
-
-/*****************************************************************************
- * DoWork: mix a new output buffer
- *****************************************************************************
- * Terminology : in this function a word designates a single float32, eg.
- * a stereo sample is consituted of two words.
- *****************************************************************************/
-static aout_buffer_t *DoWork( aout_mixer_t * p_mixer, unsigned samples,
- float f_multiplier )
+/**
+ * Mixes a new output buffer
+ */
+static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t *p_buffer,
+ float f_multiplier )
{
- aout_mixer_input_t * p_input = p_mixer->input;
- const int i_nb_channels = aout_FormatNbChannels( &p_mixer->fmt );
- int i_nb_words = samples * i_nb_channels;
-
- block_t *p_buffer = block_Alloc( i_nb_words * sizeof(float) );
- if( unlikely( p_buffer == NULL ) )
- return NULL;
- p_buffer->i_nb_samples = samples;
-
- float * p_out = (float *)p_buffer->p_buffer;
- float * p_in = (float *)p_input->begin;
+ f_multiplier *= p_mixer->input->multiplier;
- f_multiplier *= p_input->multiplier;
-
- for( ; ; )
- {
- ptrdiff_t i_available_words = (
- (float *)p_input->fifo.p_first->p_buffer - p_in)
- + p_input->fifo.p_first->i_nb_samples
- * i_nb_channels;
-
- if( i_available_words < i_nb_words )
- {
- aout_buffer_t * p_old_buffer;
-
- ScaleWords( p_out, p_in, i_available_words, f_multiplier );
- i_nb_words -= i_available_words;
- p_out += i_available_words;
+ if( f_multiplier == 1.0 )
+ return; /* nothing to do */
- /* Next buffer */
- p_old_buffer = aout_FifoPop( &p_input->fifo );
- aout_BufferFree( p_old_buffer );
- if( p_input->fifo.p_first == NULL )
- {
- msg_Err( p_mixer, "internal amix error" );
- break;
- }
- p_in = (float *)p_input->fifo.p_first->p_buffer;
- }
- else
- {
- ScaleWords( p_out, p_in, i_nb_words, f_multiplier );
- p_input->begin = (void *)(p_in + i_nb_words);
- break;
- }
- }
- return p_buffer;
+ float *p = (float *)p_buffer->p_buffer;
+ for( size_t i = p_buffer->i_buffer / sizeof(float); i > 0; i-- )
+ *(p++) *= f_multiplier;
}
+++ /dev/null
-/*****************************************************************************
- * spdif.c : dummy mixer for S/PDIF output (1 input only)
- *****************************************************************************
- * Copyright (C) 2002 the VideoLAN team
- * $Id$
- *
- * Authors: Christophe Massiot <massiot@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <assert.h>
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_aout.h>
-#include <vlc_aout_mixer.h>
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int Create ( vlc_object_t * );
-
-static aout_buffer_t *DoWork( aout_mixer_t *, unsigned, float );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-vlc_module_begin ()
- set_category( CAT_AUDIO )
- set_subcategory( SUBCAT_AUDIO_MISC )
- set_description( N_("Dummy S/PDIF audio mixer") )
- set_capability( "audio mixer", 1 )
- set_callbacks( Create, NULL )
-vlc_module_end ()
-
-/*****************************************************************************
- * Create: allocate spdif mixer
- *****************************************************************************/
-static int Create( vlc_object_t *p_this )
-{
- aout_mixer_t *p_mixer = (aout_mixer_t *)p_this;
-
- if ( !AOUT_FMT_NON_LINEAR(&p_mixer->fmt) )
- return -1;
-
- p_mixer->mix = DoWork;
- return 0;
-}
-
-/*****************************************************************************
- * DoWork: mix a new output buffer - this does nothing, indeed
- *****************************************************************************/
-static aout_buffer_t *DoWork( aout_mixer_t * p_mixer, unsigned samples,
- float multiplier )
-{
- aout_mixer_input_t * p_input = p_mixer->input;
- aout_buffer_t * p_old_buffer = aout_FifoPop( &p_input->fifo );
-
- (void) samples; (void) multiplier;
- return p_old_buffer;
-}
# include "config.h"
#endif
-#include <stddef.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int Create ( vlc_object_t * );
-
-static aout_buffer_t *DoWork( aout_mixer_t *, unsigned samples, float );
+static int Create( vlc_object_t * );
+static void DoNothing( aout_mixer_t *, aout_buffer_t *p_buffer, float );
/*****************************************************************************
* Module descriptor
vlc_module_begin ()
set_category( CAT_AUDIO )
set_subcategory( SUBCAT_AUDIO_MISC )
- set_description( N_("Trivial audio mixer") )
+ set_description( N_("Dummy audio mixer") )
set_capability( "audio mixer", 1 )
set_callbacks( Create, NULL )
vlc_module_end ()
{
aout_mixer_t *p_mixer = (aout_mixer_t *)p_this;
- if( AOUT_FMT_NON_LINEAR( &p_mixer->fmt ) )
- return -1;
-
- p_mixer->mix = DoWork;
+ p_mixer->mix = DoNothing;
return 0;
}
-/*****************************************************************************
- * DoWork: mix a new output buffer
- *****************************************************************************/
-static aout_buffer_t *DoWork( aout_mixer_t *p_mixer, unsigned samples,
- float multiplier )
+static void DoNothing( aout_mixer_t *p_mixer, aout_buffer_t *p_buffer,
+ float multiplier )
{
- aout_mixer_input_t *p_input = p_mixer->input;
- unsigned framesize = aout_FormatNbChannels( &p_mixer->fmt )
- * (p_mixer->fmt.i_bitspersample / 8);
- size_t needed = samples * framesize;
- aout_buffer_t *p_buffer = block_Alloc( needed );
-
- if( unlikely(p_buffer == NULL) )
- return NULL;
- p_buffer->i_nb_samples = samples;
-
- uint8_t * p_in = p_input->begin;
- uint8_t * p_out = p_buffer->p_buffer;
-
- for ( ; ; )
- {
- size_t avail = p_input->fifo.p_first->i_nb_samples * framesize
- - (p_in - p_input->fifo.p_first->p_buffer);
-
- if ( avail < needed )
- {
- vlc_memcpy( p_out, p_in, avail );
- needed -= avail;
- p_out += avail;
-
- /* Next buffer */
- aout_buffer_t *p_old_buffer = aout_FifoPop( &p_input->fifo );
- aout_BufferFree( p_old_buffer );
- if ( p_input->fifo.p_first == NULL )
- {
- msg_Err( p_mixer, "internal amix error" );
- break;
- }
- p_in = p_input->fifo.p_first->p_buffer;
- }
- else
- {
- vlc_memcpy( p_out, p_in, needed );
- p_input->begin = p_in + needed;
- break;
- }
- }
+ (void) p_mixer;
+ (void) p_buffer;
(void) multiplier;
- return p_buffer;
}
prev_date = p_buffer->i_pts + p_buffer->i_length;
}
- p_buffer = p_fifo->p_first;
if( !AOUT_FMT_NON_LINEAR( &p_mixer->fmt ) )
{
+ p_buffer = p_fifo->p_first;
+
/* Additionally check that p_first_byte_to_mix is well located. */
+ const unsigned framesize = p_mixer->fmt.i_bytes_per_frame;
mtime_t i_buffer = (start_date - p_buffer->i_pts)
- * p_mixer->fmt.i_bytes_per_frame
- * p_mixer->fmt.i_rate
- / p_mixer->fmt.i_frame_length
- / CLOCK_FREQ;
+ * framesize * p_mixer->fmt.i_rate / CLOCK_FREQ;
if( p_input->begin == NULL )
p_input->begin = p_buffer->p_buffer;
}
p_input->begin = p_buffer->p_buffer + i_buffer;
}
- }
- /* Run the mixer. */
- p_buffer = p_mixer->mix( p_mixer, p_aout->output.i_nb_samples, volume );
- aout_unlock_input_fifos( p_aout );
+ /* Build packet with adequate number of samples */
+ const unsigned samples = p_aout->output.i_nb_samples;
+ unsigned needed = samples * framesize;
+ p_buffer = block_Alloc( needed );
+ if( unlikely(p_buffer == NULL) )
+ /* XXX: should free input buffers */
+ goto giveup;
+ p_buffer->i_nb_samples = samples;
+
+ uint8_t *p_in = p_input->begin;
+ uint8_t *p_out = p_buffer->p_buffer;
+
+ for( ;; )
+ {
+ size_t avail = p_fifo->p_first->i_nb_samples * framesize
+ - (p_in - p_fifo->p_first->p_buffer);
+
+ if( avail < needed )
+ {
+ vlc_memcpy( p_out, p_in, avail );
+ needed -= avail;
+ p_out += avail;
- if( unlikely(p_buffer == NULL) )
- return -1;
+ /* Next buffer */
+ aout_BufferFree( aout_FifoPop( p_fifo ) );
+ if( p_input->fifo.p_first == NULL )
+ {
+ msg_Err( p_mixer, "internal amix error" );
+ vlc_memset( p_out, 0, needed );
+ break;
+ }
+ p_in = p_fifo->p_first->p_buffer;
+ }
+ else
+ {
+ vlc_memcpy( p_out, p_in, needed );
+ p_input->begin = p_in + needed;
+ break;
+ }
+ }
+ }
+ else
+ p_buffer = aout_FifoPop( p_fifo );
p_buffer->i_pts = start_date;
p_buffer->i_length = end_date - start_date;
+
+ /* Run the mixer. */
+ p_mixer->mix( p_mixer, p_buffer, volume );
+ aout_unlock_input_fifos( p_aout );
aout_OutputPlay( p_aout, p_buffer );
return 0;