blob: 826ab40053b90bf7b08c5c5019b9c0dfbb873f0b [file] [log] [blame]
Jean-Marc Valin8b2ff0d2009-10-17 21:40:10 -04001/* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2009 Xiph.Org Foundation
3 Copyright (c) 2008 Gregory Maxwell
4 Written by Jean-Marc Valin and Gregory Maxwell */
Jean-Marc Valinecb36a32007-12-05 01:31:49 +11005/*
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 - Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 - Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17 - Neither the name of the Xiph.org Foundation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*/
33
34#ifndef MODES_H
35#define MODES_H
36
Jean-Marc Valin81a82952008-02-17 22:41:29 +110037#include "celt_types.h"
Jean-Marc Valin73e51b32007-12-05 17:48:24 +110038#include "celt.h"
Jean-Marc Valin8b2a5922008-02-29 00:32:51 +110039#include "arch.h"
Jean-Marc Valin81b38c22008-02-29 21:08:49 +110040#include "mdct.h"
Jean-Marc Valin961f7232010-07-01 10:14:20 -040041#include "entenc.h"
42#include "entdec.h"
Jean-Marc Valin29f52992008-03-10 13:34:52 +110043
Jean-Marc Valincae30df2010-05-21 00:26:03 -040044#define MAX_CONFIG_SIZES 5
Jean-Marc Valin073d0bc2010-05-05 21:37:53 -040045
Jean-Marc Valinf9fdbff2010-09-05 21:02:38 -040046#define CELT_BITSTREAM_VERSION 0x8000000e
Jean-Marc Valin59093c02008-05-15 21:53:27 +100047
Jean-Marc Valinb18ec0b2008-04-11 04:07:52 +100048#ifdef STATIC_MODES
49#include "static_modes.h"
50#endif
51
Jean-Marc Valin29f52992008-03-10 13:34:52 +110052#define MAX_PERIOD 1024
Jean-Marc Valin73e51b32007-12-05 17:48:24 +110053
Jean-Marc Valinb18ec0b2008-04-11 04:07:52 +100054#ifndef CHANNELS
55# ifdef DISABLE_STEREO
Jean-Marc Valinbf2398b2009-10-15 07:28:19 -040056# define CHANNELS(_C) (1)
Jean-Marc Valinb18ec0b2008-04-11 04:07:52 +100057# else
Jean-Marc Valinbf2398b2009-10-15 07:28:19 -040058# define CHANNELS(_C) (_C)
Jean-Marc Valinb18ec0b2008-04-11 04:07:52 +100059# endif
Jean-Marc Valin05e56c42008-04-10 09:13:05 +100060#endif
61
Jean-Marc Valinb18ec0b2008-04-11 04:07:52 +100062#ifndef OVERLAP
63#define OVERLAP(mode) ((mode)->overlap)
64#endif
65
66#ifndef FRAMESIZE
67#define FRAMESIZE(mode) ((mode)->mdctSize)
68#endif
Jean-Marc Valin05e56c42008-04-10 09:13:05 +100069
Jean-Marc Valin3ad8db42010-08-25 13:11:09 -040070typedef struct {
Jean-Marc Valin732ea382010-08-25 13:52:27 -040071 int size;
72 const celt_int16 *index;
73 const unsigned char *bits;
Jean-Marc Valin3ad8db42010-08-25 13:11:09 -040074} PulseCache;
75
Jean-Marc Valin276de722008-02-20 17:45:51 +110076/** Mode definition (opaque)
77 @brief Mode definition
78 */
Jean-Marc Valinc245a222007-12-06 19:14:20 +110079struct CELTMode {
Jean-Marc Valin30f7f812009-10-17 14:35:13 -040080 celt_int32 Fs;
Jean-Marc Valina5431bf2008-01-03 20:53:01 +110081 int overlap;
Jean-Marc Valin80ed1472009-10-15 21:45:32 -040082
Jean-Marc Valinecb36a32007-12-05 01:31:49 +110083 int nbEBands;
Jean-Marc Valin85f41b22010-07-16 18:12:45 -040084 int effEBands;
Jean-Marc Valinaf1fce92010-07-16 11:05:06 -040085 celt_word16 preemph[4];
Jean-Marc Valin30f7f812009-10-17 14:35:13 -040086 const celt_int16 *eBands; /**< Definition for each "pseudo-critical band" */
Jean-Marc Valin36d78e62007-12-13 14:59:30 +110087
Jean-Marc Valin276de722008-02-20 17:45:51 +110088 int nbAllocVectors; /**< Number of lines in the matrix below */
Jean-Marc Valin01b54b92010-06-03 23:29:35 -040089 const unsigned char *allocVectors; /**< Number of bits in each band for several rates */
Jean-Marc Valin25358cd2008-02-19 12:21:32 +110090
Jean-Marc Valin81b38c22008-02-29 21:08:49 +110091 /* Stuff that could go in the {en,de}coder, but we save space this way */
Jean-Marc Valin72513f32010-07-07 21:26:38 -040092 mdct_lookup mdct;
Jean-Marc Valin24c9cda2008-05-02 10:34:07 +100093
Jean-Marc Valin234969c2009-10-17 22:12:42 -040094 const celt_word16 *window;
Jean-Marc Valin81b38c22008-02-29 21:08:49 +110095
Jean-Marc Valin72513f32010-07-07 21:26:38 -040096 int maxLM;
Jean-Marc Valin9d1decd2008-06-17 13:28:13 +100097 int nbShortMdcts;
98 int shortMdctSize;
Jean-Marc Valin9d1decd2008-06-17 13:28:13 +100099
Jean-Marc Valinbb528812010-08-25 22:12:18 -0400100 const celt_int16 *prob;
Jean-Marc Valinf400a3c2010-04-05 23:58:44 -0400101 const celt_int16 *logN;
Jean-Marc Valin3ad8db42010-08-25 13:11:09 -0400102
103 PulseCache cache;
Jean-Marc Valin73e51b32007-12-05 17:48:24 +1100104};
Jean-Marc Valinecb36a32007-12-05 01:31:49 +1100105
Jean-Marc Valin961f7232010-07-01 10:14:20 -0400106/* Prototypes for _ec versions of the encoder/decoder calls (not public) */
107int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
108int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, float * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
109int celt_decode_with_ec(CELTDecoder * restrict st, const unsigned char *data, int len, celt_int16 * restrict pcm, int frame_size, ec_dec *dec);
Jean-Marc Valinb6a5f9d2010-07-06 17:54:33 -0400110int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *data, int len, float * restrict pcm, int frame_size, ec_dec *dec);
Jean-Marc Valinecb36a32007-12-05 01:31:49 +1100111#endif