annotate tremor/synthesis.c @ 22379:6b245d6e56a9

winsocks expects an int in milliseconds instead of struct timeval to set the timeout of a socket patch by Zuxy Meng, zuxy dot meng ... gmailcom
author ivo
date Thu, 01 Mar 2007 14:57:44 +0000
parents cd6b211be811
children 8dfda4d651ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
1 /********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
2 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
4 * *
19251
cd6b211be811 Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents: 14280
diff changeset
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
cd6b211be811 Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents: 14280
diff changeset
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
cd6b211be811 Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents: 14280
diff changeset
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
cd6b211be811 Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents: 14280
diff changeset
8 * *
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
11 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
12 ********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
13
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
14 function: single-block PCM synthesis
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
15 last mod: $Id$
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
16
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
17 ********************************************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
18
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
19 #include <stdio.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
20 #include "ogg.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
21 #include "ivorbiscodec.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
22 #include "codec_internal.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
23 #include "registry.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
24 #include "misc.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
25 #include "os.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
26
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
27 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
28 vorbis_dsp_state *vd=vb->vd;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29 backend_lookup_state *b=(backend_lookup_state *)vd->backend_state;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 vorbis_info *vi=vd->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32 oggpack_buffer *opb=&vb->opb;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33 int type,mode,i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35 /* first things first. Make sure decode is ready */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36 _vorbis_block_ripcord(vb);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37 oggpack_readinit(opb,op->packet,op->bytes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39 /* Check the packet type */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40 if(oggpack_read(opb,1)!=0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41 /* Oops. This is not an audio data packet */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 return(OV_ENOTAUDIO);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
44
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
45 /* read our mode and pre/post windowsize */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
46 mode=oggpack_read(opb,b->modebits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
47 if(mode==-1)return(OV_EBADPACKET);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49 vb->mode=mode;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50 vb->W=ci->mode_param[mode]->blockflag;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
51 if(vb->W){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
52 vb->lW=oggpack_read(opb,1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
53 vb->nW=oggpack_read(opb,1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54 if(vb->nW==-1) return(OV_EBADPACKET);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
55 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
56 vb->lW=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
57 vb->nW=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
58 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 /* more setup */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61 vb->granulepos=op->granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62 vb->sequence=op->packetno-3; /* first block is third packet */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63 vb->eofflag=op->e_o_s;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 /* alloc pcm passback storage */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
66 vb->pcmend=ci->blocksizes[vb->W];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
67 vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
68 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
69 vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71 /* unpack_header enforces range checking */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72 type=ci->map_type[ci->mode_param[mode]->mapping];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79 oggpack_buffer opb;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80 int mode;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 oggpack_readinit(&opb,op->packet,op->bytes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84 /* Check the packet type */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85 if(oggpack_read(&opb,1)!=0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86 /* Oops. This is not an audio data packet */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 return(OV_ENOTAUDIO);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 int modebits=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
92 int v=ci->modes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 while(v>1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94 modebits++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95 v>>=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
98 /* read our mode and pre/post windowsize */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
99 mode=oggpack_read(&opb,modebits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
100 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
101 if(mode==-1)return(OV_EBADPACKET);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
102 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
103 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
104
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
105