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.2 2000/01/22 13:28:19 xiphmont Exp $
17 ********************************************************************/
21 #include "vorbis/codec.h"
25 static void pack (vorbis_info_floor *i,oggpack_buffer *opb){
26 vorbis_info_floor0 *d=(vorbis_info_floor0 *)i;
28 _oggpack_write(opb,d->order,8);
29 _oggpack_write(opb,d->rate,16);
30 _oggpack_write(opb,d->barkmap,16);
31 _oggpack_write(opb,d->stages,8);
32 for(j=0;j<d->stages;j++)
33 _oggpack_write(opb,d->books[j],8);
36 static vorbis_info_floor *unpack (vorbis_info *vi,oggpack_buffer *opb){
38 vorbis_info_floor0 *d=malloc(sizeof(vorbis_info_floor0));
39 d->order=_oggpack_read(opb,8);
40 d->rate=_oggpack_read(opb,16);
41 d->barkmap=_oggpack_read(opb,16);
42 d->stages=_oggpack_read(opb,8);
44 if(d->order<1)goto err_out;
45 if(d->rate<1)goto err_out;
46 if(d->barkmap<1)goto err_out;
47 if(d->stages<1)goto err_out;
49 d->books=alloca(sizeof(int)*d->stages);
50 for(j=0;j<d->stages;j++){
51 d->books[j]=_oggpack_read(opb,8);
52 if(d->books[j]<0 || d->books[j]>=vi->books)goto err_out;
60 static vorbis_look_floor *look (vorbis_info *vi,vorbis_info_mode *mi,
61 vorbis_info_floor *i){
64 static void free_info(vorbis_info_floor *i){
65 vorbis_info_floor0 *d=(vorbis_info_floor0 *)i;
67 if(d->books)free(d->books);
68 memset(i,0,sizeof(vorbis_info_floor0));
71 static void free_look(vorbis_look_floor *i){
74 static void forward(vorbis_block *vb,vorbis_look_floor *i,
75 double *in,double *out){
78 /* Convert our floor to a set of lpc coefficients
79 vb->amp[i]=sqrt(vorbis_curve_to_lpc(floor,lpc,vl));
81 LSP <-> LPC is orthogonal and LSP quantizes more stably
82 vorbis_lpc_to_lsp(lpc,lsp,vl->m);
84 code the spectral envelope; mutates the lsp coeffs to reflect
85 what was actually encoded
86 _vs_spectrum_encode(vb,vb->amp[i],lsp);
88 Generate residue from the decoded envelope, which will be
89 slightly different to the pre-encoding floor due to
90 quantization. Slow, yes, but perhaps more accurate
92 vorbis_lsp_to_lpc(lsp,lpc,vl->m);
93 vorbis_lpc_to_curve(curve,lpc,vb->amp[i],vl);*/
96 static void inverse(vorbis_block *vb,vorbis_look_floor *i,
97 double *in,double *out){
102 vorbis_func_floor floor0_exportbundle={
103 &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse