FFmpeg  4.0
sbcdsp_init_arm.c
Go to the documentation of this file.
1 /*
2  * Bluetooth low-complexity, subband codec (SBC)
3  *
4  * Copyright (C) 2017 Aurelien Jacobs <aurel@gnuage.org>
5  * Copyright (C) 2008-2010 Nokia Corporation
6  * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
7  * Copyright (C) 2004-2005 Henryk Ploetz <henryk@ploetzli.ch>
8  * Copyright (C) 2005-2006 Brad Midgley <bmidgley@xmission.com>
9  *
10  * This file is part of FFmpeg.
11  *
12  * FFmpeg is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * FFmpeg is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with FFmpeg; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 /**
28  * @file
29  * SBC ARMv6 optimization for some basic "building bricks"
30  */
31 
32 #include "libavutil/cpu.h"
33 #include "libavutil/arm/cpu.h"
34 #include "libavcodec/sbcdsp.h"
35 
36 void ff_sbc_analyze_4_armv6(const int16_t *in, int32_t *out, const int16_t *consts);
37 void ff_sbc_analyze_8_armv6(const int16_t *in, int32_t *out, const int16_t *consts);
38 
39 void ff_sbc_analyze_4_neon(const int16_t *in, int32_t *out, const int16_t *consts);
40 void ff_sbc_analyze_8_neon(const int16_t *in, int32_t *out, const int16_t *consts);
41 void ff_sbc_calc_scalefactors_neon(int32_t sb_sample_f[16][2][8],
42  uint32_t scale_factor[2][8],
43  int blocks, int channels, int subbands);
44 int ff_sbc_calc_scalefactors_j_neon(int32_t sb_sample_f[16][2][8],
45  uint32_t scale_factor[2][8],
46  int blocks, int subbands);
47 int ff_sbc_enc_process_input_4s_neon(int position, const uint8_t *pcm,
48  int16_t X[2][SBC_X_BUFFER_SIZE],
49  int nsamples, int nchannels);
50 int ff_sbc_enc_process_input_8s_neon(int position, const uint8_t *pcm,
51  int16_t X[2][SBC_X_BUFFER_SIZE],
52  int nsamples, int nchannels);
53 
55  8, 4, 2, 1, 128, 64, 32, 16
56 };
57 
58 #if HAVE_BIGENDIAN
59 #define PERM(a, b, c, d) { \
60  (a * 2) + 1, (a * 2) + 0, \
61  (b * 2) + 1, (b * 2) + 0, \
62  (c * 2) + 1, (c * 2) + 0, \
63  (d * 2) + 1, (d * 2) + 0 \
64  }
65 #else
66 #define PERM(a, b, c, d) { \
67  (a * 2) + 0, (a * 2) + 1, \
68  (b * 2) + 0, (b * 2) + 1, \
69  (c * 2) + 0, (c * 2) + 1, \
70  (d * 2) + 0, (d * 2) + 1 \
71  }
72 #endif
73 
75  PERM(7, 3, 6, 4),
76  PERM(0, 2, 1, 5)
77 };
78 
80  PERM(15, 7, 14, 8),
81  PERM(13, 9, 12, 10),
82  PERM(11, 3, 6, 0),
83  PERM( 5, 1, 4, 2)
84 };
85 
86 av_cold void ff_sbcdsp_init_arm(SBCDSPContext *s)
87 {
89 
90  if (have_armv6(cpu_flags)) {
91  s->sbc_analyze_4 = ff_sbc_analyze_4_armv6;
92  s->sbc_analyze_8 = ff_sbc_analyze_8_armv6;
93  }
94 
95  if (have_neon(cpu_flags)) {
96  s->sbc_analyze_4 = ff_sbc_analyze_4_neon;
97  s->sbc_analyze_8 = ff_sbc_analyze_8_neon;
98  s->sbc_calc_scalefactors = ff_sbc_calc_scalefactors_neon;
99  s->sbc_calc_scalefactors_j = ff_sbc_calc_scalefactors_j_neon;
100  if (s->increment != 1) {
101  s->sbc_enc_process_input_4s = ff_sbc_enc_process_input_4s_neon;
102  s->sbc_enc_process_input_8s = ff_sbc_enc_process_input_8s_neon;
103  }
104  }
105 }
void ff_sbc_analyze_4_neon(const int16_t *in, int32_t *out, const int16_t *consts)
const char * s
Definition: avisynth_c.h:768
#define SBC_X_BUFFER_SIZE
Definition: sbcdsp.h:39
#define have_armv6(flags)
Definition: cpu.h:26
channels
Definition: aptx.c:30
int ff_sbc_calc_scalefactors_j_neon(int32_t sb_sample_f[16][2][8], uint32_t scale_factor[2][8], int blocks, int subbands)
void ff_sbc_analyze_8_neon(const int16_t *in, int32_t *out, const int16_t *consts)
static atomic_int cpu_flags
Definition: cpu.c:50
SBC basic "building bricks".
uint8_t
#define av_cold
Definition: attributes.h:82
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
int32_t ff_sbcdsp_joint_bits_mask[8]
#define PERM(a, b, c, d)
av_cold void ff_sbcdsp_init_arm(SBCDSPContext *s)
#define have_neon(flags)
Definition: cpu.h:26
int32_t
void ff_sbc_analyze_4_armv6(const int16_t *in, int32_t *out, const int16_t *consts)
int ff_sbc_enc_process_input_8s_neon(int position, const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE], int nsamples, int nchannels)
void ff_sbc_calc_scalefactors_neon(int32_t sb_sample_f[16][2][8], uint32_t scale_factor[2][8], int blocks, int channels, int subbands)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define SBC_ALIGN
Definition: sbc.h:78
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:93
uint8_t ff_sbc_input_perm_4[2][8]
void ff_sbc_analyze_8_armv6(const int16_t *in, int32_t *out, const int16_t *consts)
FILE * out
Definition: movenc.c:54
subbands
Definition: aptx.c:36
uint8_t ff_sbc_input_perm_8[4][8]
int ff_sbc_enc_process_input_4s_neon(int position, const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE], int nsamples, int nchannels)