File: float.c

package info (click to toggle)
vlc 3.0.21-10
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 212,728 kB
  • sloc: ansic: 441,379; cpp: 110,628; objc: 36,394; sh: 6,947; makefile: 6,592; javascript: 4,902; xml: 1,611; asm: 1,355; yacc: 640; python: 555; lex: 88; perl: 77; sed: 16
file content (103 lines) | stat: -rw-r--r-- 3,304 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*****************************************************************************
 * float32.c : precise float32 audio volume implementation
 *****************************************************************************
 * Copyright (C) 2002 VLC authors and VideoLAN
 * $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 Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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 <stddef.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
#include <vlc_aout_volume.h>

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int Create( vlc_object_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin ()
    set_category( CAT_AUDIO )
    set_subcategory( SUBCAT_AUDIO_MISC )
    set_description( N_("Single precision audio volume") )
    set_capability( "audio volume", 10 )
    set_callbacks( Create, NULL )
vlc_module_end ()

/**
 * Mixes a new output buffer
 */
static void FilterFL32( audio_volume_t *p_volume, block_t *p_buffer,
                        float f_multiplier )
{
    if( f_multiplier == 1.f )
        return; /* nothing to do */

    float *p = (float *)p_buffer->p_buffer;
    for( size_t i = p_buffer->i_buffer / sizeof(*p); i > 0; i-- )
        *(p++) *= f_multiplier;

    (void) p_volume;
}

static void FilterFL64( audio_volume_t *p_volume, block_t *p_buffer,
                        float f_multiplier )
{
    double *p = (double *)p_buffer->p_buffer;
    double mult = f_multiplier;
    if( mult == 1. )
        return; /* nothing to do */

    for( size_t i = p_buffer->i_buffer / sizeof(*p); i > 0; i-- )
        *(p++) *= mult;

    (void) p_volume;
}

/**
 * Initializes the mixer
 */
static int Create( vlc_object_t *p_this )
{
    audio_volume_t *p_volume = (audio_volume_t *)p_this;

    switch (p_volume->format)
    {
        case VLC_CODEC_FL32:
            p_volume->amplify = FilterFL32;
            break;
        case VLC_CODEC_FL64:
            p_volume->amplify = FilterFL64;
            break;
        default:
            return -1;
    }
    return 0;
}