FLAC的subframe,有一种格式是LPC的,在文件中的格式如下:
(链接地址:https://xiph.org/flac/format.html#subframe_lpc)
<n> | Unencoded warm-up samples (n = frame's bits-per-sample * lpc order). |
<4> | (Quantized linear predictor coefficients' precision in bits)-1 (1111 = invalid). |
<5> | Quantized linear predictor coefficient shift needed in bits (NOTE: this number is signed two's-complement). |
<n> | Unencoded predictor coefficients (n = qlp coeff precision * lpc order) (NOTE: the coefficients are signed two's-complement). |
RESIDUAL | Encoded residual |
第一行:表示不做LPC编码的sample,这些sample都保存在这个位置。sample的个数等于LPC的阶数,每个sample用bits-per-sample个bits表示。
所以,这里一共用了 bits-per-sample * lpc order 这么多bits
第二行:用来表示后面的LPC系数用多少个bits来存储的。在代码中称为precision。在第四行那里存储的系数,每个系数就是用了precision个bits.
第三行:是做完LPC计算后,右移多少位,称之为shift,简称为s
第四行:存储的是系数,每个系数用precision个bits存储的。记为 a[0], a[1], ..... a[order-1]
第五行:是预测后剩余的residual,记为R.
最后恢复每个sample用如下公式:
X[n+1] = R[n+1] + ( a[0] * X[n] + a[1] * X[n-1] + ....... + a[order-1] * X[n-order+1] ) >> S
参考代码如下:
for(i = 0; i < data_len; i++) {
sum = 0;
history = data;
for(j = 0; j < order; j++) {
sum += qlp_coeff[j] * (*(--history));
}
*(data++) = *(residual++) + (sum >> lp_quantization);
}