]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/qcelpdata.h
VP3: Do not ignore error from read_huffman_tree().
[ffmpeg] / libavcodec / qcelpdata.h
index b50e030ade98a2374baed8a91ff297813a0eb1bb..0ab0be1c9fd604e2d0a02f9c10deb66d57ac7222 100644 (file)
 #define AVCODEC_QCELPDATA_H
 
 /**
- * @file qcelpdata.h
+ * @file libavcodec/qcelpdata.h
  * Data tables for the QCELP decoder
  * @author Reynaldo H. Verdejo Pinochet
  * @remark FFmpeg merging spearheaded by Kenan Gillet
+ * @remark Development mentored by Benjamin Larson
  */
 
+#include <stddef.h>
 #include <stdint.h>
+#include "libavutil/common.h"
+
+/**
+ * QCELP unpacked data frame
+ */
+typedef struct {
+/// @defgroup qcelp_codebook_parameters QCELP excitation codebook parameters
+/// @{
+    uint8_t cbsign[16]; ///!< sign of the codebook gain for each codebook subframe
+    uint8_t cbgain[16]; ///!< unsigned codebook gain for each codebook subframe
+    uint8_t cindex[16]; ///!< codebook index for each codebook subframe
+/// @}
+
+/// @defgroup qcelp_pitch_parameters QCELP pitch prediction parameters
+/// @{
+    uint8_t plag[4];    ///!< pitch lag for each pitch subframe
+    uint8_t pfrac[4];   ///!< fractional pitch lag for each pitch subframe
+    uint8_t pgain[4];   ///!< pitch gain for each pitch subframe
+/// @}
+
+    /**
+     * line spectral pair frequencies (LSP) for RATE_OCTAVE,
+     * line spectral pair frequencies grouped into five vectors
+     * of dimension two (LSPV) for other rates
+     */
+    uint8_t lspv[10];
+
+    /**
+     * reserved bits only present in bitrate 1, 1/4 and 1/8 packets
+     */
+    uint8_t reserved;
+} QCELPFrame;
 
 /**
  * pre-calculated table for hammsinc function
@@ -45,7 +79,7 @@ typedef struct {
     uint8_t bitlen; /*!< number of bits to read */
 } QCELPBitmap;
 
-#define QCELP_OF(variable, bit, len) {offsetof(QCELPContext, variable), bit, len}
+#define QCELP_OF(variable, bit, len) {offsetof(QCELPFrame, variable), bit, len}
 
 /**
  * bitmap unpacking tables for RATE_FULL
@@ -239,7 +273,7 @@ static const QCELPBitmap * const qcelp_unpacking_bitmaps_per_rate[5] = {
     qcelp_rate_full_bitmap,
 };
 
-static const uint16_t qcelp_bits_per_rate[5] = {
+static const uint16_t qcelp_unpacking_bitmaps_lengths[5] = {
     0, ///!< for SILENCE rate
     FF_ARRAY_ELEMS(qcelp_rate_octave_bitmap),
     FF_ARRAY_ELEMS(qcelp_rate_quarter_bitmap),
@@ -390,6 +424,16 @@ static const qcelp_vector * const qcelp_lspvq[5] = {
  */
 #define QCELP_SCALE 8192.
 
+/**
+ * the upper boundary of the clipping, depends on QCELP_SCALE
+ */
+#define QCELP_CLIP_UPPER_BOUND (8191.75/8192.)
+
+/**
+ * the lower boundary of the clipping, depends on QCELP_SCALE
+ */
+#define QCELP_CLIP_LOWER_BOUND -1.
+
 /**
  * table for computing Ga (decoded linear codebook gain magnitude)
  *
@@ -470,7 +514,7 @@ static const int8_t qcelp_rate_half_codebook[128] = {
 /**
  * sqrt(1.887) is the maximum of the pseudorandom
  * white sequence used to generate the scaled codebook
- * vector for framerate 1/4.
+ * vector for bitrate 1/4.
  *
  * TIA/EIA/IS-733 2.4.8.1.2
  */
@@ -478,9 +522,9 @@ static const int8_t qcelp_rate_half_codebook[128] = {
 
 /**
  * table for impulse response of BPF used to filter
- * the white excitation for framerate 1/4 synthesis
+ * the white excitation for bitrate 1/4 synthesis
  *
- * Only half the tables are needed because of symetry.
+ * Only half the tables are needed because of symmetry.
  *
  * TIA/EIA/IS-733 2.4.8.1.2-1.1
  */
@@ -490,4 +534,20 @@ static const double qcelp_rnd_fir_coefs[11] = {
   -9.918777e-2, 3.749518e-2,  8.985137e-1
 };
 
+/**
+ * This spread factor is used, for bitrate 1/8 and I_F_Q,
+ * to force the LSP frequencies to be at least 80 Hz apart.
+ *
+ * TIA/EIA/IS-733 2.4.3.3.2
+ */
+#define QCELP_LSP_SPREAD_FACTOR 0.02
+
+/**
+ * predictor coefficient for the conversion of LSP codes
+ * to LSP frequencies for 1/8 and I_F_Q
+ *
+ * TIA/EIA/IS-733 2.4.3.2.7-2
+ */
+#define QCELP_LSP_OCTAVE_PREDICTOR 29.0/32
+
 #endif /* AVCODEC_QCELPDATA_H */