1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: floor backend 0 implementation
15 last mod: $Id: floor0.c,v 1.5 2000/01/28 14:34:43 xiphmont Exp $
17 ********************************************************************/
21 #include "vorbis/codec.h"
25 static void free_info(vorbis_info_floor *i){
27 memset(i,0,sizeof(vorbis_info_floor0));
31 static void free_look(vorbis_look_floor *i){
34 static void pack (vorbis_info_floor *i,oggpack_buffer *opb){
35 vorbis_info_floor0 *d=(vorbis_info_floor0 *)i;
37 _oggpack_write(opb,d->order,8);
38 _oggpack_write(opb,d->rate,16);
39 _oggpack_write(opb,d->barkmap,16);
40 _oggpack_write(opb,d->stages-1,4);
41 for(j=0;j<d->stages;j++)
42 _oggpack_write(opb,d->books[j],8);
45 static vorbis_info_floor *unpack (vorbis_info *vi,oggpack_buffer *opb){
47 vorbis_info_floor0 *d=malloc(sizeof(vorbis_info_floor0));
48 d->order=_oggpack_read(opb,8);
49 d->rate=_oggpack_read(opb,16);
50 d->barkmap=_oggpack_read(opb,16);
51 d->stages=_oggpack_read(opb,4)+1;
53 if(d->order<1)goto err_out;
54 if(d->rate<1)goto err_out;
55 if(d->barkmap<1)goto err_out;
56 if(d->stages<1)goto err_out;
58 for(j=0;j<d->stages;j++){
59 d->books[j]=_oggpack_read(opb,8);
60 if(d->books[j]<0 || d->books[j]>=vi->books)goto err_out;
68 static vorbis_look_floor *look (vorbis_info *vi,vorbis_info_mode *mi,
69 vorbis_info_floor *i){
73 static int forward(vorbis_block *vb,vorbis_look_floor *i,
74 double *in,double *out){
77 /* Convert our floor to a set of lpc coefficients
78 vb->amp[i]=sqrt(vorbis_curve_to_lpc(floor,lpc,vl));
80 LSP <-> LPC is orthogonal and LSP quantizes more stably
81 vorbis_lpc_to_lsp(lpc,lsp,vl->m);
83 code the spectral envelope; mutates the lsp coeffs to reflect
84 what was actually encoded
85 _vs_spectrum_encode(vb,vb->amp[i],lsp);
87 Generate residue from the decoded envelope, which will be
88 slightly different to the pre-encoding floor due to
89 quantization. Slow, yes, but perhaps more accurate
91 vorbis_lsp_to_lpc(lsp,lpc,vl->m);
92 vorbis_lpc_to_curve(curve,lpc,vb->amp[i],vl);*/
95 static int inverse(vorbis_block *vb,vorbis_look_floor *i,
101 vorbis_func_floor floor0_exportbundle={
102 &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse