2005-02-17 09:08:18 +00:00
|
|
|
/********************************************************************
|
|
|
|
* *
|
|
|
|
* THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
|
|
|
|
* *
|
|
|
|
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
|
|
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
|
|
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
|
|
|
* *
|
|
|
|
* THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
|
|
|
|
* BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
|
|
|
|
* *
|
|
|
|
********************************************************************
|
|
|
|
|
|
|
|
function: single-block PCM synthesis
|
|
|
|
last mod: $Id$
|
|
|
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "ogg.h"
|
|
|
|
#include "ivorbiscodec.h"
|
|
|
|
#include "codec_internal.h"
|
|
|
|
#include "registry.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
2005-06-06 23:01:51 +00:00
|
|
|
|
2010-12-04 12:59:37 +00:00
|
|
|
static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){
|
2010-12-08 16:07:46 +00:00
|
|
|
vorbis_dsp_state *vd= vb ? vb->vd : 0;
|
|
|
|
private_state *b= vd ? (private_state *)vd->backend_state: 0;
|
|
|
|
vorbis_info *vi= vd ? vd->vi : 0;
|
|
|
|
codec_setup_info *ci= vi ? (codec_setup_info *)vi->codec_setup : 0;
|
|
|
|
oggpack_buffer *opb=vb ? &vb->opb : 0;
|
2011-09-22 11:47:51 +00:00
|
|
|
int type,mode;
|
2005-02-17 09:08:18 +00:00
|
|
|
|
2010-12-08 16:07:46 +00:00
|
|
|
if (!vd || !b || !vi || !ci || !opb) {
|
|
|
|
return OV_EBADPACKET;
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
/* first things first. Make sure decode is ready */
|
|
|
|
_vorbis_block_ripcord(vb);
|
2010-12-06 14:36:52 +00:00
|
|
|
oggpack_readinit(opb,op->packet,op->bytes);
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
/* Check the packet type */
|
|
|
|
if(oggpack_read(opb,1)!=0){
|
|
|
|
/* Oops. This is not an audio data packet */
|
|
|
|
return(OV_ENOTAUDIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read our mode and pre/post windowsize */
|
|
|
|
mode=oggpack_read(opb,b->modebits);
|
|
|
|
if(mode==-1)return(OV_EBADPACKET);
|
|
|
|
|
|
|
|
vb->mode=mode;
|
2010-12-08 16:07:46 +00:00
|
|
|
if(!ci->mode_param[mode]){
|
|
|
|
return(OV_EBADPACKET);
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
vb->W=ci->mode_param[mode]->blockflag;
|
|
|
|
if(vb->W){
|
|
|
|
vb->lW=oggpack_read(opb,1);
|
|
|
|
vb->nW=oggpack_read(opb,1);
|
|
|
|
if(vb->nW==-1) return(OV_EBADPACKET);
|
|
|
|
}else{
|
|
|
|
vb->lW=0;
|
|
|
|
vb->nW=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* more setup */
|
|
|
|
vb->granulepos=op->granulepos;
|
|
|
|
vb->sequence=op->packetno-3; /* first block is third packet */
|
|
|
|
vb->eofflag=op->e_o_s;
|
|
|
|
|
2010-02-17 00:49:53 +00:00
|
|
|
if(decodep && vi->channels<=CHANNELS)
|
|
|
|
{
|
2009-09-07 19:39:51 +00:00
|
|
|
/* set pcm end point */
|
2005-02-17 09:08:18 +00:00
|
|
|
vb->pcmend=ci->blocksizes[vb->W];
|
2005-06-06 23:01:51 +00:00
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
/* unpack_header enforces range checking */
|
|
|
|
type=ci->map_type[ci->mode_param[mode]->mapping];
|
|
|
|
return(_mapping_P[type]->inverse(vb,b->mode[mode]));
|
|
|
|
}else{
|
|
|
|
/* no pcm */
|
|
|
|
vb->pcmend=0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-04 12:59:37 +00:00
|
|
|
int vorbis_synthesis(vorbis_block *vb,ogg_packet *op)
|
|
|
|
ICODE_ATTR_TREMOR_NOT_MDCT;
|
|
|
|
int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
|
|
|
|
return _vorbis_synthesis1(vb,op,1);
|
|
|
|
}
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
/* used to track pcm position without actually performing decode.
|
|
|
|
Useful for sequential 'fast forward' */
|
2010-12-04 12:59:37 +00:00
|
|
|
int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
|
|
|
|
return _vorbis_synthesis1(vb,op,0);
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:08:18 +00:00
|
|
|
long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
|
|
|
|
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
|
|
|
oggpack_buffer opb;
|
|
|
|
int mode;
|
|
|
|
|
2010-12-06 14:36:52 +00:00
|
|
|
oggpack_readinit(&opb,op->packet,op->bytes);
|
2005-02-17 09:08:18 +00:00
|
|
|
|
|
|
|
/* Check the packet type */
|
|
|
|
if(oggpack_read(&opb,1)!=0){
|
|
|
|
/* Oops. This is not an audio data packet */
|
|
|
|
return(OV_ENOTAUDIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int modebits=0;
|
|
|
|
int v=ci->modes;
|
|
|
|
while(v>1){
|
|
|
|
modebits++;
|
|
|
|
v>>=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read our mode and pre/post windowsize */
|
|
|
|
mode=oggpack_read(&opb,modebits);
|
|
|
|
}
|
|
|
|
if(mode==-1)return(OV_EBADPACKET);
|
|
|
|
return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|