Jean-Marc Valin | 8b2a592 | 2008-02-29 00:32:51 +1100 | [diff] [blame] | 1 | /* (C) 2007-2008 Jean-Marc Valin, CSIRO |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 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 | |
Jean-Marc Valin | 02fa913 | 2008-02-20 12:09:29 +1100 | [diff] [blame] | 32 | #ifdef HAVE_CONFIG_H |
| 33 | #include "config.h" |
| 34 | #endif |
| 35 | |
Jean-Marc Valin | 65d57e6 | 2008-02-18 15:49:37 +1100 | [diff] [blame] | 36 | #include "celt.h" |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 37 | #include "modes.h" |
Jean-Marc Valin | 472a5f0 | 2008-02-19 13:12:32 +1100 | [diff] [blame] | 38 | #include "rate.h" |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 39 | #include "os_support.h" |
Jean-Marc Valin | f7cec83 | 2008-04-18 17:29:56 +1000 | [diff] [blame] | 40 | #include "stack_alloc.h" |
Jean-Marc Valin | 4ce9205 | 2008-04-23 13:42:10 +1000 | [diff] [blame] | 41 | #include "quant_bands.h" |
Jean-Marc Valin | ecb36a3 | 2007-12-05 01:31:49 +1100 | [diff] [blame] | 42 | |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 43 | #ifdef STATIC_MODES |
Jean-Marc Valin | b18ec0b | 2008-04-11 04:07:52 +1000 | [diff] [blame] | 44 | #include "static_modes.c" |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 45 | #endif |
| 46 | |
Jean-Marc Valin | 44ffd5a | 2008-02-22 00:39:25 +1100 | [diff] [blame] | 47 | #define MODEVALID 0xa110ca7e |
| 48 | #define MODEFREED 0xb10cf8ee |
| 49 | |
Jean-Marc Valin | d748cd5 | 2008-03-01 07:27:03 +1100 | [diff] [blame] | 50 | #ifndef M_PI |
| 51 | #define M_PI 3.141592653 |
| 52 | #endif |
| 53 | |
Jean-Marc Valin | 44ffd5a | 2008-02-22 00:39:25 +1100 | [diff] [blame] | 54 | |
Peter Kirk | 19f9dc9 | 2008-06-06 14:38:38 +0200 | [diff] [blame] | 55 | int celt_mode_info(const CELTMode *mode, int request, celt_int32_t *value) |
Jean-Marc Valin | f997ad5 | 2008-01-31 16:47:16 +1100 | [diff] [blame] | 56 | { |
| 57 | switch (request) |
| 58 | { |
| 59 | case CELT_GET_FRAME_SIZE: |
| 60 | *value = mode->mdctSize; |
| 61 | break; |
| 62 | case CELT_GET_LOOKAHEAD: |
| 63 | *value = mode->overlap; |
| 64 | break; |
Jean-Marc Valin | 4c6bc88 | 2008-01-31 17:34:27 +1100 | [diff] [blame] | 65 | case CELT_GET_NB_CHANNELS: |
| 66 | *value = mode->nbChannels; |
| 67 | break; |
Jean-Marc Valin | 59093c0 | 2008-05-15 21:53:27 +1000 | [diff] [blame] | 68 | case CELT_GET_BITSTREAM_VERSION: |
| 69 | *value = CELT_BITSTREAM_VERSION; |
| 70 | break; |
Jean-Marc Valin | cb7a2a3 | 2008-02-11 16:44:48 +1100 | [diff] [blame] | 71 | default: |
Jean-Marc Valin | b6f9061 | 2008-10-05 22:39:13 -0400 | [diff] [blame^] | 72 | return CELT_UNIMPLEMENTED; |
Jean-Marc Valin | f997ad5 | 2008-01-31 16:47:16 +1100 | [diff] [blame] | 73 | } |
Jean-Marc Valin | cb7a2a3 | 2008-02-11 16:44:48 +1100 | [diff] [blame] | 74 | return CELT_OK; |
Jean-Marc Valin | f997ad5 | 2008-01-31 16:47:16 +1100 | [diff] [blame] | 75 | } |
| 76 | |
Jean-Marc Valin | 5588d52 | 2008-03-10 15:07:58 +1100 | [diff] [blame] | 77 | #ifndef STATIC_MODES |
| 78 | |
Jean-Marc Valin | 134492a | 2008-02-18 16:46:22 +1100 | [diff] [blame] | 79 | #define PBANDS 8 |
Jean-Marc Valin | 47c248a | 2008-04-26 08:16:12 +1000 | [diff] [blame] | 80 | |
| 81 | #ifdef STDIN_TUNING |
| 82 | int MIN_BINS; |
| 83 | #else |
Jean-Marc Valin | 52824c7 | 2008-05-06 18:01:17 +1000 | [diff] [blame] | 84 | #define MIN_BINS 3 |
Jean-Marc Valin | 47c248a | 2008-04-26 08:16:12 +1000 | [diff] [blame] | 85 | #endif |
| 86 | |
Jean-Marc Valin | 17683eb | 2008-02-18 21:45:19 +1100 | [diff] [blame] | 87 | /* Defining 25 critical bands for the full 0-20 kHz audio bandwidth |
| 88 | Taken from http://ccrma.stanford.edu/~jos/bbt/Bark_Frequency_Scale.html */ |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 89 | #define BARK_BANDS 25 |
Jean-Marc Valin | 25358cd | 2008-02-19 12:21:32 +1100 | [diff] [blame] | 90 | static const celt_int16_t bark_freq[BARK_BANDS+1] = { |
Jean-Marc Valin | 17683eb | 2008-02-18 21:45:19 +1100 | [diff] [blame] | 91 | 0, 100, 200, 300, 400, |
| 92 | 510, 630, 770, 920, 1080, |
| 93 | 1270, 1480, 1720, 2000, 2320, |
| 94 | 2700, 3150, 3700, 4400, 5300, |
| 95 | 6400, 7700, 9500, 12000, 15500, |
| 96 | 20000}; |
| 97 | |
Jean-Marc Valin | 25358cd | 2008-02-19 12:21:32 +1100 | [diff] [blame] | 98 | static const celt_int16_t pitch_freq[PBANDS+1] ={0, 345, 689, 1034, 1378, 2067, 3273, 5340, 6374}; |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 99 | |
Jean-Marc Valin | 75e9c86 | 2008-02-18 17:04:15 +1100 | [diff] [blame] | 100 | /* This allocation table is per critical band. When creating a mode, the bits get added together |
| 101 | into the codec bands, which are sometimes larger than one critical band at low frequency */ |
Jean-Marc Valin | 47c248a | 2008-04-26 08:16:12 +1000 | [diff] [blame] | 102 | |
| 103 | #ifdef STDIN_TUNING |
| 104 | int BITALLOC_SIZE; |
| 105 | int *band_allocation; |
| 106 | #else |
Jean-Marc Valin | 9c70906 | 2008-08-03 22:07:06 -0400 | [diff] [blame] | 107 | #define BITALLOC_SIZE 12 |
Jean-Marc Valin | 25358cd | 2008-02-19 12:21:32 +1100 | [diff] [blame] | 108 | static const int band_allocation[BARK_BANDS*BITALLOC_SIZE] = |
Jean-Marc Valin | 9c70906 | 2008-08-03 22:07:06 -0400 | [diff] [blame] | 109 | { 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 110 | 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
Jean-Marc Valin | 52824c7 | 2008-05-06 18:01:17 +1000 | [diff] [blame] | 111 | 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 4, 5, 7, 7, 7, 5, 4, 0, 0, 0, 0, 0, 0, |
| 112 | 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 3, 3, 5, 6, 8, 8, 8, 6, 5, 4, 0, 0, 0, 0, 0, |
| 113 | 3, 2, 2, 2, 3, 3, 2, 3, 2, 3, 4, 4, 6, 7, 9, 9, 9, 7, 6, 5, 5, 5, 0, 0, 0, |
| 114 | 3, 3, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 7, 9, 10, 10, 10, 9, 6, 5, 5, 5, 5, 1, 0, |
Jean-Marc Valin | 6855bf6 | 2008-05-07 16:44:29 +1000 | [diff] [blame] | 115 | 4, 3, 3, 3, 3, 3, 3, 3, 4, 4, 6, 7, 7, 9, 11, 10, 10, 9, 9, 8, 11, 10, 10, 1, 1, |
Jean-Marc Valin | f61be66 | 2008-09-22 10:46:55 -0400 | [diff] [blame] | 116 | 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 8, 8, 10, 12, 12, 11, 11, 17, 12, 15, 15, 20, 18, 10, 1, |
| 117 | 8, 7, 7, 7, 7, 7, 8, 8, 9, 10, 11, 12, 14, 17, 18, 21, 22, 27, 29, 39, 37, 38, 40, 35, 1, |
Jean-Marc Valin | 6855bf6 | 2008-05-07 16:44:29 +1000 | [diff] [blame] | 118 | 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 14, 18, 20, 24, 28, 32, 32, 35, 38, 38, 42, 50, 59, 54, 31, |
| 119 | 8, 8, 8, 8, 8, 9, 10, 12, 14, 20, 22, 25, 28, 30, 35, 42, 46, 50, 55, 60, 62, 62, 62, 62, 62, |
Jean-Marc Valin | 9eba823 | 2008-08-02 20:51:44 -0400 | [diff] [blame] | 120 | 12, 12, 12, 12, 12, 13, 15, 18, 22, 30, 32, 35, 40, 45, 55, 62, 66, 70, 85, 90, 92, 92, 92, 92, 92, |
| 121 | }; |
Jean-Marc Valin | 47c248a | 2008-04-26 08:16:12 +1000 | [diff] [blame] | 122 | #endif |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 123 | |
Jean-Marc Valin | db0141e | 2008-03-10 16:37:37 +1100 | [diff] [blame] | 124 | static celt_int16_t *compute_ebands(celt_int32_t Fs, int frame_size, int *nbEBands) |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 125 | { |
Jean-Marc Valin | db0141e | 2008-03-10 16:37:37 +1100 | [diff] [blame] | 126 | celt_int16_t *eBands; |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 127 | int i, res, min_width, lin, low, high, nBark; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 128 | res = (Fs+frame_size)/(2*frame_size); |
| 129 | min_width = MIN_BINS*res; |
Jean-Marc Valin | a85657b | 2008-02-20 11:59:30 +1100 | [diff] [blame] | 130 | /*printf ("min_width = %d\n", min_width);*/ |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 131 | |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 132 | /* Find the number of critical bands supported by our sampling rate */ |
| 133 | for (nBark=1;nBark<BARK_BANDS;nBark++) |
| 134 | if (bark_freq[nBark+1]*2 >= Fs) |
| 135 | break; |
| 136 | |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 137 | /* Find where the linear part ends (i.e. where the spacing is more than min_width */ |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 138 | for (lin=0;lin<nBark;lin++) |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 139 | if (bark_freq[lin+1]-bark_freq[lin] >= min_width) |
| 140 | break; |
| 141 | |
Jean-Marc Valin | a85657b | 2008-02-20 11:59:30 +1100 | [diff] [blame] | 142 | /*printf ("lin = %d (%d Hz)\n", lin, bark_freq[lin]);*/ |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 143 | low = ((bark_freq[lin]/res)+(MIN_BINS-1))/MIN_BINS; |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 144 | high = nBark-lin; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 145 | *nbEBands = low+high; |
Jean-Marc Valin | db0141e | 2008-03-10 16:37:37 +1100 | [diff] [blame] | 146 | eBands = celt_alloc(sizeof(celt_int16_t)*(*nbEBands+2)); |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 147 | |
| 148 | /* Linear spacing (min_width) */ |
| 149 | for (i=0;i<low;i++) |
| 150 | eBands[i] = MIN_BINS*i; |
| 151 | /* Spacing follows critical bands */ |
| 152 | for (i=0;i<high;i++) |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 153 | eBands[i+low] = (bark_freq[lin+i]+res/2)/res; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 154 | /* Enforce the minimum spacing at the boundary */ |
| 155 | for (i=0;i<*nbEBands;i++) |
| 156 | if (eBands[i] < MIN_BINS*i) |
| 157 | eBands[i] = MIN_BINS*i; |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 158 | eBands[*nbEBands] = (bark_freq[nBark]+res/2)/res; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 159 | eBands[*nbEBands+1] = frame_size; |
| 160 | if (eBands[*nbEBands] > eBands[*nbEBands+1]) |
| 161 | eBands[*nbEBands] = eBands[*nbEBands+1]; |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 162 | |
| 163 | /* FIXME: Remove last band if too small */ |
Jean-Marc Valin | 2ca8fc3 | 2008-02-18 16:27:49 +1100 | [diff] [blame] | 164 | /*for (i=0;i<*nbEBands+2;i++) |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 165 | printf("%d ", eBands[i]); |
Jean-Marc Valin | f61be66 | 2008-09-22 10:46:55 -0400 | [diff] [blame] | 166 | printf ("\n"); |
| 167 | exit(1);*/ |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 168 | return eBands; |
| 169 | } |
| 170 | |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 171 | static void compute_pbands(CELTMode *mode, int res) |
| 172 | { |
| 173 | int i; |
Jean-Marc Valin | db0141e | 2008-03-10 16:37:37 +1100 | [diff] [blame] | 174 | celt_int16_t *pBands; |
| 175 | pBands=celt_alloc(sizeof(celt_int16_t)*(PBANDS+2)); |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 176 | mode->nbPBands = PBANDS; |
| 177 | for (i=0;i<PBANDS+1;i++) |
| 178 | { |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 179 | pBands[i] = (pitch_freq[i]+res/2)/res; |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 180 | if (pBands[i] < mode->eBands[i]) |
| 181 | pBands[i] = mode->eBands[i]; |
| 182 | } |
| 183 | pBands[PBANDS+1] = mode->eBands[mode->nbEBands+1]; |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 184 | for (i=1;i<mode->nbPBands+1;i++) |
| 185 | { |
| 186 | int j; |
| 187 | for (j=0;j<mode->nbEBands;j++) |
| 188 | if (mode->eBands[j] <= pBands[i] && mode->eBands[j+1] > pBands[i]) |
| 189 | break; |
Jean-Marc Valin | a85657b | 2008-02-20 11:59:30 +1100 | [diff] [blame] | 190 | /*printf ("%d %d\n", i, j);*/ |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 191 | if (mode->eBands[j] != pBands[i]) |
| 192 | { |
| 193 | if (pBands[i]-mode->eBands[j] < mode->eBands[j+1]-pBands[i] && |
| 194 | mode->eBands[j] != pBands[i-1]) |
| 195 | pBands[i] = mode->eBands[j]; |
| 196 | else |
| 197 | pBands[i] = mode->eBands[j+1]; |
| 198 | } |
| 199 | } |
Jean-Marc Valin | 2ca8fc3 | 2008-02-18 16:27:49 +1100 | [diff] [blame] | 200 | /*for (i=0;i<mode->nbPBands+2;i++) |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 201 | printf("%d ", pBands[i]); |
Jean-Marc Valin | 2ca8fc3 | 2008-02-18 16:27:49 +1100 | [diff] [blame] | 202 | printf ("\n");*/ |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 203 | mode->pBands = pBands; |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 204 | mode->pitchEnd = pBands[PBANDS]; |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 205 | } |
| 206 | |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 207 | static void compute_allocation_table(CELTMode *mode, int res) |
| 208 | { |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 209 | int i, j, eband, nBark; |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 210 | celt_int16_t *allocVectors, *allocEnergy; |
| 211 | const int C = CHANNELS(mode); |
| 212 | |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 213 | /* Find the number of critical bands supported by our sampling rate */ |
| 214 | for (nBark=1;nBark<BARK_BANDS;nBark++) |
| 215 | if (bark_freq[nBark+1]*2 >= mode->Fs) |
| 216 | break; |
| 217 | |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 218 | mode->nbAllocVectors = BITALLOC_SIZE; |
Jean-Marc Valin | db0141e | 2008-03-10 16:37:37 +1100 | [diff] [blame] | 219 | allocVectors = celt_alloc(sizeof(celt_int16_t)*(BITALLOC_SIZE*mode->nbEBands)); |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 220 | allocEnergy = celt_alloc(sizeof(celt_int16_t)*(mode->nbAllocVectors*(mode->nbEBands+1))); |
| 221 | /* Compute per-codec-band allocation from per-critical-band matrix */ |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 222 | for (i=0;i<BITALLOC_SIZE;i++) |
| 223 | { |
| 224 | eband = 0; |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 225 | for (j=0;j<nBark;j++) |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 226 | { |
Jean-Marc Valin | 5c0d486 | 2008-07-24 08:49:34 -0400 | [diff] [blame] | 227 | int edge, low; |
| 228 | celt_int32_t alloc; |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 229 | edge = mode->eBands[eband+1]*res; |
Jean-Marc Valin | 13294b5 | 2008-05-30 16:07:06 +1000 | [diff] [blame] | 230 | alloc = band_allocation[i*BARK_BANDS+j]; |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 231 | alloc = alloc*C*mode->mdctSize/256; |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 232 | if (edge < bark_freq[j+1]) |
| 233 | { |
| 234 | int num, den; |
Jean-Marc Valin | 13294b5 | 2008-05-30 16:07:06 +1000 | [diff] [blame] | 235 | num = alloc * (edge-bark_freq[j]); |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 236 | den = bark_freq[j+1]-bark_freq[j]; |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 237 | low = (num+den/2)/den; |
| 238 | allocVectors[i*mode->nbEBands+eband] += low; |
| 239 | eband++; |
Jean-Marc Valin | 13294b5 | 2008-05-30 16:07:06 +1000 | [diff] [blame] | 240 | allocVectors[i*mode->nbEBands+eband] += alloc-low; |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 241 | } else { |
Jean-Marc Valin | 13294b5 | 2008-05-30 16:07:06 +1000 | [diff] [blame] | 242 | allocVectors[i*mode->nbEBands+eband] += alloc; |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 246 | /* Compute fine energy resolution and update the pulse allocation table to subtract that */ |
Jean-Marc Valin | ad63719 | 2008-05-07 13:44:39 +1000 | [diff] [blame] | 247 | for (i=0;i<mode->nbAllocVectors;i++) |
| 248 | { |
| 249 | int sum = 0; |
Jean-Marc Valin | ad63719 | 2008-05-07 13:44:39 +1000 | [diff] [blame] | 250 | for (j=0;j<mode->nbEBands;j++) |
| 251 | { |
Jean-Marc Valin | 9c70906 | 2008-08-03 22:07:06 -0400 | [diff] [blame] | 252 | int ebits; |
| 253 | int min_bits=0; |
Jean-Marc Valin | 504f8c2 | 2008-08-05 20:39:53 -0400 | [diff] [blame] | 254 | if (allocVectors[i*mode->nbEBands+j] > 0) |
Jean-Marc Valin | 9c70906 | 2008-08-03 22:07:06 -0400 | [diff] [blame] | 255 | min_bits = 1; |
Jean-Marc Valin | c24b518 | 2008-09-19 16:49:26 -0400 | [diff] [blame] | 256 | ebits = IMAX(min_bits , allocVectors[i*mode->nbEBands+j] / (C*(mode->eBands[j+1]-mode->eBands[j]))); |
Jean-Marc Valin | 504f8c2 | 2008-08-05 20:39:53 -0400 | [diff] [blame] | 257 | if (ebits>7) |
| 258 | ebits=7; |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 259 | /* The bits used for fine allocation can't be used for pulses */ |
Jean-Marc Valin | 9c70906 | 2008-08-03 22:07:06 -0400 | [diff] [blame] | 260 | /* However, we give two "free" bits to all modes to compensate for the fact that some energy |
| 261 | resolution is needed regardless of the frame size. */ |
| 262 | if (ebits>1) |
| 263 | allocVectors[i*mode->nbEBands+j] -= C*(ebits-2); |
Jean-Marc Valin | 504f8c2 | 2008-08-05 20:39:53 -0400 | [diff] [blame] | 264 | if (allocVectors[i*mode->nbEBands+j] < 0) |
| 265 | allocVectors[i*mode->nbEBands+j] = 0; |
Jean-Marc Valin | 9c70906 | 2008-08-03 22:07:06 -0400 | [diff] [blame] | 266 | sum += ebits; |
| 267 | allocEnergy[i*(mode->nbEBands+1)+j] = ebits; |
Jean-Marc Valin | ad63719 | 2008-05-07 13:44:39 +1000 | [diff] [blame] | 268 | } |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 269 | allocEnergy[i*(mode->nbEBands+1)+mode->nbEBands] = sum; |
Jean-Marc Valin | ad63719 | 2008-05-07 13:44:39 +1000 | [diff] [blame] | 270 | } |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 271 | mode->energy_alloc = allocEnergy; |
| 272 | mode->allocVectors = allocVectors; |
Jean-Marc Valin | ad63719 | 2008-05-07 13:44:39 +1000 | [diff] [blame] | 273 | } |
| 274 | |
Jean-Marc Valin | 36e6e01 | 2008-08-02 22:25:19 -0400 | [diff] [blame] | 275 | #endif /* STATIC_MODES */ |
| 276 | |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 277 | CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *error) |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 278 | { |
Jean-Marc Valin | 47c248a | 2008-04-26 08:16:12 +1000 | [diff] [blame] | 279 | int i; |
| 280 | #ifdef STDIN_TUNING |
| 281 | scanf("%d ", &MIN_BINS); |
| 282 | scanf("%d ", &BITALLOC_SIZE); |
| 283 | band_allocation = celt_alloc(sizeof(int)*BARK_BANDS*BITALLOC_SIZE); |
| 284 | for (i=0;i<BARK_BANDS*BITALLOC_SIZE;i++) |
| 285 | { |
| 286 | scanf("%d ", band_allocation+i); |
| 287 | } |
| 288 | #endif |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 289 | #ifdef STATIC_MODES |
Jean-Marc Valin | 949902f | 2008-03-11 10:43:06 +1100 | [diff] [blame] | 290 | const CELTMode *m = NULL; |
| 291 | CELTMode *mode=NULL; |
Jean-Marc Valin | f7cec83 | 2008-04-18 17:29:56 +1000 | [diff] [blame] | 292 | ALLOC_STACK; |
Jean-Marc Valin | 680a9ec | 2008-03-10 14:52:18 +1100 | [diff] [blame] | 293 | for (i=0;i<TOTAL_MODES;i++) |
| 294 | { |
| 295 | if (Fs == static_mode_list[i]->Fs && |
| 296 | channels == static_mode_list[i]->nbChannels && |
Jean-Marc Valin | 60d0837 | 2008-10-03 07:30:08 -0400 | [diff] [blame] | 297 | frame_size == static_mode_list[i]->mdctSize) |
Jean-Marc Valin | 680a9ec | 2008-03-10 14:52:18 +1100 | [diff] [blame] | 298 | { |
Jean-Marc Valin | 949902f | 2008-03-11 10:43:06 +1100 | [diff] [blame] | 299 | m = static_mode_list[i]; |
Jean-Marc Valin | 680a9ec | 2008-03-10 14:52:18 +1100 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | } |
Jean-Marc Valin | 949902f | 2008-03-11 10:43:06 +1100 | [diff] [blame] | 303 | if (m == NULL) |
Jean-Marc Valin | 680a9ec | 2008-03-10 14:52:18 +1100 | [diff] [blame] | 304 | { |
| 305 | celt_warning("Mode not included as part of the static modes"); |
| 306 | if (error) |
| 307 | *error = CELT_BAD_ARG; |
| 308 | return NULL; |
| 309 | } |
Jean-Marc Valin | 949902f | 2008-03-11 10:43:06 +1100 | [diff] [blame] | 310 | mode = (CELTMode*)celt_alloc(sizeof(CELTMode)); |
| 311 | CELT_COPY(mode, m, 1); |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 312 | #else |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 313 | int res; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 314 | CELTMode *mode; |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 315 | celt_word16_t *window; |
Jean-Marc Valin | f7cec83 | 2008-04-18 17:29:56 +1000 | [diff] [blame] | 316 | ALLOC_STACK; |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 317 | |
Jean-Marc Valin | 75e9c86 | 2008-02-18 17:04:15 +1100 | [diff] [blame] | 318 | /* The good thing here is that permutation of the arguments will automatically be invalid */ |
| 319 | |
| 320 | if (Fs < 32000 || Fs > 64000) |
| 321 | { |
| 322 | celt_warning("Sampling rate must be between 32 kHz and 64 kHz"); |
| 323 | if (error) |
| 324 | *error = CELT_BAD_ARG; |
| 325 | return NULL; |
| 326 | } |
| 327 | if (channels < 0 || channels > 2) |
| 328 | { |
| 329 | celt_warning("Only mono and stereo supported"); |
| 330 | if (error) |
| 331 | *error = CELT_BAD_ARG; |
| 332 | return NULL; |
| 333 | } |
Jean-Marc Valin | 96748cf | 2008-06-06 17:04:07 +1000 | [diff] [blame] | 334 | if (frame_size < 64 || frame_size > 512 || frame_size%2!=0) |
Jean-Marc Valin | 75e9c86 | 2008-02-18 17:04:15 +1100 | [diff] [blame] | 335 | { |
Gregory Maxwell | cbaf67e | 2008-09-28 04:19:19 -0400 | [diff] [blame] | 336 | celt_warning("Only even frame sizes from 64 to 512 are supported"); |
Jean-Marc Valin | 75e9c86 | 2008-02-18 17:04:15 +1100 | [diff] [blame] | 337 | if (error) |
| 338 | *error = CELT_BAD_ARG; |
| 339 | return NULL; |
| 340 | } |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 341 | res = (Fs+frame_size)/(2*frame_size); |
| 342 | |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 343 | mode = celt_alloc(sizeof(CELTMode)); |
Jean-Marc Valin | e6b7465 | 2008-02-20 18:01:08 +1100 | [diff] [blame] | 344 | mode->Fs = Fs; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 345 | mode->mdctSize = frame_size; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 346 | mode->nbChannels = channels; |
| 347 | mode->eBands = compute_ebands(Fs, frame_size, &mode->nbEBands); |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 348 | compute_pbands(mode, res); |
Jean-Marc Valin | 8b2a592 | 2008-02-29 00:32:51 +1100 | [diff] [blame] | 349 | mode->ePredCoef = QCONST16(.8f,15); |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 350 | |
| 351 | if (frame_size > 384 && (frame_size%8)==0) |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 352 | { |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 353 | mode->nbShortMdcts = 4; |
| 354 | } else if (frame_size > 384 && (frame_size%10)==0) |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 355 | { |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 356 | mode->nbShortMdcts = 5; |
| 357 | } else if (frame_size > 256 && (frame_size%6)==0) |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 358 | { |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 359 | mode->nbShortMdcts = 3; |
| 360 | } else if (frame_size > 256 && (frame_size%8)==0) |
| 361 | { |
| 362 | mode->nbShortMdcts = 4; |
| 363 | } else if (frame_size > 64 && (frame_size%4)==0) |
| 364 | { |
| 365 | mode->nbShortMdcts = 2; |
| 366 | } else if (frame_size > 128 && (frame_size%6)==0) |
| 367 | { |
| 368 | mode->nbShortMdcts = 3; |
| 369 | } else |
| 370 | { |
| 371 | mode->nbShortMdcts = 1; |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 372 | } |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 373 | |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 374 | if (mode->nbShortMdcts > 1) |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 375 | mode->overlap = ((frame_size/mode->nbShortMdcts)>>2)<<2; /* Overlap must be divisible by 4 */ |
Jean-Marc Valin | 16ca18b | 2008-06-18 23:44:48 +1000 | [diff] [blame] | 376 | else |
Gregory Maxwell | 23e654f | 2008-09-27 16:20:03 -0400 | [diff] [blame] | 377 | mode->overlap = (frame_size>>3)<<2; |
| 378 | |
Jean-Marc Valin | 9838fec | 2008-02-18 14:45:11 +1100 | [diff] [blame] | 379 | compute_allocation_table(mode, res); |
Jean-Marc Valin | a85657b | 2008-02-20 11:59:30 +1100 | [diff] [blame] | 380 | /*printf ("%d bands\n", mode->nbEBands);*/ |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 381 | |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 382 | window = (celt_word16_t*)celt_alloc(mode->overlap*sizeof(celt_word16_t)); |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 383 | |
Jean-Marc Valin | f28062f | 2008-03-03 13:24:01 +1100 | [diff] [blame] | 384 | #ifndef FIXED_POINT |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 385 | for (i=0;i<mode->overlap;i++) |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 386 | window[i] = Q15ONE*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)); |
Jean-Marc Valin | f28062f | 2008-03-03 13:24:01 +1100 | [diff] [blame] | 387 | #else |
| 388 | for (i=0;i<mode->overlap;i++) |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 389 | window[i] = MIN32(32767,32768.*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap))); |
Jean-Marc Valin | f28062f | 2008-03-03 13:24:01 +1100 | [diff] [blame] | 390 | #endif |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 391 | mode->window = window; |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 392 | |
Jean-Marc Valin | bf2d648 | 2008-05-23 16:57:34 +1000 | [diff] [blame] | 393 | mode->bits = (const celt_int16_t **)compute_alloc_cache(mode, 1); |
Jean-Marc Valin | b0bef85 | 2008-10-02 23:52:46 -0400 | [diff] [blame] | 394 | if (mode->nbChannels>=2) |
| 395 | mode->bits_stereo = (const celt_int16_t **)compute_alloc_cache(mode, mode->nbChannels); |
Jean-Marc Valin | b76ee70 | 2008-03-10 15:42:35 +1100 | [diff] [blame] | 396 | |
Jean-Marc Valin | 70720a3 | 2008-04-19 21:39:26 +1000 | [diff] [blame] | 397 | #ifndef SHORTCUTS |
Jean-Marc Valin | 5588d52 | 2008-03-10 15:07:58 +1100 | [diff] [blame] | 398 | psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs); |
Jean-Marc Valin | 70720a3 | 2008-04-19 21:39:26 +1000 | [diff] [blame] | 399 | #endif |
| 400 | |
Jean-Marc Valin | 44ffd5a | 2008-02-22 00:39:25 +1100 | [diff] [blame] | 401 | mode->marker_start = MODEVALID; |
| 402 | mode->marker_end = MODEVALID; |
Jean-Marc Valin | b76ee70 | 2008-03-10 15:42:35 +1100 | [diff] [blame] | 403 | #endif /* !STATIC_MODES */ |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 404 | mdct_init(&mode->mdct, 2*mode->mdctSize); |
Jean-Marc Valin | 24c9cda | 2008-05-02 10:34:07 +1000 | [diff] [blame] | 405 | mode->fft = pitch_state_alloc(MAX_PERIOD); |
| 406 | |
Jean-Marc Valin | 9d1decd | 2008-06-17 13:28:13 +1000 | [diff] [blame] | 407 | mode->shortMdctSize = mode->mdctSize/mode->nbShortMdcts; |
| 408 | mdct_init(&mode->shortMdct, 2*mode->shortMdctSize); |
| 409 | mode->shortWindow = mode->window; |
| 410 | |
Jean-Marc Valin | 4ce9205 | 2008-04-23 13:42:10 +1000 | [diff] [blame] | 411 | mode->prob = quant_prob_alloc(mode); |
Jean-Marc Valin | bf2d648 | 2008-05-23 16:57:34 +1000 | [diff] [blame] | 412 | |
Jean-Marc Valin | 680a9ec | 2008-03-10 14:52:18 +1100 | [diff] [blame] | 413 | if (error) |
| 414 | *error = CELT_OK; |
Jean-Marc Valin | 4991a56 | 2008-02-18 13:37:40 +1100 | [diff] [blame] | 415 | return mode; |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 416 | } |
Jean-Marc Valin | 2a8c371 | 2008-02-18 12:16:41 +1100 | [diff] [blame] | 417 | |
Peter Kirk | 19f9dc9 | 2008-06-06 14:38:38 +0200 | [diff] [blame] | 418 | void celt_mode_destroy(CELTMode *mode) |
Jean-Marc Valin | 81a8295 | 2008-02-17 22:41:29 +1100 | [diff] [blame] | 419 | { |
Jean-Marc Valin | 5588d52 | 2008-03-10 15:07:58 +1100 | [diff] [blame] | 420 | #ifndef STATIC_MODES |
Jean-Marc Valin | 25358cd | 2008-02-19 12:21:32 +1100 | [diff] [blame] | 421 | int i; |
Jean-Marc Valin | db0141e | 2008-03-10 16:37:37 +1100 | [diff] [blame] | 422 | const celt_int16_t *prevPtr = NULL; |
Jean-Marc Valin | 25358cd | 2008-02-19 12:21:32 +1100 | [diff] [blame] | 423 | for (i=0;i<mode->nbEBands;i++) |
| 424 | { |
| 425 | if (mode->bits[i] != prevPtr) |
| 426 | { |
| 427 | prevPtr = mode->bits[i]; |
| 428 | celt_free((int*)mode->bits[i]); |
| 429 | } |
| 430 | } |
| 431 | celt_free((int**)mode->bits); |
Gregory Maxwell | b6a3b0c | 2008-10-03 17:12:44 -0400 | [diff] [blame] | 432 | if (mode->bits_stereo != NULL) |
| 433 | { |
| 434 | for (i=0;i<mode->nbEBands;i++) |
| 435 | { |
| 436 | if (mode->bits_stereo[i] != prevPtr) |
| 437 | { |
| 438 | prevPtr = mode->bits_stereo[i]; |
| 439 | celt_free((int*)mode->bits_stereo[i]); |
| 440 | } |
| 441 | } |
| 442 | celt_free((int**)mode->bits_stereo); |
| 443 | } |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 444 | if (check_mode(mode) != CELT_OK) |
| 445 | return; |
| 446 | celt_free((int*)mode->eBands); |
| 447 | celt_free((int*)mode->pBands); |
| 448 | celt_free((int*)mode->allocVectors); |
Jean-Marc Valin | 25ec9ac | 2008-10-04 22:37:11 -0400 | [diff] [blame] | 449 | celt_free((celt_int16_t *)mode->energy_alloc); |
| 450 | |
Jean-Marc Valin | 3dbc1d0 | 2008-03-08 15:21:24 +1100 | [diff] [blame] | 451 | celt_free((celt_word16_t*)mode->window); |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 452 | |
Jean-Marc Valin | 44ffd5a | 2008-02-22 00:39:25 +1100 | [diff] [blame] | 453 | mode->marker_start = MODEFREED; |
| 454 | mode->marker_end = MODEFREED; |
Jean-Marc Valin | 70720a3 | 2008-04-19 21:39:26 +1000 | [diff] [blame] | 455 | #ifndef SHORTCUTS |
Jean-Marc Valin | 5588d52 | 2008-03-10 15:07:58 +1100 | [diff] [blame] | 456 | psydecay_clear(&mode->psy); |
Jean-Marc Valin | f39e869 | 2008-03-10 12:13:23 +1100 | [diff] [blame] | 457 | #endif |
Jean-Marc Valin | 70720a3 | 2008-04-19 21:39:26 +1000 | [diff] [blame] | 458 | #endif |
Jean-Marc Valin | 9656ca0 | 2008-04-11 17:23:01 +1000 | [diff] [blame] | 459 | mdct_clear(&mode->mdct); |
Jean-Marc Valin | c994394 | 2008-08-30 00:55:07 -0400 | [diff] [blame] | 460 | mdct_clear(&mode->shortMdct); |
Jean-Marc Valin | 24c9cda | 2008-05-02 10:34:07 +1000 | [diff] [blame] | 461 | pitch_state_free(mode->fft); |
Jean-Marc Valin | 4ce9205 | 2008-04-23 13:42:10 +1000 | [diff] [blame] | 462 | quant_prob_free(mode->prob); |
Jean-Marc Valin | 949902f | 2008-03-11 10:43:06 +1100 | [diff] [blame] | 463 | celt_free((CELTMode *)mode); |
Jean-Marc Valin | 2ca8fc3 | 2008-02-18 16:27:49 +1100 | [diff] [blame] | 464 | } |
Jean-Marc Valin | 44ffd5a | 2008-02-22 00:39:25 +1100 | [diff] [blame] | 465 | |
| 466 | int check_mode(const CELTMode *mode) |
| 467 | { |
| 468 | if (mode->marker_start == MODEVALID && mode->marker_end == MODEVALID) |
| 469 | return CELT_OK; |
| 470 | if (mode->marker_start == MODEFREED || mode->marker_end == MODEFREED) |
| 471 | celt_warning("Using a mode that has already been freed"); |
| 472 | else |
| 473 | celt_warning("This is not a valid CELT mode"); |
| 474 | return CELT_INVALID_MODE; |
| 475 | } |