Jean-Marc Valin | 8b2ff0d | 2009-10-17 21:40:10 -0400 | [diff] [blame] | 1 | /* 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 Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 5 | /* |
| 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 Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 37 | #include "celt_types.h" |
Jean-Marc Valin | 73e51b3 | 2007-12-05 17:48:24 +1100 | [diff] [blame] | 38 | #include "celt.h" |
Jean-Marc Valin | 8b2a592 | 2008-02-29 00:32:51 +1100 | [diff] [blame] | 39 | #include "arch.h" |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 40 | #include "mdct.h" |
Jean-Marc Valin | 961f723 | 2010-07-01 10:14:20 -0400 | [diff] [blame] | 41 | #include "entenc.h" |
| 42 | #include "entdec.h" |
Jean-Marc Valin | 29f5299 | 2008-03-10 13:34:52 +1100 | [diff] [blame] | 43 | |
Jean-Marc Valin | cae30df | 2010-05-21 00:26:03 -0400 | [diff] [blame] | 44 | #define MAX_CONFIG_SIZES 5 |
Jean-Marc Valin | 073d0bc | 2010-05-05 21:37:53 -0400 | [diff] [blame] | 45 | |
Jean-Marc Valin | f9fdbff | 2010-09-05 21:02:38 -0400 | [diff] [blame] | 46 | #define CELT_BITSTREAM_VERSION 0x8000000e |
Jean-Marc Valin | 59093c0 | 2008-05-15 21:53:27 +1000 | [diff] [blame] | 47 | |
Jean-Marc Valin | b18ec0b | 2008-04-11 04:07:52 +1000 | [diff] [blame] | 48 | #ifdef STATIC_MODES |
| 49 | #include "static_modes.h" |
| 50 | #endif |
| 51 | |
Jean-Marc Valin | 29f5299 | 2008-03-10 13:34:52 +1100 | [diff] [blame] | 52 | #define MAX_PERIOD 1024 |
Jean-Marc Valin | 73e51b3 | 2007-12-05 17:48:24 +1100 | [diff] [blame] | 53 | |
Jean-Marc Valin | b18ec0b | 2008-04-11 04:07:52 +1000 | [diff] [blame] | 54 | #ifndef CHANNELS |
| 55 | # ifdef DISABLE_STEREO |
Jean-Marc Valin | bf2398b | 2009-10-15 07:28:19 -0400 | [diff] [blame] | 56 | # define CHANNELS(_C) (1) |
Jean-Marc Valin | b18ec0b | 2008-04-11 04:07:52 +1000 | [diff] [blame] | 57 | # else |
Jean-Marc Valin | bf2398b | 2009-10-15 07:28:19 -0400 | [diff] [blame] | 58 | # define CHANNELS(_C) (_C) |
Jean-Marc Valin | b18ec0b | 2008-04-11 04:07:52 +1000 | [diff] [blame] | 59 | # endif |
Jean-Marc Valin | 05e56c4 | 2008-04-10 09:13:05 +1000 | [diff] [blame] | 60 | #endif |
| 61 | |
Jean-Marc Valin | b18ec0b | 2008-04-11 04:07:52 +1000 | [diff] [blame] | 62 | #ifndef OVERLAP |
| 63 | #define OVERLAP(mode) ((mode)->overlap) |
| 64 | #endif |
| 65 | |
| 66 | #ifndef FRAMESIZE |
| 67 | #define FRAMESIZE(mode) ((mode)->mdctSize) |
| 68 | #endif |
Jean-Marc Valin | 05e56c4 | 2008-04-10 09:13:05 +1000 | [diff] [blame] | 69 | |
Jean-Marc Valin | 3ad8db4 | 2010-08-25 13:11:09 -0400 | [diff] [blame] | 70 | typedef struct { |
Jean-Marc Valin | 732ea38 | 2010-08-25 13:52:27 -0400 | [diff] [blame] | 71 | int size; |
| 72 | const celt_int16 *index; |
| 73 | const unsigned char *bits; |
Jean-Marc Valin | 3ad8db4 | 2010-08-25 13:11:09 -0400 | [diff] [blame] | 74 | } PulseCache; |
| 75 | |
Jean-Marc Valin | 276de72 | 2008-02-20 17:45:51 +1100 | [diff] [blame] | 76 | /** Mode definition (opaque) |
| 77 | @brief Mode definition |
| 78 | */ |
Jean-Marc Valin | c245a22 | 2007-12-06 19:14:20 +1100 | [diff] [blame] | 79 | struct CELTMode { |
Jean-Marc Valin | 30f7f81 | 2009-10-17 14:35:13 -0400 | [diff] [blame] | 80 | celt_int32 Fs; |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 81 | int overlap; |
Jean-Marc Valin | 80ed147 | 2009-10-15 21:45:32 -0400 | [diff] [blame] | 82 | |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 83 | int nbEBands; |
Jean-Marc Valin | 85f41b2 | 2010-07-16 18:12:45 -0400 | [diff] [blame] | 84 | int effEBands; |
Jean-Marc Valin | af1fce9 | 2010-07-16 11:05:06 -0400 | [diff] [blame] | 85 | celt_word16 preemph[4]; |
Jean-Marc Valin | 30f7f81 | 2009-10-17 14:35:13 -0400 | [diff] [blame] | 86 | const celt_int16 *eBands; /**< Definition for each "pseudo-critical band" */ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 87 | |
Jean-Marc Valin | 276de72 | 2008-02-20 17:45:51 +1100 | [diff] [blame] | 88 | int nbAllocVectors; /**< Number of lines in the matrix below */ |
Jean-Marc Valin | 01b54b9 | 2010-06-03 23:29:35 -0400 | [diff] [blame] | 89 | const unsigned char *allocVectors; /**< Number of bits in each band for several rates */ |
Jean-Marc Valin | 25358cd | 2008-02-19 12:21:32 +1100 | [diff] [blame] | 90 | |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 91 | /* Stuff that could go in the {en,de}coder, but we save space this way */ |
Jean-Marc Valin | 72513f3 | 2010-07-07 21:26:38 -0400 | [diff] [blame] | 92 | mdct_lookup mdct; |
Jean-Marc Valin | 24c9cda | 2008-05-02 10:34:07 +1000 | [diff] [blame] | 93 | |
Jean-Marc Valin | 234969c | 2009-10-17 22:12:42 -0400 | [diff] [blame] | 94 | const celt_word16 *window; |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 95 | |
Jean-Marc Valin | 72513f3 | 2010-07-07 21:26:38 -0400 | [diff] [blame] | 96 | int maxLM; |
Jean-Marc Valin | 9d1decd | 2008-06-17 13:28:13 +1000 | [diff] [blame] | 97 | int nbShortMdcts; |
| 98 | int shortMdctSize; |
Jean-Marc Valin | 9d1decd | 2008-06-17 13:28:13 +1000 | [diff] [blame] | 99 | |
Jean-Marc Valin | bb52881 | 2010-08-25 22:12:18 -0400 | [diff] [blame] | 100 | const celt_int16 *prob; |
Jean-Marc Valin | f400a3c | 2010-04-05 23:58:44 -0400 | [diff] [blame] | 101 | const celt_int16 *logN; |
Jean-Marc Valin | 3ad8db4 | 2010-08-25 13:11:09 -0400 | [diff] [blame] | 102 | |
| 103 | PulseCache cache; |
Jean-Marc Valin | 73e51b3 | 2007-12-05 17:48:24 +1100 | [diff] [blame] | 104 | }; |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 105 | |
Jean-Marc Valin | 961f723 | 2010-07-01 10:14:20 -0400 | [diff] [blame] | 106 | /* Prototypes for _ec versions of the encoder/decoder calls (not public) */ |
| 107 | int 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); |
| 108 | int 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); |
| 109 | int 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 Valin | b6a5f9d | 2010-07-06 17:54:33 -0400 | [diff] [blame] | 110 | int 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 Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 111 | #endif |