1 /*****************************************************************************
2 * mixer.c : audio output mixing operations
3 *****************************************************************************
4 * Copyright (C) 2002-2004 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include <vlc_common.h>
36 #include <vlc_modules.h>
38 #include <vlc_aout_mixer.h>
39 #include "aout_internal.h"
43 * Creates a software amplifier.
45 audio_mixer_t *aout_MixerNew(vlc_object_t *obj, vlc_fourcc_t format)
47 audio_mixer_t *mixer = vlc_custom_create(obj, sizeof (*mixer), "mixer");
48 if (unlikely(mixer == NULL))
51 mixer->format = format;
53 mixer->module = module_need(mixer, "audio mixer", NULL, false);
54 if (mixer->module == NULL)
56 vlc_object_release(mixer);
63 * Destroys a software amplifier.
65 void aout_MixerDelete(audio_mixer_t *mixer)
70 module_unneed(mixer, mixer->module);
71 vlc_object_release(mixer);
75 * Applies replay gain and software volume to an audio buffer.
77 void aout_MixerRun(audio_mixer_t *mixer, block_t *block, float amp)
79 mixer->mix(mixer, block, amp);
83 float (aout_ReplayGainSelect)(vlc_object_t *obj, const char *str,
84 const audio_replay_gain_t *replay_gain)
87 unsigned mode = AUDIO_REPLAY_GAIN_MAX;
89 if (likely(str != NULL))
90 { /* Find selectrf mode */
91 if (!strcmp (str, "track"))
92 mode = AUDIO_REPLAY_GAIN_TRACK;
94 if (!strcmp (str, "album"))
95 mode = AUDIO_REPLAY_GAIN_ALBUM;
97 /* If the selectrf mode is not available, prefer the other one */
98 if (mode != AUDIO_REPLAY_GAIN_MAX && !replay_gain->pb_gain[mode])
100 if (replay_gain->pb_gain[!mode])
106 if (mode == AUDIO_REPLAY_GAIN_MAX)
109 if (replay_gain->pb_gain[mode])
110 gain = replay_gain->pf_gain[mode]
111 + var_InheritFloat (obj, "audio-replay-gain-preamp");
113 gain = var_InheritFloat (obj, "audio-replay-gain-default");
115 float multiplier = pow (10., gain / 20.);
117 if (replay_gain->pb_peak[mode]
118 && var_InheritBool (obj, "audio-replay-gain-peak-protection")
119 && replay_gain->pf_peak[mode] * multiplier > 1.0)
120 multiplier = 1.0f / replay_gain->pf_peak[mode];