Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 1 | /* (C) 2007 Jean-Marc Valin, CSIRO |
| 2 | */ |
| 3 | /* |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions |
| 6 | are met: |
| 7 | |
| 8 | - Redistributions of source code must retain the above copyright |
| 9 | notice, this list of conditions and the following disclaimer. |
| 10 | |
| 11 | - Redistributions in binary form must reproduce the above copyright |
| 12 | notice, this list of conditions and the following disclaimer in the |
| 13 | documentation and/or other materials provided with the distribution. |
| 14 | |
| 15 | - Neither the name of the Xiph.org Foundation nor the names of its |
| 16 | contributors may be used to endorse or promote products derived from |
| 17 | this software without specific prior written permission. |
| 18 | |
| 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 23 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #include "modes.h" |
| 33 | |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 34 | #define NBANDS 18 |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 35 | #define PBANDS 8 |
Jean-Marc Valin | 95c59ea | 2008-01-08 16:22:37 +1100 | [diff] [blame] | 36 | #define PITCH_END 74 |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 37 | |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 38 | #define NBANDS128 15 |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 39 | #define PBANDS128 8 |
| 40 | #define PITCH_END128 45 |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 41 | |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 42 | static const float means[15] = { |
| 43 | 14.8621, 12.6918, 10.2978, 9.5862, 10.3784, |
| 44 | 10.4555, 9.1594, 9.0280, 8.3291, 8.3410, |
| 45 | 8.5737, 8.5614, 9.0107, 7.6809, 7.0665}; |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 46 | |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 47 | static const float means18[18] = { |
| 48 | 9.9067, 8.4524, 6.8577, 6.3804, 6.1786, 5.9815, |
| 49 | 6.2068, 6.1076, 5.7711, 5.7734, 5.7935, 5.3981, |
| 50 | 5.1992, 5.7214, 5.9656, 5.7548, 5.0802, 4.2626}; |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 51 | |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 52 | static const int decay[15] = { |
| 53 | 14800, 13800, 12600, 12000, 11000, 10000, 9800, 8400, 8000, 7500, 7000, 7000, 7000, 6000, 6000 |
| 54 | }; |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 55 | |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 56 | static const int decay18[18] = { |
| 57 | 14800, 13800, 12600, 12000, 11000, 11000, 10000, 10000, 9800, 8400, 8400, 8000, 7500, 7000, 7000, 7000, 6000, 6000 |
| 58 | }; |
| 59 | |
Jean-Marc Valin | 95c59ea | 2008-01-08 16:22:37 +1100 | [diff] [blame] | 60 | const int qbank0[NBANDS +2] = {0, 4, 8, 12, 16, 20, 24, 28, 32, 38, 44, 52, 62, 74, 90,112,142,182, 232,256}; |
| 61 | const int pbank0[PBANDS +2] = {0, 4, 8, 12, 16, 24, 38, 62, PITCH_END, 256}; |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 62 | //const int pbank0[PBANDS +2] = {0, 4, 8, 12, 19, PITCH_END, 128}; |
Jean-Marc Valin | ec71aee | 2008-01-12 23:38:01 +1100 | [diff] [blame] | 63 | const int qpulses0[NBANDS ] = {7, 6, 6, 5, 5, 5, 5, 4, 3, 3, 3, 3, 3, 3, -3, -2, 0, 0}; |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 64 | //const int qpulses0[NBANDS ] = {7, 5, 5, 5, 4, 4, 3, 3, 3, 3, 4, 3, 3, -2, 0, 0, 0, 0}; |
| 65 | |
| 66 | |
| 67 | const int qbank1[NBANDS128+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128}; |
| 68 | |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 69 | const int qpulses1[NBANDS128] = {7, 5, 5, 5, 4, 5, 4, 5, 5, 4, 2, 0, 0, 0, 0}; |
Jean-Marc Valin | a2482ac | 2008-01-11 11:24:22 +1100 | [diff] [blame] | 70 | const int qpulses2[NBANDS] = {28,25,23,20,18,15, 13, 11, 10, 8,8, 7, 7, -6, -5, -4, -1, -1}; |
| 71 | //const int qpulses2[NBANDS128] = {28,24,20,16,24,20, 18, 12, 10, 10,-7, -4, 1, 1, 1, 1, 1, 1}; |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 72 | const int qpulses2s[NBANDS128] ={38,30,24,20,24,20, 18, 16, 14, 20,-20,-14, -8, -8, -5}; |
| 73 | |
Jean-Marc Valin | a2482ac | 2008-01-11 11:24:22 +1100 | [diff] [blame] | 74 | const int qpulses4s[NBANDS] ={38,31,25,21,18,16, 14, 12, 14, 12,14,15, 14, 15, 16, 12, 10, 6}; |
Jean-Marc Valin | f8dda66 | 2008-01-10 17:02:36 +1100 | [diff] [blame] | 75 | |
| 76 | //const int qpulses4s[NBANDS128] ={38,35,30,27,24,22, 21, 20, 22, 20,20,20, 20, 20, 14, 12, 12, 12}; |
| 77 | |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 78 | const int pbank1[PBANDS128+2] = {0, 2, 4, 6, 8, 12, 20, 28, PITCH_END128, 128}; |
| 79 | //const int pbank1[PBANDS128+2] = {0, 4, 8, 12, 20, PITCH_END128, 128}; |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 80 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 81 | #define NALLOCS 7 |
| 82 | int bitalloc0[NBANDS*NALLOCS] = |
| 83 | { 5, 4, 4, 4, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, |
| 84 | 8, 7, 7, 6, 6, 6, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 85 | 10, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 17, 15, 6, 7, |
| 86 | 16, 15, 14, 14, 14, 13, 13, 13, 13, 13, 15, 16, 17, 18, 20, 18, 11, 12, |
| 87 | 26, 25, 24, 22, 20, 18, 19, 19, 25, 22, 25, 30, 30, 35, 35, 35, 35, 25, |
| 88 | 32, 30, 28, 27, 25, 24, 23, 21, 29, 27, 35, 40, 42, 50, 59, 54, 51, 36, |
| 89 | 42, 40, 38, 37, 35, 34, 33, 31, 39, 37, 45, 50, 52, 60, 60, 60, 60, 46, |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 90 | }; |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 91 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 92 | |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 93 | #define NBANDS256 15 |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 94 | #define PBANDS256 8 |
| 95 | #define PITCH_END256 88 |
Jean-Marc Valin | a4833ff | 2008-01-10 15:34:00 +1100 | [diff] [blame] | 96 | const int qbank3[NBANDS256+2] = {0, 4, 8, 12, 16, 24, 32, 40, 48, 56, 72, 88, 104, 136, 168, 232, 256}; |
Jean-Marc Valin | 2875f6b | 2008-01-05 13:32:32 +1100 | [diff] [blame] | 97 | //const int pbank3[PBANDS256+2] = {0, 8, 16, 24, 40, PITCH_END256, 256}; |
Jean-Marc Valin | a4833ff | 2008-01-10 15:34:00 +1100 | [diff] [blame] | 98 | const int pbank3[PBANDS256+2] = {0, 4, 8, 12, 16, 24, 40, 56, PITCH_END256, 256}; |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 99 | |
| 100 | const CELTMode mode0 = { |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 101 | 128, /**< overlap */ |
Jean-Marc Valin | 95c59ea | 2008-01-08 16:22:37 +1100 | [diff] [blame] | 102 | 256, /**< mdctSize */ |
| 103 | 1, /**< nbMdctBlocks */ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 104 | 1, /**< channels */ |
| 105 | |
| 106 | NBANDS, /**< nbEBands */ |
| 107 | PBANDS, /**< nbPBands */ |
| 108 | PITCH_END, /**< pitchEnd */ |
| 109 | |
| 110 | qbank0, /**< eBands */ |
| 111 | pbank0, /**< pBands*/ |
| 112 | qpulses0, /**< nbPulses */ |
| 113 | |
| 114 | 0.8, /**< ePredCoef */ |
| 115 | means18, /**< eMeans */ |
| 116 | decay18, /**< eDecay */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 117 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 118 | 7, /**< nbAllocVectors */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 119 | bitalloc0, /**< allocVectors */ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 120 | }; |
| 121 | |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 122 | |
Jean-Marc Valin | 6baa8e1 | 2007-12-08 00:08:37 +1100 | [diff] [blame] | 123 | /* Approx 38 kbps @ 44.1 kHz */ |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 124 | const CELTMode mode1 = { |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 125 | 128, /**< overlap */ |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 126 | 128, /**< mdctSize */ |
| 127 | 2, /**< nbMdctBlocks */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 128 | 1, /**< channels */ |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 129 | |
| 130 | NBANDS128, /**< nbEBands */ |
| 131 | PBANDS128, /**< nbPBands */ |
| 132 | PITCH_END128,/**< pitchEnd */ |
| 133 | |
| 134 | qbank1, /**< eBands */ |
| 135 | pbank1, /**< pBands*/ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 136 | qpulses1, /**< nbPulses */ |
| 137 | |
| 138 | 0.7, /**< ePredCoef */ |
| 139 | means, /**< eMeans */ |
| 140 | decay, /**< eDecay */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 141 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 142 | 7, /**< nbAllocVectors */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 143 | bitalloc0, /**< allocVectors */ |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 144 | }; |
Jean-Marc Valin | 73e51b3 | 2007-12-05 17:48:24 +1100 | [diff] [blame] | 145 | |
Jean-Marc Valin | 6baa8e1 | 2007-12-08 00:08:37 +1100 | [diff] [blame] | 146 | /* Approx 58 kbps @ 44.1 kHz */ |
| 147 | const CELTMode mode2 = { |
Jean-Marc Valin | a2482ac | 2008-01-11 11:24:22 +1100 | [diff] [blame] | 148 | 256, /**< overlap */ |
| 149 | 256, /**< mdctSize */ |
| 150 | 1, /**< nbMdctBlocks */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 151 | 1, /**< channels */ |
Jean-Marc Valin | 6baa8e1 | 2007-12-08 00:08:37 +1100 | [diff] [blame] | 152 | |
Jean-Marc Valin | a2482ac | 2008-01-11 11:24:22 +1100 | [diff] [blame] | 153 | NBANDS, /**< nbEBands */ |
| 154 | PBANDS, /**< nbPBands */ |
| 155 | PITCH_END,/**< pitchEnd */ |
Jean-Marc Valin | 6baa8e1 | 2007-12-08 00:08:37 +1100 | [diff] [blame] | 156 | |
Jean-Marc Valin | a2482ac | 2008-01-11 11:24:22 +1100 | [diff] [blame] | 157 | qbank0, /**< eBands */ |
| 158 | pbank0, /**< pBands*/ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 159 | qpulses2, /**< nbPulses */ |
| 160 | |
Jean-Marc Valin | a2482ac | 2008-01-11 11:24:22 +1100 | [diff] [blame] | 161 | 0.8, /**< ePredCoef */ |
| 162 | means18, /**< eMeans */ |
| 163 | decay18, /**< eDecay */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 164 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 165 | 7, /**< nbAllocVectors */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 166 | bitalloc0, /**< allocVectors */ |
Jean-Marc Valin | 6baa8e1 | 2007-12-08 00:08:37 +1100 | [diff] [blame] | 167 | }; |
| 168 | |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 169 | const CELTMode mode3 = { |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 170 | 128, /**< overlap */ |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 171 | 256, /**< mdctSize */ |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 172 | 1, /**< nbMdctBlocks */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 173 | 1, /**< channels */ |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 174 | |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 175 | NBANDS256, /**< nbEBands */ |
| 176 | PBANDS256, /**< nbPBands */ |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 177 | PITCH_END256,/**< pitchEnd */ |
| 178 | |
| 179 | qbank3, /**< eBands */ |
| 180 | pbank3, /**< pBands*/ |
Jean-Marc Valin | a5431bf | 2008-01-03 20:53:01 +1100 | [diff] [blame] | 181 | qpulses1, /**< nbPulses */ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 182 | |
| 183 | 0.7, /**< ePredCoef */ |
| 184 | means, /**< eMeans */ |
| 185 | decay, /**< eDecay */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 186 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 187 | 7, /**< nbAllocVectors */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 188 | bitalloc0, /**< allocVectors */ |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 189 | }; |
| 190 | |
Jean-Marc Valin | 4a89768 | 2007-12-12 00:45:15 +1100 | [diff] [blame] | 191 | /* Stereo mode around 120 kbps */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 192 | const CELTMode mode4 = { |
Jean-Marc Valin | f8dda66 | 2008-01-10 17:02:36 +1100 | [diff] [blame] | 193 | 256, /**< overlap */ |
Jean-Marc Valin | fdca84b | 2008-01-09 10:44:18 +1100 | [diff] [blame] | 194 | 256, /**< mdctSize */ |
| 195 | 1, /**< nbMdctBlocks */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 196 | 2, /**< channels */ |
| 197 | |
Jean-Marc Valin | f8dda66 | 2008-01-10 17:02:36 +1100 | [diff] [blame] | 198 | NBANDS, /**< nbEBands */ |
| 199 | PBANDS, /**< nbPBands */ |
| 200 | PITCH_END,/**< pitchEnd */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 201 | |
Jean-Marc Valin | f8dda66 | 2008-01-10 17:02:36 +1100 | [diff] [blame] | 202 | qbank0, /**< eBands */ |
| 203 | pbank0, /**< pBands*/ |
| 204 | qpulses4s, /**< nbPulses */ |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 205 | |
Jean-Marc Valin | f8dda66 | 2008-01-10 17:02:36 +1100 | [diff] [blame] | 206 | 0.8, /**< ePredCoef */ |
| 207 | means18, /**< eMeans */ |
| 208 | decay18, /**< eDecay */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 209 | |
Jean-Marc Valin | 4fbd18d | 2008-01-17 14:07:55 +1100 | [diff] [blame^] | 210 | 7, /**< nbAllocVectors */ |
Jean-Marc Valin | f51ca49 | 2008-01-17 10:58:38 +1100 | [diff] [blame] | 211 | bitalloc0, /**< allocVectors */ |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 212 | }; |
| 213 | |
Jean-Marc Valin | 36d78e6 | 2007-12-13 14:59:30 +1100 | [diff] [blame] | 214 | const CELTMode const *celt_mode0 = &mode0; |
Jean-Marc Valin | 73e51b3 | 2007-12-05 17:48:24 +1100 | [diff] [blame] | 215 | const CELTMode const *celt_mode1 = &mode1; |
Jean-Marc Valin | 6baa8e1 | 2007-12-08 00:08:37 +1100 | [diff] [blame] | 216 | const CELTMode const *celt_mode2 = &mode2; |
Jean-Marc Valin | aa5bd61 | 2007-12-08 00:27:10 +1100 | [diff] [blame] | 217 | const CELTMode const *celt_mode3 = &mode3; |
Jean-Marc Valin | ffa1347 | 2007-12-10 16:54:17 +1100 | [diff] [blame] | 218 | const CELTMode const *celt_mode4 = &mode4; |