LCOV - code coverage report
Current view: directory - media/libvorbis/lib - vorbis_floor0.c (source / functions) Found Hit Coverage
Test: app.info Lines: 97 0 0.0 %
Date: 2012-06-02 Functions: 7 0 0.0 %

       1                 : /********************************************************************
       2                 :  *                                                                  *
       3                 :  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
       4                 :  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
       5                 :  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
       6                 :  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
       7                 :  *                                                                  *
       8                 :  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
       9                 :  * by the Xiph.Org Foundation http://www.xiph.org/                  *
      10                 :  *                                                                  *
      11                 :  ********************************************************************
      12                 : 
      13                 :  function: floor backend 0 implementation
      14                 :  last mod: $Id: floor0.c 17558 2010-10-22 00:24:41Z tterribe $
      15                 : 
      16                 :  ********************************************************************/
      17                 : 
      18                 : #include <stdlib.h>
      19                 : #include <string.h>
      20                 : #include <math.h>
      21                 : #include <ogg/ogg.h>
      22                 : #include "vorbis/codec.h"
      23                 : #include "codec_internal.h"
      24                 : #include "registry.h"
      25                 : #include "lpc.h"
      26                 : #include "lsp.h"
      27                 : #include "codebook.h"
      28                 : #include "scales.h"
      29                 : #include "misc.h"
      30                 : #include "os.h"
      31                 : 
      32                 : #include "misc.h"
      33                 : #include <stdio.h>
      34                 : 
      35                 : typedef struct {
      36                 :   int ln;
      37                 :   int  m;
      38                 :   int **linearmap;
      39                 :   int  n[2];
      40                 : 
      41                 :   vorbis_info_floor0 *vi;
      42                 : 
      43                 :   long bits;
      44                 :   long frames;
      45                 : } vorbis_look_floor0;
      46                 : 
      47                 : 
      48                 : /***********************************************/
      49                 : 
      50               0 : static void floor0_free_info(vorbis_info_floor *i){
      51               0 :   vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
      52               0 :   if(info){
      53               0 :     memset(info,0,sizeof(*info));
      54               0 :     _ogg_free(info);
      55                 :   }
      56               0 : }
      57                 : 
      58               0 : static void floor0_free_look(vorbis_look_floor *i){
      59               0 :   vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
      60               0 :   if(look){
      61                 : 
      62               0 :     if(look->linearmap){
      63                 : 
      64               0 :       if(look->linearmap[0])_ogg_free(look->linearmap[0]);
      65               0 :       if(look->linearmap[1])_ogg_free(look->linearmap[1]);
      66                 : 
      67               0 :       _ogg_free(look->linearmap);
      68                 :     }
      69               0 :     memset(look,0,sizeof(*look));
      70               0 :     _ogg_free(look);
      71                 :   }
      72               0 : }
      73                 : 
      74               0 : static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
      75               0 :   codec_setup_info     *ci=vi->codec_setup;
      76                 :   int j;
      77                 : 
      78               0 :   vorbis_info_floor0 *info=_ogg_malloc(sizeof(*info));
      79               0 :   info->order=oggpack_read(opb,8);
      80               0 :   info->rate=oggpack_read(opb,16);
      81               0 :   info->barkmap=oggpack_read(opb,16);
      82               0 :   info->ampbits=oggpack_read(opb,6);
      83               0 :   info->ampdB=oggpack_read(opb,8);
      84               0 :   info->numbooks=oggpack_read(opb,4)+1;
      85                 : 
      86               0 :   if(info->order<1)goto err_out;
      87               0 :   if(info->rate<1)goto err_out;
      88               0 :   if(info->barkmap<1)goto err_out;
      89               0 :   if(info->numbooks<1)goto err_out;
      90                 : 
      91               0 :   for(j=0;j<info->numbooks;j++){
      92               0 :     info->books[j]=oggpack_read(opb,8);
      93               0 :     if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
      94               0 :     if(ci->book_param[info->books[j]]->maptype==0)goto err_out;
      95               0 :     if(ci->book_param[info->books[j]]->dim<1)goto err_out;
      96                 :   }
      97               0 :   return(info);
      98                 : 
      99                 :  err_out:
     100               0 :   floor0_free_info(info);
     101               0 :   return(NULL);
     102                 : }
     103                 : 
     104                 : /* initialize Bark scale and normalization lookups.  We could do this
     105                 :    with static tables, but Vorbis allows a number of possible
     106                 :    combinations, so it's best to do it computationally.
     107                 : 
     108                 :    The below is authoritative in terms of defining scale mapping.
     109                 :    Note that the scale depends on the sampling rate as well as the
     110                 :    linear block and mapping sizes */
     111                 : 
     112               0 : static void floor0_map_lazy_init(vorbis_block      *vb,
     113                 :                                  vorbis_info_floor *infoX,
     114                 :                                  vorbis_look_floor0 *look){
     115               0 :   if(!look->linearmap[vb->W]){
     116               0 :     vorbis_dsp_state   *vd=vb->vd;
     117               0 :     vorbis_info        *vi=vd->vi;
     118               0 :     codec_setup_info   *ci=vi->codec_setup;
     119               0 :     vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
     120               0 :     int W=vb->W;
     121               0 :     int n=ci->blocksizes[W]/2,j;
     122                 : 
     123                 :     /* we choose a scaling constant so that:
     124                 :        floor(bark(rate/2-1)*C)=mapped-1
     125                 :      floor(bark(rate/2)*C)=mapped */
     126               0 :     float scale=look->ln/toBARK(info->rate/2.f);
     127                 : 
     128                 :     /* the mapping from a linear scale to a smaller bark scale is
     129                 :        straightforward.  We do *not* make sure that the linear mapping
     130                 :        does not skip bark-scale bins; the decoder simply skips them and
     131                 :        the encoder may do what it wishes in filling them.  They're
     132                 :        necessary in some mapping combinations to keep the scale spacing
     133                 :        accurate */
     134               0 :     look->linearmap[W]=_ogg_malloc((n+1)*sizeof(**look->linearmap));
     135               0 :     for(j=0;j<n;j++){
     136               0 :       int val=floor( toBARK((info->rate/2.f)/n*j)
     137                 :                      *scale); /* bark numbers represent band edges */
     138               0 :       if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
     139               0 :       look->linearmap[W][j]=val;
     140                 :     }
     141               0 :     look->linearmap[W][j]=-1;
     142               0 :     look->n[W]=n;
     143                 :   }
     144               0 : }
     145                 : 
     146               0 : static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
     147                 :                                       vorbis_info_floor *i){
     148               0 :   vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
     149               0 :   vorbis_look_floor0 *look=_ogg_calloc(1,sizeof(*look));
     150               0 :   look->m=info->order;
     151               0 :   look->ln=info->barkmap;
     152               0 :   look->vi=info;
     153                 : 
     154               0 :   look->linearmap=_ogg_calloc(2,sizeof(*look->linearmap));
     155                 : 
     156               0 :   return look;
     157                 : }
     158                 : 
     159               0 : static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
     160               0 :   vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
     161               0 :   vorbis_info_floor0 *info=look->vi;
     162                 :   int j,k;
     163                 : 
     164               0 :   int ampraw=oggpack_read(&vb->opb,info->ampbits);
     165               0 :   if(ampraw>0){ /* also handles the -1 out of data case */
     166               0 :     long maxval=(1<<info->ampbits)-1;
     167               0 :     float amp=(float)ampraw/maxval*info->ampdB;
     168               0 :     int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
     169                 : 
     170               0 :     if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
     171               0 :       codec_setup_info  *ci=vb->vd->vi->codec_setup;
     172               0 :       codebook *b=ci->fullbooks+info->books[booknum];
     173               0 :       float last=0.f;
     174                 : 
     175                 :       /* the additional b->dim is a guard against any possible stack
     176                 :          smash; b->dim is provably more than we can overflow the
     177                 :          vector */
     178               0 :       float *lsp=_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
     179                 : 
     180               0 :       for(j=0;j<look->m;j+=b->dim)
     181               0 :         if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
     182               0 :       for(j=0;j<look->m;){
     183               0 :         for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
     184               0 :         last=lsp[j-1];
     185                 :       }
     186                 : 
     187               0 :       lsp[look->m]=amp;
     188               0 :       return(lsp);
     189                 :     }
     190                 :   }
     191                 :  eop:
     192               0 :   return(NULL);
     193                 : }
     194                 : 
     195               0 : static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
     196                 :                            void *memo,float *out){
     197               0 :   vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
     198               0 :   vorbis_info_floor0 *info=look->vi;
     199                 : 
     200               0 :   floor0_map_lazy_init(vb,info,look);
     201                 : 
     202               0 :   if(memo){
     203               0 :     float *lsp=(float *)memo;
     204               0 :     float amp=lsp[look->m];
     205                 : 
     206                 :     /* take the coefficients back to a spectral envelope curve */
     207               0 :     vorbis_lsp_to_curve(out,
     208               0 :                         look->linearmap[vb->W],
     209               0 :                         look->n[vb->W],
     210                 :                         look->ln,
     211               0 :                         lsp,look->m,amp,(float)info->ampdB);
     212               0 :     return(1);
     213                 :   }
     214               0 :   memset(out,0,sizeof(*out)*look->n[vb->W]);
     215               0 :   return(0);
     216                 : }
     217                 : 
     218                 : /* export hooks */
     219                 : const vorbis_func_floor floor0_exportbundle={
     220                 :   NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
     221                 :   &floor0_free_look,&floor0_inverse1,&floor0_inverse2
     222                 : };

Generated by: LCOV version 1.7