annotate tremor/mapping0.c @ 33669:e7ef5b755462

Redraw GUI only after all necessary values have been set. Move guiGetEvent() type guiSetVolume call before the redraw call.
author ib
date Tue, 28 Jun 2011 17:23:37 +0000
parents e83eef58b30a
children
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: channel mapping 0 implementation
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
15
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 #include <stdlib.h>
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 <string.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
21 #include <math.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
22 #include "ogg.h"
28240
4940b8a98c78 Fix r28222, including alloca.h directly might break compilation.
reimar
parents: 28187
diff changeset
23 #include "os.h"
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
24 #include "ivorbiscodec.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
25 #include "mdct.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
26 #include "codec_internal.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
27 #include "codebook.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
28 #include "window.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29 #include "registry.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 #include "misc.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32 /* simplistic, wasteful way of doing this (unique lookup for each
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33 mode/submapping); there should be a central repository for
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34 identical lookups. That will require minor work, so I'm putting it
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35 off as low priority.
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37 Why a lookup for each backend in a given mode? Because the
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38 blocksize is set by the mode, and low backend lookups may require
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39 parameters from other areas of the mode/mapping */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 vorbis_info_mode *mode;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43 vorbis_info_mapping0 *map;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
44
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
45 vorbis_look_floor **floor_look;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
46
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
47 vorbis_look_residue **residue_look;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49 vorbis_func_floor **floor_func;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50 vorbis_func_residue **residue_func;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
51
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
52 int ch;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
53 long lastframe; /* if a different mode is called, we need to
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54 invalidate decay */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
55 } vorbis_look_mapping0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
56
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
57 static void mapping0_free_info(vorbis_info_mapping *i){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
58 vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59 if(info){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 memset(info,0,sizeof(*info));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61 _ogg_free(info);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 static void mapping0_free_look(vorbis_look_mapping *look){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
66 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
67 vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
68 if(l){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
69
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70 for(i=0;i<l->map->submaps;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71 l->floor_func[i]->free_look(l->floor_look[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72 l->residue_func[i]->free_look(l->residue_look[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75 _ogg_free(l->floor_func);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76 _ogg_free(l->residue_func);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77 _ogg_free(l->floor_look);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 _ogg_free(l->residue_look);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79 memset(l,0,sizeof(*l));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80 _ogg_free(l);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84 static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85 vorbis_info_mapping *m){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 vorbis_info *vi=vd->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89 vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)_ogg_calloc(1,sizeof(*look));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90 vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 look->mode=vm;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
92
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 look->floor_look=(vorbis_look_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_look));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95 look->residue_look=(vorbis_look_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_look));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97 look->floor_func=(vorbis_func_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_func));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
98 look->residue_func=(vorbis_func_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_func));
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
99
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
100 for(i=0;i<info->submaps;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
101 int floornum=info->floorsubmap[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
102 int resnum=info->residuesubmap[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
103
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
104 look->floor_func[i]=_floor_P[ci->floor_type[floornum]];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
105 look->floor_look[i]=look->floor_func[i]->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
106 look(vd,vm,ci->floor_param[floornum]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
107 look->residue_func[i]=_residue_P[ci->residue_type[resnum]];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
108 look->residue_look[i]=look->residue_func[i]->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
109 look(vd,vm,ci->residue_param[resnum]);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
110
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
111 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
112
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
113 look->ch=vi->channels;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
114
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
115 return(look);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
116 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
117
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
118 static int ilog(unsigned int v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
119 int ret=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
120 if(v)--v;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
121 while(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
122 ret++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
123 v>>=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
124 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
125 return(ret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
126 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
127
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
128 /* also responsible for range checking */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
129 static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
130 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
131 vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
132 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
133 memset(info,0,sizeof(*info));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
134
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
135 if(oggpack_read(opb,1))
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
136 info->submaps=oggpack_read(opb,4)+1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
137 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
138 info->submaps=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
139
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
140 if(oggpack_read(opb,1)){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
141 info->coupling_steps=oggpack_read(opb,8)+1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
142
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
143 for(i=0;i<info->coupling_steps;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
144 int testM=info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
145 int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
146
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
147 if(testM<0 ||
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
148 testA<0 ||
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
149 testM==testA ||
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
150 testM>=vi->channels ||
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
151 testA>=vi->channels) goto err_out;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
152 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
153
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
154 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
155
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
156 if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
157
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
158 if(info->submaps>1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
159 for(i=0;i<vi->channels;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
160 info->chmuxlist[i]=oggpack_read(opb,4);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
161 if(info->chmuxlist[i]>=info->submaps)goto err_out;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
162 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
163 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
164 for(i=0;i<info->submaps;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
165 int temp=oggpack_read(opb,8);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
166 if(temp>=ci->times)goto err_out;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
167 info->floorsubmap[i]=oggpack_read(opb,8);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
168 if(info->floorsubmap[i]>=ci->floors)goto err_out;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
169 info->residuesubmap[i]=oggpack_read(opb,8);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
170 if(info->residuesubmap[i]>=ci->residues)goto err_out;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
171 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
172
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
173 return info;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
174
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
175 err_out:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
176 mapping0_free_info(info);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
177 return(NULL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
178 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
179
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
180 static int seq=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
181 static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
182 vorbis_dsp_state *vd=vb->vd;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
183 vorbis_info *vi=vd->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
184 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
185 backend_lookup_state *b=(backend_lookup_state *)vd->backend_state;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
186 vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
187 vorbis_info_mapping0 *info=look->map;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
188
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
189 int i,j;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
190 long n=vb->pcmend=ci->blocksizes[vb->W];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
191
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
192 ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
193 int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
194
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
195 int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
196 void **floormemo=(void **)alloca(sizeof(*floormemo)*vi->channels);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
197
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
198 /* time domain information decode (note that applying the
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
199 information would have to happen later; we'll probably add a
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
200 function entry to the harness for that later */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
201 /* NOT IMPLEMENTED */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
202
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
203 /* recover the spectral envelope; store it in the PCM vector for now */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
204 for(i=0;i<vi->channels;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
205 int submap=info->chmuxlist[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
206 floormemo[i]=look->floor_func[submap]->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
207 inverse1(vb,look->floor_look[submap]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
208 if(floormemo[i])
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
209 nonzero[i]=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
210 else
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
211 nonzero[i]=0;
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
212 memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
213 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
214
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
215 /* channel coupling can 'dirty' the nonzero listing */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
216 for(i=0;i<info->coupling_steps;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
217 if(nonzero[info->coupling_mag[i]] ||
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
218 nonzero[info->coupling_ang[i]]){
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
219 nonzero[info->coupling_mag[i]]=1;
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
220 nonzero[info->coupling_ang[i]]=1;
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
221 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
222 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
223
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
224 /* recover the residue into our working vectors */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
225 for(i=0;i<info->submaps;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
226 int ch_in_bundle=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
227 for(j=0;j<vi->channels;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
228 if(info->chmuxlist[j]==i){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
229 if(nonzero[j])
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
230 zerobundle[ch_in_bundle]=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
231 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
232 zerobundle[ch_in_bundle]=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
233 pcmbundle[ch_in_bundle++]=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
234 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
235 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
236
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
237 look->residue_func[i]->inverse(vb,look->residue_look[i],
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
238 pcmbundle,zerobundle,ch_in_bundle);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
239 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
240
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
241 //for(j=0;j<vi->channels;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
242 //_analysis_output("coupled",seq+j,vb->pcm[j],-8,n/2,0,0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
243
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
244
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
245 /* channel coupling */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
246 for(i=info->coupling_steps-1;i>=0;i--){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
247 ogg_int32_t *pcmM=vb->pcm[info->coupling_mag[i]];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
248 ogg_int32_t *pcmA=vb->pcm[info->coupling_ang[i]];
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
249
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
250 for(j=0;j<n/2;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
251 ogg_int32_t mag=pcmM[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
252 ogg_int32_t ang=pcmA[j];
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
253
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
254 if(mag>0)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
255 if(ang>0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
256 pcmM[j]=mag;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
257 pcmA[j]=mag-ang;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
258 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
259 pcmA[j]=mag;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
260 pcmM[j]=mag+ang;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
261 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
262 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
263 if(ang>0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
264 pcmM[j]=mag;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
265 pcmA[j]=mag+ang;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
266 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
267 pcmA[j]=mag;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
268 pcmM[j]=mag-ang;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
269 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
270 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
271 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
272
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
273 //for(j=0;j<vi->channels;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
274 //_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
275
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
276 /* compute and apply spectral envelope */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
277 for(i=0;i<vi->channels;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
278 ogg_int32_t *pcm=vb->pcm[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
279 int submap=info->chmuxlist[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
280 look->floor_func[submap]->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
281 inverse2(vb,look->floor_look[submap],floormemo[i],pcm);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
282 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
283
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
284 //for(j=0;j<vi->channels;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
285 //_analysis_output("mdct",seq+j,vb->pcm[j],-24,n/2,0,1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
286
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
287 /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
288 /* only MDCT right now.... */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
289 for(i=0;i<vi->channels;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
290 ogg_int32_t *pcm=vb->pcm[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
291 mdct_backward(n,pcm,pcm);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
292 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
293
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
294 //for(j=0;j<vi->channels;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
295 //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
296
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
297 /* window the data */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
298 for(i=0;i<vi->channels;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
299 ogg_int32_t *pcm=vb->pcm[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
300 if(nonzero[i])
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
301 _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
302 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
303 for(j=0;j<n;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
304 pcm[j]=0;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 28240
diff changeset
305
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
306 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
307
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
308 //for(j=0;j<vi->channels;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
309 //_analysis_output("window",seq+j,vb->pcm[j],-24,n,0,0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
310
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
311 seq+=vi->channels;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
312 /* all done! */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
313 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
314 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
315
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
316 /* export hooks */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
317 vorbis_func_mapping mapping0_exportbundle={
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
318 &mapping0_unpack,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
319 &mapping0_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
320 &mapping0_free_info,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
321 &mapping0_free_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
322 &mapping0_inverse
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
323 };