]> git.sesse.net Git - vlc/blob - modules/arm_neon/volume.c
flac: don't overwrite bitspersample
[vlc] / modules / arm_neon / volume.c
1 /*****************************************************************************
2  * volume.c : ARM NEON audio volume
3  *****************************************************************************
4  * Copyright (C) 2012 RĂ©mi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <assert.h>
26
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_cpu.h>
30 #include <vlc_aout.h>
31 #include <vlc_aout_volume.h>
32
33 static int Probe(vlc_object_t *);
34
35 vlc_module_begin()
36     set_category(CAT_AUDIO)
37     set_subcategory(SUBCAT_AUDIO_MISC)
38     set_description(N_("ARM NEON audio volume"))
39     set_capability("audio volume", 10)
40     set_callbacks(Probe, NULL)
41 vlc_module_end()
42
43 static void AmplifyFloat(audio_volume_t *, block_t *, float);
44
45 static int Probe(vlc_object_t *obj)
46 {
47     audio_volume_t *volume = (audio_volume_t *)obj;
48
49     if (!vlc_CPU_ARM_NEON())
50         return VLC_EGENERIC;
51     if (volume->format == VLC_CODEC_FL32)
52         volume->amplify = AmplifyFloat;
53     else
54         return VLC_EGENERIC;
55     return VLC_SUCCESS;
56 }
57
58 void amplify_float_arm_neon(float *, const float *, size_t, float);
59
60 static void AmplifyFloat(audio_volume_t *volume, block_t *block, float amp)
61 {
62     float *buf = (float *)block->p_buffer;
63     size_t length = block->i_buffer;
64
65     if (amp == 1.0)
66         return;
67
68     /* Unaligned header */
69     assert(((uintptr_t)buf & 3) == 0);
70     while (unlikely((uintptr_t)buf & 12))
71     {
72         *(buf++) *= amp;
73         length -= 4;
74     }
75     /* Unaligned footer */
76     assert((length & 3) == 0);
77     while (unlikely(length & 12))
78     {
79         length -= 4;
80         buf[length / 4] *= amp;
81     }
82
83     amplify_float_arm_neon(buf, buf, length, amp);
84     (void) volume;
85 }