misc/libtremor/tremor/block.c
author nemo
Fri, 29 Mar 2013 10:54:12 -0400
changeset 8818 8f317ba10675
parent 7859 519d5bc91dd3
permissions -rw-r--r--
This should ensure rope can still be aimed quickly when an alt weapon is active.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7859
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     1
/********************************************************************
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     2
 *                                                                  *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     3
 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE.   *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     4
 *                                                                  *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     5
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     6
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     7
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     8
 *                                                                  *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
     9
 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002    *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    10
 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    11
 *                                                                  *
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    12
 ********************************************************************
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    13
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    14
 function: PCM data vector blocking, windowing and dis/reassembly
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    15
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    16
 ********************************************************************/
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    17
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    18
#include <stdio.h>
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    19
#include <stdlib.h>
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    20
#include <string.h>
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    21
#include "ogg.h"
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    22
#include "ivorbiscodec.h"
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    23
#include "codec_internal.h"
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    24
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    25
#include "window.h"
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    26
#include "registry.h"
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    27
#include "misc.h"
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    28
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    29
static int ilog(unsigned int v){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    30
  int ret=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    31
  if(v)--v;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    32
  while(v){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    33
    ret++;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    34
    v>>=1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    35
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    36
  return(ret);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    37
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    38
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    39
/* pcm accumulator examples (not exhaustive):
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    40
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    41
 <-------------- lW ---------------->
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    42
                   <--------------- W ---------------->
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    43
:            .....|.....       _______________         |
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    44
:        .'''     |     '''_---      |       |\        |
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    45
:.....'''         |_____--- '''......|       | \_______|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    46
:.................|__________________|_______|__|______|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    47
                  |<------ Sl ------>|      > Sr <     |endW
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    48
                  |beginSl           |endSl  |  |endSr
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    49
                  |beginW            |endlW  |beginSr
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    50
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    51
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    52
                      |< lW >|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    53
                   <--------------- W ---------------->
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    54
                  |   |  ..  ______________            |
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    55
                  |   | '  `/        |     ---_        |
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    56
                  |___.'___/`.       |         ---_____|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    57
                  |_______|__|_______|_________________|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    58
                  |      >|Sl|<      |<------ Sr ----->|endW
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    59
                  |       |  |endSl  |beginSr          |endSr
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    60
                  |beginW |  |endlW
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    61
                  mult[0] |beginSl                     mult[n]
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    62
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    63
 <-------------- lW ----------------->
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    64
                          |<--W-->|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    65
:            ..............  ___  |   |
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    66
:        .'''             |`/   \ |   |
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    67
:.....'''                 |/`....\|...|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    68
:.........................|___|___|___|
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    69
                          |Sl |Sr |endW
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    70
                          |   |   |endSr
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    71
                          |   |beginSr
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    72
                          |   |endSl
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    73
			  |beginSl
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    74
			  |beginW
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    75
*/
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    76
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    77
/* block abstraction setup *********************************************/
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    78
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    79
#ifndef WORD_ALIGN
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    80
#define WORD_ALIGN 8
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    81
#endif
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    82
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    83
int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    84
  memset(vb,0,sizeof(*vb));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    85
  vb->vd=v;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    86
  vb->localalloc=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    87
  vb->localstore=NULL;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    88
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    89
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    90
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    91
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    92
void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    93
  bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    94
  if(bytes+vb->localtop>vb->localalloc){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    95
    /* can't just _ogg_realloc... there are outstanding pointers */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    96
    if(vb->localstore){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    97
      struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    98
      vb->totaluse+=vb->localtop;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
    99
      link->next=vb->reap;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   100
      link->ptr=vb->localstore;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   101
      vb->reap=link;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   102
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   103
    /* highly conservative */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   104
    vb->localalloc=bytes;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   105
    vb->localstore=_ogg_malloc(vb->localalloc);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   106
    vb->localtop=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   107
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   108
  {
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   109
    void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   110
    vb->localtop+=bytes;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   111
    return ret;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   112
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   113
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   114
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   115
/* reap the chain, pull the ripcord */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   116
void _vorbis_block_ripcord(vorbis_block *vb){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   117
  /* reap the chain */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   118
  struct alloc_chain *reap=vb->reap;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   119
  while(reap){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   120
    struct alloc_chain *next=reap->next;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   121
    _ogg_free(reap->ptr);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   122
    memset(reap,0,sizeof(*reap));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   123
    _ogg_free(reap);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   124
    reap=next;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   125
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   126
  /* consolidate storage */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   127
  if(vb->totaluse){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   128
    vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   129
    vb->localalloc+=vb->totaluse;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   130
    vb->totaluse=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   131
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   132
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   133
  /* pull the ripcord */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   134
  vb->localtop=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   135
  vb->reap=NULL;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   136
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   137
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   138
int vorbis_block_clear(vorbis_block *vb){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   139
  _vorbis_block_ripcord(vb);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   140
  if(vb->localstore)_ogg_free(vb->localstore);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   141
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   142
  memset(vb,0,sizeof(*vb));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   143
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   144
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   145
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   146
static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   147
  int i;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   148
  codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   149
  private_state *b=NULL;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   150
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   151
  memset(v,0,sizeof(*v));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   152
  b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   153
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   154
  v->vi=vi;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   155
  b->modebits=ilog(ci->modes);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   156
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   157
  /* Vorbis I uses only window type 0 */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   158
  b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   159
  b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   160
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   161
  /* finish the codebooks */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   162
  if(!ci->fullbooks){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   163
    ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   164
    for(i=0;i<ci->books;i++){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   165
      vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   166
      /* decode codebooks are now standalone after init */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   167
      vorbis_staticbook_destroy(ci->book_param[i]);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   168
      ci->book_param[i]=NULL;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   169
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   170
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   171
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   172
  v->pcm_storage=ci->blocksizes[1];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   173
  v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   174
  v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   175
  for(i=0;i<vi->channels;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   176
    v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   177
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   178
  /* all 1 (large block) or 0 (small block) */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   179
  /* explicitly set for the sake of clarity */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   180
  v->lW=0; /* previous window size */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   181
  v->W=0;  /* current window size */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   182
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   183
  /* initialize all the mapping/backend lookups */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   184
  b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   185
  for(i=0;i<ci->modes;i++){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   186
    int mapnum=ci->mode_param[i]->mapping;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   187
    int maptype=ci->map_type[mapnum];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   188
    b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   189
					 ci->map_param[mapnum]);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   190
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   191
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   192
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   193
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   194
int vorbis_synthesis_restart(vorbis_dsp_state *v){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   195
  vorbis_info *vi=v->vi;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   196
  codec_setup_info *ci;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   197
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   198
  if(!v->backend_state)return -1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   199
  if(!vi)return -1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   200
  ci=vi->codec_setup;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   201
  if(!ci)return -1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   202
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   203
  v->centerW=ci->blocksizes[1]/2;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   204
  v->pcm_current=v->centerW;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   205
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   206
  v->pcm_returned=-1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   207
  v->granulepos=-1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   208
  v->sequence=-1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   209
  ((private_state *)(v->backend_state))->sample_count=-1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   210
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   211
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   212
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   213
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   214
int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   215
  _vds_init(v,vi);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   216
  vorbis_synthesis_restart(v);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   217
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   218
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   219
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   220
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   221
void vorbis_dsp_clear(vorbis_dsp_state *v){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   222
  int i;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   223
  if(v){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   224
    vorbis_info *vi=v->vi;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   225
    codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   226
    private_state *b=(private_state *)v->backend_state;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   227
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   228
    if(v->pcm){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   229
      for(i=0;i<vi->channels;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   230
	if(v->pcm[i])_ogg_free(v->pcm[i]);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   231
      _ogg_free(v->pcm);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   232
      if(v->pcmret)_ogg_free(v->pcmret);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   233
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   234
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   235
    /* free mode lookups; these are actually vorbis_look_mapping structs */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   236
    if(ci){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   237
      for(i=0;i<ci->modes;i++){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   238
	int mapnum=ci->mode_param[i]->mapping;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   239
	int maptype=ci->map_type[mapnum];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   240
	if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   241
      }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   242
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   243
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   244
    if(b){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   245
      if(b->mode)_ogg_free(b->mode);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   246
      _ogg_free(b);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   247
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   248
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   249
    memset(v,0,sizeof(*v));
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   250
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   251
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   252
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   253
/* Unlike in analysis, the window is only partially applied for each
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   254
   block.  The time domain envelope is not yet handled at the point of
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   255
   calling (as it relies on the previous block). */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   256
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   257
int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   258
  vorbis_info *vi=v->vi;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   259
  codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   260
  private_state *b=v->backend_state;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   261
  int i,j;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   262
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   263
  if(v->pcm_current>v->pcm_returned  && v->pcm_returned!=-1)return(OV_EINVAL);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   264
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   265
  v->lW=v->W;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   266
  v->W=vb->W;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   267
  v->nW=-1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   268
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   269
  if((v->sequence==-1)||
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   270
     (v->sequence+1 != vb->sequence)){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   271
    v->granulepos=-1; /* out of sequence; lose count */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   272
    b->sample_count=-1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   273
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   274
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   275
  v->sequence=vb->sequence;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   276
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   277
  if(vb->pcm){  /* no pcm to process if vorbis_synthesis_trackonly
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   278
                   was called on block */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   279
    int n=ci->blocksizes[v->W]/2;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   280
    int n0=ci->blocksizes[0]/2;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   281
    int n1=ci->blocksizes[1]/2;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   282
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   283
    int thisCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   284
    int prevCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   285
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   286
    if(v->centerW){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   287
      thisCenter=n1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   288
      prevCenter=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   289
    }else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   290
      thisCenter=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   291
      prevCenter=n1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   292
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   293
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   294
    /* v->pcm is now used like a two-stage double buffer.  We don't want
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   295
       to have to constantly shift *or* adjust memory usage.  Don't
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   296
       accept a new block until the old is shifted out */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   297
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   298
    /* overlap/add PCM */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   299
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   300
    for(j=0;j<vi->channels;j++){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   301
      /* the overlap/add section */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   302
      if(v->lW){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   303
	if(v->W){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   304
	  /* large/large */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   305
	  ogg_int32_t *pcm=v->pcm[j]+prevCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   306
	  ogg_int32_t *p=vb->pcm[j];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   307
	  for(i=0;i<n1;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   308
	    pcm[i]+=p[i];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   309
	}else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   310
	  /* large/small */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   311
	  ogg_int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   312
	  ogg_int32_t *p=vb->pcm[j];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   313
	  for(i=0;i<n0;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   314
	    pcm[i]+=p[i];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   315
	}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   316
      }else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   317
	if(v->W){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   318
	  /* small/large */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   319
	  ogg_int32_t *pcm=v->pcm[j]+prevCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   320
	  ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   321
	  for(i=0;i<n0;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   322
	    pcm[i]+=p[i];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   323
	  for(;i<n1/2+n0/2;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   324
	    pcm[i]=p[i];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   325
	}else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   326
	  /* small/small */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   327
	  ogg_int32_t *pcm=v->pcm[j]+prevCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   328
	  ogg_int32_t *p=vb->pcm[j];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   329
	  for(i=0;i<n0;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   330
	    pcm[i]+=p[i];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   331
	}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   332
      }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   333
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   334
      /* the copy section */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   335
      {
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   336
	ogg_int32_t *pcm=v->pcm[j]+thisCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   337
	ogg_int32_t *p=vb->pcm[j]+n;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   338
	for(i=0;i<n;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   339
	  pcm[i]=p[i];
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   340
      }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   341
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   342
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   343
    if(v->centerW)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   344
      v->centerW=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   345
    else
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   346
      v->centerW=n1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   347
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   348
    /* deal with initial packet state; we do this using the explicit
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   349
       pcm_returned==-1 flag otherwise we're sensitive to first block
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   350
       being short or long */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   351
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   352
    if(v->pcm_returned==-1){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   353
      v->pcm_returned=thisCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   354
      v->pcm_current=thisCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   355
    }else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   356
      v->pcm_returned=prevCenter;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   357
      v->pcm_current=prevCenter+
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   358
	ci->blocksizes[v->lW]/4+
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   359
	ci->blocksizes[v->W]/4;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   360
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   361
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   362
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   363
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   364
  /* track the frame number... This is for convenience, but also
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   365
     making sure our last packet doesn't end with added padding.  If
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   366
     the last packet is partial, the number of samples we'll have to
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   367
     return will be past the vb->granulepos.
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   368
     
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   369
     This is not foolproof!  It will be confused if we begin
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   370
     decoding at the last page after a seek or hole.  In that case,
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   371
     we don't have a starting point to judge where the last frame
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   372
     is.  For this reason, vorbisfile will always try to make sure
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   373
     it reads the last two marked pages in proper sequence */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   374
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   375
  if(b->sample_count==-1){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   376
    b->sample_count=0;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   377
  }else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   378
    b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   379
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   380
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   381
  if(v->granulepos==-1){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   382
    if(vb->granulepos!=-1){ /* only set if we have a position to set to */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   383
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   384
      v->granulepos=vb->granulepos;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   385
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   386
      /* is this a short page? */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   387
      if(b->sample_count>v->granulepos){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   388
	/* corner case; if this is both the first and last audio page,
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   389
	   then spec says the end is cut, not beginning */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   390
	if(vb->eofflag){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   391
	  /* trim the end */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   392
	  /* no preceeding granulepos; assume we started at zero (we'd
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   393
	     have to in a short single-page stream) */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   394
	  /* granulepos could be -1 due to a seek, but that would result
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   395
	     in a long coun`t, not short count */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   396
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   397
	  v->pcm_current-=(b->sample_count-v->granulepos);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   398
	}else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   399
	  /* trim the beginning */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   400
	  v->pcm_returned+=(b->sample_count-v->granulepos);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   401
	  if(v->pcm_returned>v->pcm_current)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   402
	    v->pcm_returned=v->pcm_current;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   403
	}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   404
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   405
      }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   406
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   407
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   408
  }else{
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   409
    v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   410
    if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   411
      
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   412
      if(v->granulepos>vb->granulepos){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   413
	long extra=v->granulepos-vb->granulepos;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   414
	
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   415
	if(extra)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   416
	  if(vb->eofflag){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   417
	    /* partial last frame.  Strip the extra samples off */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   418
	    v->pcm_current-=extra;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   419
	  } /* else {Shouldn't happen *unless* the bitstream is out of
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   420
	       spec.  Either way, believe the bitstream } */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   421
      } /* else {Shouldn't happen *unless* the bitstream is out of
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   422
	   spec.  Either way, believe the bitstream } */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   423
      v->granulepos=vb->granulepos;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   424
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   425
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   426
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   427
  /* Update, cleanup */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   428
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   429
  if(vb->eofflag)v->eofflag=1;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   430
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   431
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   432
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   433
/* pcm==NULL indicates we just want the pending samples, no more */
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   434
int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   435
  vorbis_info *vi=v->vi;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   436
  if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   437
    if(pcm){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   438
      int i;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   439
      for(i=0;i<vi->channels;i++)
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   440
	v->pcmret[i]=v->pcm[i]+v->pcm_returned;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   441
      *pcm=v->pcmret;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   442
    }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   443
    return(v->pcm_current-v->pcm_returned);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   444
  }
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   445
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   446
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   447
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   448
int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   449
  if(bytes && v->pcm_returned+bytes>v->pcm_current)return(OV_EINVAL);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   450
  v->pcm_returned+=bytes;
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   451
  return(0);
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   452
}
519d5bc91dd3 revert tremor back to a version before koda broke it ;p
Xeli
parents:
diff changeset
   453