Mercurial > libavcodec.hg
comparison vorbis.c @ 10309:d157ccc267e7 libavcodec
brace placement and linebreak cosmetics
author | diego |
---|---|
date | Mon, 28 Sep 2009 21:13:47 +0000 |
parents | 8078ecd2fe4c |
children | d3644248015a |
comparison
equal
deleted
inserted
replaced
10308:28b0f87cfdf1 | 10309:d157ccc267e7 |
---|---|
30 #include "vorbis.h" | 30 #include "vorbis.h" |
31 | 31 |
32 | 32 |
33 /* Helper functions */ | 33 /* Helper functions */ |
34 | 34 |
35 unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n) | 35 // x^(1/n) |
36 unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) | |
37 { | |
36 unsigned int ret=0, i, j; | 38 unsigned int ret=0, i, j; |
37 | 39 |
38 do { | 40 do { |
39 ++ret; | 41 ++ret; |
40 for(i=0,j=ret;i<n-1;i++) j*=ret; | 42 for(i=0,j=ret;i<n-1;i++) j*=ret; |
46 // Generate vlc codes from vorbis huffman code lengths | 48 // Generate vlc codes from vorbis huffman code lengths |
47 | 49 |
48 // the two bits[p] > 32 checks should be redundant, all calling code should | 50 // the two bits[p] > 32 checks should be redundant, all calling code should |
49 // already ensure that, but since it allows overwriting the stack it seems | 51 // already ensure that, but since it allows overwriting the stack it seems |
50 // reasonable to check redundantly. | 52 // reasonable to check redundantly. |
51 int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) { | 53 int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) |
54 { | |
52 uint_fast32_t exit_at_level[33]={404,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 55 uint_fast32_t exit_at_level[33]={404,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
53 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | 56 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
54 | 57 |
55 uint_fast8_t i,j; | 58 uint_fast8_t i,j; |
56 uint_fast32_t code,p; | 59 uint_fast32_t code,p; |
65 return 0; | 68 return 0; |
66 } | 69 } |
67 | 70 |
68 codes[p]=0; | 71 codes[p]=0; |
69 if (bits[p] > 32) return 1; | 72 if (bits[p] > 32) return 1; |
70 for(i=0;i<bits[p];++i) { | 73 for(i=0;i<bits[p];++i) |
71 exit_at_level[i+1]=1<<i; | 74 exit_at_level[i+1]=1<<i; |
72 } | |
73 | 75 |
74 #ifdef V_DEBUG | 76 #ifdef V_DEBUG |
75 av_log(NULL, AV_LOG_INFO, " %d. of %d code len %d code %d - ", p, num, bits[p], codes[p]); | 77 av_log(NULL, AV_LOG_INFO, " %d. of %d code len %d code %d - ", p, num, bits[p], codes[p]); |
76 init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); | 78 init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); |
77 for(i=0;i<bits[p];++i) { | 79 for(i=0;i<bits[p];++i) |
78 av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0"); | 80 av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0"); |
79 } | |
80 av_log(NULL, AV_LOG_INFO, "\n"); | 81 av_log(NULL, AV_LOG_INFO, "\n"); |
81 #endif | 82 #endif |
82 | 83 |
83 ++p; | 84 ++p; |
84 | 85 |
85 for(;p<num;++p) { | 86 for(;p<num;++p) { |
86 if (bits[p] > 32) return 1; | 87 if (bits[p] > 32) return 1; |
87 if (bits[p]==0) continue; | 88 if (bits[p]==0) continue; |
88 // find corresponding exit(node which the tree can grow further from) | 89 // find corresponding exit(node which the tree can grow further from) |
89 for(i=bits[p];i>0;--i) { | 90 for(i=bits[p];i>0;--i) |
90 if (exit_at_level[i]) break; | 91 if (exit_at_level[i]) break; |
91 } | |
92 if (!i) return 1; // overspecified tree | 92 if (!i) return 1; // overspecified tree |
93 code=exit_at_level[i]; | 93 code=exit_at_level[i]; |
94 exit_at_level[i]=0; | 94 exit_at_level[i]=0; |
95 // construct code (append 0s to end) and introduce new exits | 95 // construct code (append 0s to end) and introduce new exits |
96 for(j=i+1;j<=bits[p];++j) { | 96 for(j=i+1;j<=bits[p];++j) |
97 exit_at_level[j]=code+(1<<(j-1)); | 97 exit_at_level[j]=code+(1<<(j-1)); |
98 } | |
99 codes[p]=code; | 98 codes[p]=code; |
100 | 99 |
101 #ifdef V_DEBUG | 100 #ifdef V_DEBUG |
102 av_log(NULL, AV_LOG_INFO, " %d. code len %d code %d - ", p, bits[p], codes[p]); | 101 av_log(NULL, AV_LOG_INFO, " %d. code len %d code %d - ", p, bits[p], codes[p]); |
103 init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); | 102 init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); |
104 for(i=0;i<bits[p];++i) { | 103 for(i=0;i<bits[p];++i) |
105 av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0"); | 104 av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0"); |
106 } | |
107 av_log(NULL, AV_LOG_INFO, "\n"); | 105 av_log(NULL, AV_LOG_INFO, "\n"); |
108 #endif | 106 #endif |
109 | 107 |
110 } | 108 } |
111 | 109 |
114 if (exit_at_level[p]) return 1; | 112 if (exit_at_level[p]) return 1; |
115 | 113 |
116 return 0; | 114 return 0; |
117 } | 115 } |
118 | 116 |
119 void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values) { | 117 void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values) |
118 { | |
120 int i; | 119 int i; |
121 list[0].sort = 0; | 120 list[0].sort = 0; |
122 list[1].sort = 1; | 121 list[1].sort = 1; |
123 for (i = 2; i < values; i++) { | 122 for (i = 2; i < values; i++) { |
124 int j; | 123 int j; |
144 } | 143 } |
145 } | 144 } |
146 } | 145 } |
147 } | 146 } |
148 | 147 |
149 static inline void render_line_unrolled(intptr_t x, intptr_t y, int x1, intptr_t sy, int ady, int adx, float * buf) { | 148 static inline void render_line_unrolled(intptr_t x, intptr_t y, int x1, |
149 intptr_t sy, int ady, int adx, | |
150 float * buf) | |
151 { | |
150 int err = -adx; | 152 int err = -adx; |
151 x -= x1-1; | 153 x -= x1-1; |
152 buf += x1-1; | 154 buf += x1-1; |
153 while (++x < 0) { | 155 while (++x < 0) { |
154 err += ady; | 156 err += ady; |
164 y += sy; | 166 y += sy; |
165 buf[x] = ff_vorbis_floor1_inverse_db_table[y]; | 167 buf[x] = ff_vorbis_floor1_inverse_db_table[y]; |
166 } | 168 } |
167 } | 169 } |
168 | 170 |
169 static void render_line(int x0, int y0, int x1, int y1, float * buf) { | 171 static void render_line(int x0, int y0, int x1, int y1, float * buf) |
172 { | |
170 int dy = y1 - y0; | 173 int dy = y1 - y0; |
171 int adx = x1 - x0; | 174 int adx = x1 - x0; |
172 int ady = FFABS(dy); | 175 int ady = FFABS(dy); |
173 int sy = dy<0 ? -1 : 1; | 176 int sy = dy<0 ? -1 : 1; |
174 buf[x0] = ff_vorbis_floor1_inverse_db_table[y0]; | 177 buf[x0] = ff_vorbis_floor1_inverse_db_table[y0]; |
190 buf[x] = ff_vorbis_floor1_inverse_db_table[y]; | 193 buf[x] = ff_vorbis_floor1_inverse_db_table[y]; |
191 } | 194 } |
192 } | 195 } |
193 } | 196 } |
194 | 197 |
195 void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, uint_fast16_t * y_list, int * flag, int multiplier, float * out, int samples) { | 198 void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, |
199 uint_fast16_t * y_list, int * flag, | |
200 int multiplier, float * out, int samples) | |
201 { | |
196 int lx, ly, i; | 202 int lx, ly, i; |
197 lx = 0; | 203 lx = 0; |
198 ly = y_list[0] * multiplier; | 204 ly = y_list[0] * multiplier; |
199 for (i = 1; i < values; i++) { | 205 for (i = 1; i < values; i++) { |
200 int pos = list[i].sort; | 206 int pos = list[i].sort; |