1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Bluetooth low-complexity, subband codec (SBC)
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * Copyright (C) 2017  Aurelien Jacobs <aurel@gnuage.org>
5cabdff1aSopenharmony_ci * Copyright (C) 2008-2010  Nokia Corporation
6cabdff1aSopenharmony_ci * Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7cabdff1aSopenharmony_ci * Copyright (C) 2004-2005  Henryk Ploetz <henryk@ploetzli.ch>
8cabdff1aSopenharmony_ci * Copyright (C) 2005-2006  Brad Midgley <bmidgley@xmission.com>
9cabdff1aSopenharmony_ci *
10cabdff1aSopenharmony_ci * This file is part of FFmpeg.
11cabdff1aSopenharmony_ci *
12cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
13cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
14cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
15cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
18cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
19cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20cabdff1aSopenharmony_ci * Lesser General Public License for more details.
21cabdff1aSopenharmony_ci *
22cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
23cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
24cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25cabdff1aSopenharmony_ci */
26cabdff1aSopenharmony_ci
27cabdff1aSopenharmony_ci/**
28cabdff1aSopenharmony_ci * @file
29cabdff1aSopenharmony_ci * SBC basic "building bricks"
30cabdff1aSopenharmony_ci */
31cabdff1aSopenharmony_ci
32cabdff1aSopenharmony_ci#ifndef AVCODEC_SBCDSP_H
33cabdff1aSopenharmony_ci#define AVCODEC_SBCDSP_H
34cabdff1aSopenharmony_ci
35cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h"
36cabdff1aSopenharmony_ci
37cabdff1aSopenharmony_ci#include "sbc.h"
38cabdff1aSopenharmony_ci#include "sbcdsp_data.h"
39cabdff1aSopenharmony_ci
40cabdff1aSopenharmony_ci#define SCALE_OUT_BITS 15
41cabdff1aSopenharmony_ci#define SBC_X_BUFFER_SIZE 328
42cabdff1aSopenharmony_ci
43cabdff1aSopenharmony_citypedef struct sbc_dsp_context SBCDSPContext;
44cabdff1aSopenharmony_ci
45cabdff1aSopenharmony_cistruct sbc_dsp_context {
46cabdff1aSopenharmony_ci    int position;
47cabdff1aSopenharmony_ci    /* Number of consecutive blocks handled by the encoder */
48cabdff1aSopenharmony_ci    uint8_t increment;
49cabdff1aSopenharmony_ci    DECLARE_ALIGNED(SBC_ALIGN, int16_t, X)[2][SBC_X_BUFFER_SIZE];
50cabdff1aSopenharmony_ci    void (*sbc_analyze_4)(const int16_t *in, int32_t *out, const int16_t *consts);
51cabdff1aSopenharmony_ci    void (*sbc_analyze_8)(const int16_t *in, int32_t *out, const int16_t *consts);
52cabdff1aSopenharmony_ci    /* Polyphase analysis filter for 4 subbands configuration,
53cabdff1aSopenharmony_ci     * it handles "increment" blocks at once */
54cabdff1aSopenharmony_ci    void (*sbc_analyze_4s)(SBCDSPContext *s,
55cabdff1aSopenharmony_ci                           int16_t *x, int32_t *out, int out_stride);
56cabdff1aSopenharmony_ci    /* Polyphase analysis filter for 8 subbands configuration,
57cabdff1aSopenharmony_ci     * it handles "increment" blocks at once */
58cabdff1aSopenharmony_ci    void (*sbc_analyze_8s)(SBCDSPContext *s,
59cabdff1aSopenharmony_ci                           int16_t *x, int32_t *out, int out_stride);
60cabdff1aSopenharmony_ci    /* Process input data (deinterleave, endian conversion, reordering),
61cabdff1aSopenharmony_ci     * depending on the number of subbands and input data byte order */
62cabdff1aSopenharmony_ci    int (*sbc_enc_process_input_4s)(int position, const uint8_t *pcm,
63cabdff1aSopenharmony_ci                                    int16_t X[2][SBC_X_BUFFER_SIZE],
64cabdff1aSopenharmony_ci                                    int nsamples, int nchannels);
65cabdff1aSopenharmony_ci    int (*sbc_enc_process_input_8s)(int position, const uint8_t *pcm,
66cabdff1aSopenharmony_ci                                    int16_t X[2][SBC_X_BUFFER_SIZE],
67cabdff1aSopenharmony_ci                                    int nsamples, int nchannels);
68cabdff1aSopenharmony_ci    /* Scale factors calculation */
69cabdff1aSopenharmony_ci    void (*sbc_calc_scalefactors)(int32_t sb_sample_f[16][2][8],
70cabdff1aSopenharmony_ci                                  uint32_t scale_factor[2][8],
71cabdff1aSopenharmony_ci                                  int blocks, int channels, int subbands);
72cabdff1aSopenharmony_ci    /* Scale factors calculation with joint stereo support */
73cabdff1aSopenharmony_ci    int (*sbc_calc_scalefactors_j)(int32_t sb_sample_f[16][2][8],
74cabdff1aSopenharmony_ci                                   uint32_t scale_factor[2][8],
75cabdff1aSopenharmony_ci                                   int blocks, int subbands);
76cabdff1aSopenharmony_ci};
77cabdff1aSopenharmony_ci
78cabdff1aSopenharmony_ci/*
79cabdff1aSopenharmony_ci * Initialize pointers to the functions which are the basic "building bricks"
80cabdff1aSopenharmony_ci * of SBC codec. Best implementation is selected based on target CPU
81cabdff1aSopenharmony_ci * capabilities.
82cabdff1aSopenharmony_ci */
83cabdff1aSopenharmony_civoid ff_sbcdsp_init(SBCDSPContext *s);
84cabdff1aSopenharmony_ci
85cabdff1aSopenharmony_civoid ff_sbcdsp_init_arm(SBCDSPContext *s);
86cabdff1aSopenharmony_civoid ff_sbcdsp_init_x86(SBCDSPContext *s);
87cabdff1aSopenharmony_ci
88cabdff1aSopenharmony_ci#endif /* AVCODEC_SBCDSP_H */
89