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 | Written by Jean-Marc Valin */ |
Jean-Marc Valin | 276de72 | 2008-02-20 17:45:51 +1100 | [diff] [blame] | 4 | /** |
| 5 | @file vq.h |
| 6 | @brief Vector quantisation of the residual |
| 7 | */ |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 8 | /* |
| 9 | Redistribution and use in source and binary forms, with or without |
| 10 | modification, are permitted provided that the following conditions |
| 11 | are met: |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 12 | |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 13 | - Redistributions of source code must retain the above copyright |
| 14 | notice, this list of conditions and the following disclaimer. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 15 | |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 16 | - Redistributions in binary form must reproduce the above copyright |
| 17 | notice, this list of conditions and the following disclaimer in the |
| 18 | documentation and/or other materials provided with the distribution. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 19 | |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Jean-Marc Valin | cb05e7c | 2012-04-20 16:40:24 -0400 | [diff] [blame] | 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #ifndef VQ_H |
| 34 | #define VQ_H |
| 35 | |
Jean-Marc Valin | 9cace64 | 2007-12-06 17:44:09 +1100 | [diff] [blame] | 36 | #include "entenc.h" |
Jean-Marc Valin | fc08d0a | 2007-12-07 13:26:15 +1100 | [diff] [blame] | 37 | #include "entdec.h" |
Jean-Marc Valin | ba11d78 | 2008-04-21 21:59:37 +1000 | [diff] [blame] | 38 | #include "modes.h" |
Jean-Marc Valin | 9cace64 | 2007-12-06 17:44:09 +1100 | [diff] [blame] | 39 | |
Jean-Marc Valin | 76674fe | 2016-08-09 23:22:27 -0400 | [diff] [blame] | 40 | #if (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(FIXED_POINT)) |
| 41 | #include "x86/vq_sse.h" |
| 42 | #endif |
| 43 | |
Rhishikesh Agashe | c9c2035 | 2015-10-07 13:55:12 -0400 | [diff] [blame] | 44 | #if defined(MIPSr1_ASM) |
| 45 | #include "mips/vq_mipsr1.h" |
| 46 | #endif |
| 47 | |
Jean-Marc Valin | 76674fe | 2016-08-09 23:22:27 -0400 | [diff] [blame] | 48 | opus_val16 op_pvq_search_c(celt_norm *X, int *iy, int K, int N, int arch); |
| 49 | |
| 50 | #if !defined(OVERRIDE_OP_PVQ_SEARCH) |
| 51 | #define op_pvq_search(x, iy, K, N, arch) \ |
| 52 | (op_pvq_search_c(x, iy, K, N, arch)) |
| 53 | #endif |
Rhishikesh Agashe | c9c2035 | 2015-10-07 13:55:12 -0400 | [diff] [blame] | 54 | |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 55 | /** Algebraic pulse-vector quantiser. The signal x is replaced by the sum of |
| 56 | * the pitch and a combination of pulses such that its norm is still equal |
| 57 | * to 1. This is the function that will typically require the most CPU. |
Jean-Marc Valin | f55b0ea | 2013-03-07 18:13:19 -0500 | [diff] [blame] | 58 | * @param X Residual signal to quantise/encode (returns quantised version) |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 59 | * @param N Number of samples to encode |
| 60 | * @param K Number of pulses to use |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 61 | * @param enc Entropy encoder state |
Timothy B. Terriberry | 21af73e | 2011-01-19 16:30:03 -0800 | [diff] [blame] | 62 | * @ret A mask indicating which blocks in the band received pulses |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 63 | */ |
Jean-Marc Valin | 9eee106 | 2016-01-04 23:29:36 -0500 | [diff] [blame] | 64 | unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc, |
Jean-Marc Valin | 76674fe | 2016-08-09 23:22:27 -0400 | [diff] [blame] | 65 | opus_val16 gain, int resynth, int arch); |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 66 | |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 67 | /** Algebraic pulse decoder |
Jean-Marc Valin | f55b0ea | 2013-03-07 18:13:19 -0500 | [diff] [blame] | 68 | * @param X Decoded normalised spectrum (returned) |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 69 | * @param N Number of samples to decode |
| 70 | * @param K Number of pulses to use |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 71 | * @param dec Entropy decoder state |
Timothy B. Terriberry | 21af73e | 2011-01-19 16:30:03 -0800 | [diff] [blame] | 72 | * @ret A mask indicating which blocks in the band received pulses |
Jean-Marc Valin | 26c9e14 | 2007-12-31 21:27:54 +1100 | [diff] [blame] | 73 | */ |
Timothy B. Terriberry | 21af73e | 2011-01-19 16:30:03 -0800 | [diff] [blame] | 74 | unsigned alg_unquant(celt_norm *X, int N, int K, int spread, int B, |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 75 | ec_dec *dec, opus_val16 gain); |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 76 | |
xiangmingzhu | c95c9a0 | 2014-04-30 15:48:07 +0800 | [diff] [blame] | 77 | void renormalise_vector(celt_norm *X, int N, opus_val16 gain, int arch); |
Jean-Marc Valin | eea914c | 2010-09-12 20:11:32 -0400 | [diff] [blame] | 78 | |
xiangmingzhu | c95c9a0 | 2014-04-30 15:48:07 +0800 | [diff] [blame] | 79 | int stereo_itheta(const celt_norm *X, const celt_norm *Y, int stereo, int N, int arch); |
Jean-Marc Valin | 1d27ef8 | 2008-07-20 23:30:29 -0400 | [diff] [blame] | 80 | |
Jean-Marc Valin | 41af421 | 2007-11-30 18:35:37 +1100 | [diff] [blame] | 81 | #endif /* VQ_H */ |