]> git.sesse.net Git - vlc/blob - src/audio_output/mixer.c
b1a8b5d33b58fd0c8a037ce286cff279e00fe938
[vlc] / src / audio_output / mixer.c
1 /*****************************************************************************
2  * mixer.c : audio output mixing operations
3  *****************************************************************************
4  * Copyright (C) 2002-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stddef.h>
32 #include <vlc_common.h>
33 #include <libvlc.h>
34 #include <vlc_modules.h>
35 #include <vlc_aout.h>
36 #include <vlc_aout_mixer.h>
37 #include "aout_internal.h"
38
39 #undef aout_MixerNew
40 /**
41  * Creates a software amplifier.
42  */
43 audio_mixer_t *aout_MixerNew(vlc_object_t *obj, vlc_fourcc_t format)
44 {
45     audio_mixer_t *mixer = vlc_custom_create(obj, sizeof (*mixer), "mixer");
46     if (unlikely(mixer == NULL))
47         return NULL;
48
49     mixer->format = format;
50     mixer->mix = NULL;
51     mixer->module = module_need(mixer, "audio mixer", NULL, false);
52     if (mixer->module == NULL)
53     {
54         msg_Err(mixer, "no suitable audio mixer");
55         vlc_object_release(mixer);
56         mixer = NULL;
57     }
58     return mixer;
59 }
60
61 /**
62  * Destroys a software amplifier.
63  */
64 void aout_MixerDelete(audio_mixer_t *mixer)
65 {
66     if (mixer == NULL)
67         return;
68
69     module_unneed(mixer, mixer->module);
70     vlc_object_release(mixer);
71 }
72
73 /**
74  * Applies replay gain and software volume to an audio buffer.
75  */
76 void aout_MixerRun(audio_mixer_t *mixer, block_t *block, float amp)
77 {
78     mixer->mix(mixer, block, amp);
79 }