diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libffmpegFLAC | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libffmpegFLAC')
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/COPYING | 504 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/README | 19 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/README.rockbox | 46 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/SOURCES | 7 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/arm.S | 271 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/arm.h | 8 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/bitstream.h | 79 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/coldfire.S | 535 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/coldfire.h | 11 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/decoder.c | 627 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/decoder.h | 49 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/golomb.h | 110 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/libffmpegFLAC.make | 18 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/shndec.c | 481 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/shndec.h | 52 |
15 files changed, 2817 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/COPYING b/lib/rbcodec/codecs/libffmpegFLAC/COPYING new file mode 100644 index 0000000000..223ede7de3 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/COPYING | |||
@@ -0,0 +1,504 @@ | |||
1 | GNU LESSER GENERAL PUBLIC LICENSE | ||
2 | Version 2.1, February 1999 | ||
3 | |||
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. | ||
5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
6 | Everyone is permitted to copy and distribute verbatim copies | ||
7 | of this license document, but changing it is not allowed. | ||
8 | |||
9 | [This is the first released version of the Lesser GPL. It also counts | ||
10 | as the successor of the GNU Library Public License, version 2, hence | ||
11 | the version number 2.1.] | ||
12 | |||
13 | Preamble | ||
14 | |||
15 | The licenses for most software are designed to take away your | ||
16 | freedom to share and change it. By contrast, the GNU General Public | ||
17 | Licenses are intended to guarantee your freedom to share and change | ||
18 | free software--to make sure the software is free for all its users. | ||
19 | |||
20 | This license, the Lesser General Public License, applies to some | ||
21 | specially designated software packages--typically libraries--of the | ||
22 | Free Software Foundation and other authors who decide to use it. You | ||
23 | can use it too, but we suggest you first think carefully about whether | ||
24 | this license or the ordinary General Public License is the better | ||
25 | strategy to use in any particular case, based on the explanations below. | ||
26 | |||
27 | When we speak of free software, we are referring to freedom of use, | ||
28 | not price. Our General Public Licenses are designed to make sure that | ||
29 | you have the freedom to distribute copies of free software (and charge | ||
30 | for this service if you wish); that you receive source code or can get | ||
31 | it if you want it; that you can change the software and use pieces of | ||
32 | it in new free programs; and that you are informed that you can do | ||
33 | these things. | ||
34 | |||
35 | To protect your rights, we need to make restrictions that forbid | ||
36 | distributors to deny you these rights or to ask you to surrender these | ||
37 | rights. These restrictions translate to certain responsibilities for | ||
38 | you if you distribute copies of the library or if you modify it. | ||
39 | |||
40 | For example, if you distribute copies of the library, whether gratis | ||
41 | or for a fee, you must give the recipients all the rights that we gave | ||
42 | you. You must make sure that they, too, receive or can get the source | ||
43 | code. If you link other code with the library, you must provide | ||
44 | complete object files to the recipients, so that they can relink them | ||
45 | with the library after making changes to the library and recompiling | ||
46 | it. And you must show them these terms so they know their rights. | ||
47 | |||
48 | We protect your rights with a two-step method: (1) we copyright the | ||
49 | library, and (2) we offer you this license, which gives you legal | ||
50 | permission to copy, distribute and/or modify the library. | ||
51 | |||
52 | To protect each distributor, we want to make it very clear that | ||
53 | there is no warranty for the free library. Also, if the library is | ||
54 | modified by someone else and passed on, the recipients should know | ||
55 | that what they have is not the original version, so that the original | ||
56 | author's reputation will not be affected by problems that might be | ||
57 | introduced by others. | ||
58 | |||
59 | Finally, software patents pose a constant threat to the existence of | ||
60 | any free program. We wish to make sure that a company cannot | ||
61 | effectively restrict the users of a free program by obtaining a | ||
62 | restrictive license from a patent holder. Therefore, we insist that | ||
63 | any patent license obtained for a version of the library must be | ||
64 | consistent with the full freedom of use specified in this license. | ||
65 | |||
66 | Most GNU software, including some libraries, is covered by the | ||
67 | ordinary GNU General Public License. This license, the GNU Lesser | ||
68 | General Public License, applies to certain designated libraries, and | ||
69 | is quite different from the ordinary General Public License. We use | ||
70 | this license for certain libraries in order to permit linking those | ||
71 | libraries into non-free programs. | ||
72 | |||
73 | When a program is linked with a library, whether statically or using | ||
74 | a shared library, the combination of the two is legally speaking a | ||
75 | combined work, a derivative of the original library. The ordinary | ||
76 | General Public License therefore permits such linking only if the | ||
77 | entire combination fits its criteria of freedom. The Lesser General | ||
78 | Public License permits more lax criteria for linking other code with | ||
79 | the library. | ||
80 | |||
81 | We call this license the "Lesser" General Public License because it | ||
82 | does Less to protect the user's freedom than the ordinary General | ||
83 | Public License. It also provides other free software developers Less | ||
84 | of an advantage over competing non-free programs. These disadvantages | ||
85 | are the reason we use the ordinary General Public License for many | ||
86 | libraries. However, the Lesser license provides advantages in certain | ||
87 | special circumstances. | ||
88 | |||
89 | For example, on rare occasions, there may be a special need to | ||
90 | encourage the widest possible use of a certain library, so that it becomes | ||
91 | a de-facto standard. To achieve this, non-free programs must be | ||
92 | allowed to use the library. A more frequent case is that a free | ||
93 | library does the same job as widely used non-free libraries. In this | ||
94 | case, there is little to gain by limiting the free library to free | ||
95 | software only, so we use the Lesser General Public License. | ||
96 | |||
97 | In other cases, permission to use a particular library in non-free | ||
98 | programs enables a greater number of people to use a large body of | ||
99 | free software. For example, permission to use the GNU C Library in | ||
100 | non-free programs enables many more people to use the whole GNU | ||
101 | operating system, as well as its variant, the GNU/Linux operating | ||
102 | system. | ||
103 | |||
104 | Although the Lesser General Public License is Less protective of the | ||
105 | users' freedom, it does ensure that the user of a program that is | ||
106 | linked with the Library has the freedom and the wherewithal to run | ||
107 | that program using a modified version of the Library. | ||
108 | |||
109 | The precise terms and conditions for copying, distribution and | ||
110 | modification follow. Pay close attention to the difference between a | ||
111 | "work based on the library" and a "work that uses the library". The | ||
112 | former contains code derived from the library, whereas the latter must | ||
113 | be combined with the library in order to run. | ||
114 | |||
115 | GNU LESSER GENERAL PUBLIC LICENSE | ||
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
117 | |||
118 | 0. This License Agreement applies to any software library or other | ||
119 | program which contains a notice placed by the copyright holder or | ||
120 | other authorized party saying it may be distributed under the terms of | ||
121 | this Lesser General Public License (also called "this License"). | ||
122 | Each licensee is addressed as "you". | ||
123 | |||
124 | A "library" means a collection of software functions and/or data | ||
125 | prepared so as to be conveniently linked with application programs | ||
126 | (which use some of those functions and data) to form executables. | ||
127 | |||
128 | The "Library", below, refers to any such software library or work | ||
129 | which has been distributed under these terms. A "work based on the | ||
130 | Library" means either the Library or any derivative work under | ||
131 | copyright law: that is to say, a work containing the Library or a | ||
132 | portion of it, either verbatim or with modifications and/or translated | ||
133 | straightforwardly into another language. (Hereinafter, translation is | ||
134 | included without limitation in the term "modification".) | ||
135 | |||
136 | "Source code" for a work means the preferred form of the work for | ||
137 | making modifications to it. For a library, complete source code means | ||
138 | all the source code for all modules it contains, plus any associated | ||
139 | interface definition files, plus the scripts used to control compilation | ||
140 | and installation of the library. | ||
141 | |||
142 | Activities other than copying, distribution and modification are not | ||
143 | covered by this License; they are outside its scope. The act of | ||
144 | running a program using the Library is not restricted, and output from | ||
145 | such a program is covered only if its contents constitute a work based | ||
146 | on the Library (independent of the use of the Library in a tool for | ||
147 | writing it). Whether that is true depends on what the Library does | ||
148 | and what the program that uses the Library does. | ||
149 | |||
150 | 1. You may copy and distribute verbatim copies of the Library's | ||
151 | complete source code as you receive it, in any medium, provided that | ||
152 | you conspicuously and appropriately publish on each copy an | ||
153 | appropriate copyright notice and disclaimer of warranty; keep intact | ||
154 | all the notices that refer to this License and to the absence of any | ||
155 | warranty; and distribute a copy of this License along with the | ||
156 | Library. | ||
157 | |||
158 | You may charge a fee for the physical act of transferring a copy, | ||
159 | and you may at your option offer warranty protection in exchange for a | ||
160 | fee. | ||
161 | |||
162 | 2. You may modify your copy or copies of the Library or any portion | ||
163 | of it, thus forming a work based on the Library, and copy and | ||
164 | distribute such modifications or work under the terms of Section 1 | ||
165 | above, provided that you also meet all of these conditions: | ||
166 | |||
167 | a) The modified work must itself be a software library. | ||
168 | |||
169 | b) You must cause the files modified to carry prominent notices | ||
170 | stating that you changed the files and the date of any change. | ||
171 | |||
172 | c) You must cause the whole of the work to be licensed at no | ||
173 | charge to all third parties under the terms of this License. | ||
174 | |||
175 | d) If a facility in the modified Library refers to a function or a | ||
176 | table of data to be supplied by an application program that uses | ||
177 | the facility, other than as an argument passed when the facility | ||
178 | is invoked, then you must make a good faith effort to ensure that, | ||
179 | in the event an application does not supply such function or | ||
180 | table, the facility still operates, and performs whatever part of | ||
181 | its purpose remains meaningful. | ||
182 | |||
183 | (For example, a function in a library to compute square roots has | ||
184 | a purpose that is entirely well-defined independent of the | ||
185 | application. Therefore, Subsection 2d requires that any | ||
186 | application-supplied function or table used by this function must | ||
187 | be optional: if the application does not supply it, the square | ||
188 | root function must still compute square roots.) | ||
189 | |||
190 | These requirements apply to the modified work as a whole. If | ||
191 | identifiable sections of that work are not derived from the Library, | ||
192 | and can be reasonably considered independent and separate works in | ||
193 | themselves, then this License, and its terms, do not apply to those | ||
194 | sections when you distribute them as separate works. But when you | ||
195 | distribute the same sections as part of a whole which is a work based | ||
196 | on the Library, the distribution of the whole must be on the terms of | ||
197 | this License, whose permissions for other licensees extend to the | ||
198 | entire whole, and thus to each and every part regardless of who wrote | ||
199 | it. | ||
200 | |||
201 | Thus, it is not the intent of this section to claim rights or contest | ||
202 | your rights to work written entirely by you; rather, the intent is to | ||
203 | exercise the right to control the distribution of derivative or | ||
204 | collective works based on the Library. | ||
205 | |||
206 | In addition, mere aggregation of another work not based on the Library | ||
207 | with the Library (or with a work based on the Library) on a volume of | ||
208 | a storage or distribution medium does not bring the other work under | ||
209 | the scope of this License. | ||
210 | |||
211 | 3. You may opt to apply the terms of the ordinary GNU General Public | ||
212 | License instead of this License to a given copy of the Library. To do | ||
213 | this, you must alter all the notices that refer to this License, so | ||
214 | that they refer to the ordinary GNU General Public License, version 2, | ||
215 | instead of to this License. (If a newer version than version 2 of the | ||
216 | ordinary GNU General Public License has appeared, then you can specify | ||
217 | that version instead if you wish.) Do not make any other change in | ||
218 | these notices. | ||
219 | |||
220 | Once this change is made in a given copy, it is irreversible for | ||
221 | that copy, so the ordinary GNU General Public License applies to all | ||
222 | subsequent copies and derivative works made from that copy. | ||
223 | |||
224 | This option is useful when you wish to copy part of the code of | ||
225 | the Library into a program that is not a library. | ||
226 | |||
227 | 4. You may copy and distribute the Library (or a portion or | ||
228 | derivative of it, under Section 2) in object code or executable form | ||
229 | under the terms of Sections 1 and 2 above provided that you accompany | ||
230 | it with the complete corresponding machine-readable source code, which | ||
231 | must be distributed under the terms of Sections 1 and 2 above on a | ||
232 | medium customarily used for software interchange. | ||
233 | |||
234 | If distribution of object code is made by offering access to copy | ||
235 | from a designated place, then offering equivalent access to copy the | ||
236 | source code from the same place satisfies the requirement to | ||
237 | distribute the source code, even though third parties are not | ||
238 | compelled to copy the source along with the object code. | ||
239 | |||
240 | 5. A program that contains no derivative of any portion of the | ||
241 | Library, but is designed to work with the Library by being compiled or | ||
242 | linked with it, is called a "work that uses the Library". Such a | ||
243 | work, in isolation, is not a derivative work of the Library, and | ||
244 | therefore falls outside the scope of this License. | ||
245 | |||
246 | However, linking a "work that uses the Library" with the Library | ||
247 | creates an executable that is a derivative of the Library (because it | ||
248 | contains portions of the Library), rather than a "work that uses the | ||
249 | library". The executable is therefore covered by this License. | ||
250 | Section 6 states terms for distribution of such executables. | ||
251 | |||
252 | When a "work that uses the Library" uses material from a header file | ||
253 | that is part of the Library, the object code for the work may be a | ||
254 | derivative work of the Library even though the source code is not. | ||
255 | Whether this is true is especially significant if the work can be | ||
256 | linked without the Library, or if the work is itself a library. The | ||
257 | threshold for this to be true is not precisely defined by law. | ||
258 | |||
259 | If such an object file uses only numerical parameters, data | ||
260 | structure layouts and accessors, and small macros and small inline | ||
261 | functions (ten lines or less in length), then the use of the object | ||
262 | file is unrestricted, regardless of whether it is legally a derivative | ||
263 | work. (Executables containing this object code plus portions of the | ||
264 | Library will still fall under Section 6.) | ||
265 | |||
266 | Otherwise, if the work is a derivative of the Library, you may | ||
267 | distribute the object code for the work under the terms of Section 6. | ||
268 | Any executables containing that work also fall under Section 6, | ||
269 | whether or not they are linked directly with the Library itself. | ||
270 | |||
271 | 6. As an exception to the Sections above, you may also combine or | ||
272 | link a "work that uses the Library" with the Library to produce a | ||
273 | work containing portions of the Library, and distribute that work | ||
274 | under terms of your choice, provided that the terms permit | ||
275 | modification of the work for the customer's own use and reverse | ||
276 | engineering for debugging such modifications. | ||
277 | |||
278 | You must give prominent notice with each copy of the work that the | ||
279 | Library is used in it and that the Library and its use are covered by | ||
280 | this License. You must supply a copy of this License. If the work | ||
281 | during execution displays copyright notices, you must include the | ||
282 | copyright notice for the Library among them, as well as a reference | ||
283 | directing the user to the copy of this License. Also, you must do one | ||
284 | of these things: | ||
285 | |||
286 | a) Accompany the work with the complete corresponding | ||
287 | machine-readable source code for the Library including whatever | ||
288 | changes were used in the work (which must be distributed under | ||
289 | Sections 1 and 2 above); and, if the work is an executable linked | ||
290 | with the Library, with the complete machine-readable "work that | ||
291 | uses the Library", as object code and/or source code, so that the | ||
292 | user can modify the Library and then relink to produce a modified | ||
293 | executable containing the modified Library. (It is understood | ||
294 | that the user who changes the contents of definitions files in the | ||
295 | Library will not necessarily be able to recompile the application | ||
296 | to use the modified definitions.) | ||
297 | |||
298 | b) Use a suitable shared library mechanism for linking with the | ||
299 | Library. A suitable mechanism is one that (1) uses at run time a | ||
300 | copy of the library already present on the user's computer system, | ||
301 | rather than copying library functions into the executable, and (2) | ||
302 | will operate properly with a modified version of the library, if | ||
303 | the user installs one, as long as the modified version is | ||
304 | interface-compatible with the version that the work was made with. | ||
305 | |||
306 | c) Accompany the work with a written offer, valid for at | ||
307 | least three years, to give the same user the materials | ||
308 | specified in Subsection 6a, above, for a charge no more | ||
309 | than the cost of performing this distribution. | ||
310 | |||
311 | d) If distribution of the work is made by offering access to copy | ||
312 | from a designated place, offer equivalent access to copy the above | ||
313 | specified materials from the same place. | ||
314 | |||
315 | e) Verify that the user has already received a copy of these | ||
316 | materials or that you have already sent this user a copy. | ||
317 | |||
318 | For an executable, the required form of the "work that uses the | ||
319 | Library" must include any data and utility programs needed for | ||
320 | reproducing the executable from it. However, as a special exception, | ||
321 | the materials to be distributed need not include anything that is | ||
322 | normally distributed (in either source or binary form) with the major | ||
323 | components (compiler, kernel, and so on) of the operating system on | ||
324 | which the executable runs, unless that component itself accompanies | ||
325 | the executable. | ||
326 | |||
327 | It may happen that this requirement contradicts the license | ||
328 | restrictions of other proprietary libraries that do not normally | ||
329 | accompany the operating system. Such a contradiction means you cannot | ||
330 | use both them and the Library together in an executable that you | ||
331 | distribute. | ||
332 | |||
333 | 7. You may place library facilities that are a work based on the | ||
334 | Library side-by-side in a single library together with other library | ||
335 | facilities not covered by this License, and distribute such a combined | ||
336 | library, provided that the separate distribution of the work based on | ||
337 | the Library and of the other library facilities is otherwise | ||
338 | permitted, and provided that you do these two things: | ||
339 | |||
340 | a) Accompany the combined library with a copy of the same work | ||
341 | based on the Library, uncombined with any other library | ||
342 | facilities. This must be distributed under the terms of the | ||
343 | Sections above. | ||
344 | |||
345 | b) Give prominent notice with the combined library of the fact | ||
346 | that part of it is a work based on the Library, and explaining | ||
347 | where to find the accompanying uncombined form of the same work. | ||
348 | |||
349 | 8. You may not copy, modify, sublicense, link with, or distribute | ||
350 | the Library except as expressly provided under this License. Any | ||
351 | attempt otherwise to copy, modify, sublicense, link with, or | ||
352 | distribute the Library is void, and will automatically terminate your | ||
353 | rights under this License. However, parties who have received copies, | ||
354 | or rights, from you under this License will not have their licenses | ||
355 | terminated so long as such parties remain in full compliance. | ||
356 | |||
357 | 9. You are not required to accept this License, since you have not | ||
358 | signed it. However, nothing else grants you permission to modify or | ||
359 | distribute the Library or its derivative works. These actions are | ||
360 | prohibited by law if you do not accept this License. Therefore, by | ||
361 | modifying or distributing the Library (or any work based on the | ||
362 | Library), you indicate your acceptance of this License to do so, and | ||
363 | all its terms and conditions for copying, distributing or modifying | ||
364 | the Library or works based on it. | ||
365 | |||
366 | 10. Each time you redistribute the Library (or any work based on the | ||
367 | Library), the recipient automatically receives a license from the | ||
368 | original licensor to copy, distribute, link with or modify the Library | ||
369 | subject to these terms and conditions. You may not impose any further | ||
370 | restrictions on the recipients' exercise of the rights granted herein. | ||
371 | You are not responsible for enforcing compliance by third parties with | ||
372 | this License. | ||
373 | |||
374 | 11. If, as a consequence of a court judgment or allegation of patent | ||
375 | infringement or for any other reason (not limited to patent issues), | ||
376 | conditions are imposed on you (whether by court order, agreement or | ||
377 | otherwise) that contradict the conditions of this License, they do not | ||
378 | excuse you from the conditions of this License. If you cannot | ||
379 | distribute so as to satisfy simultaneously your obligations under this | ||
380 | License and any other pertinent obligations, then as a consequence you | ||
381 | may not distribute the Library at all. For example, if a patent | ||
382 | license would not permit royalty-free redistribution of the Library by | ||
383 | all those who receive copies directly or indirectly through you, then | ||
384 | the only way you could satisfy both it and this License would be to | ||
385 | refrain entirely from distribution of the Library. | ||
386 | |||
387 | If any portion of this section is held invalid or unenforceable under any | ||
388 | particular circumstance, the balance of the section is intended to apply, | ||
389 | and the section as a whole is intended to apply in other circumstances. | ||
390 | |||
391 | It is not the purpose of this section to induce you to infringe any | ||
392 | patents or other property right claims or to contest validity of any | ||
393 | such claims; this section has the sole purpose of protecting the | ||
394 | integrity of the free software distribution system which is | ||
395 | implemented by public license practices. Many people have made | ||
396 | generous contributions to the wide range of software distributed | ||
397 | through that system in reliance on consistent application of that | ||
398 | system; it is up to the author/donor to decide if he or she is willing | ||
399 | to distribute software through any other system and a licensee cannot | ||
400 | impose that choice. | ||
401 | |||
402 | This section is intended to make thoroughly clear what is believed to | ||
403 | be a consequence of the rest of this License. | ||
404 | |||
405 | 12. If the distribution and/or use of the Library is restricted in | ||
406 | certain countries either by patents or by copyrighted interfaces, the | ||
407 | original copyright holder who places the Library under this License may add | ||
408 | an explicit geographical distribution limitation excluding those countries, | ||
409 | so that distribution is permitted only in or among countries not thus | ||
410 | excluded. In such case, this License incorporates the limitation as if | ||
411 | written in the body of this License. | ||
412 | |||
413 | 13. The Free Software Foundation may publish revised and/or new | ||
414 | versions of the Lesser General Public License from time to time. | ||
415 | Such new versions will be similar in spirit to the present version, | ||
416 | but may differ in detail to address new problems or concerns. | ||
417 | |||
418 | Each version is given a distinguishing version number. If the Library | ||
419 | specifies a version number of this License which applies to it and | ||
420 | "any later version", you have the option of following the terms and | ||
421 | conditions either of that version or of any later version published by | ||
422 | the Free Software Foundation. If the Library does not specify a | ||
423 | license version number, you may choose any version ever published by | ||
424 | the Free Software Foundation. | ||
425 | |||
426 | 14. If you wish to incorporate parts of the Library into other free | ||
427 | programs whose distribution conditions are incompatible with these, | ||
428 | write to the author to ask for permission. For software which is | ||
429 | copyrighted by the Free Software Foundation, write to the Free | ||
430 | Software Foundation; we sometimes make exceptions for this. Our | ||
431 | decision will be guided by the two goals of preserving the free status | ||
432 | of all derivatives of our free software and of promoting the sharing | ||
433 | and reuse of software generally. | ||
434 | |||
435 | NO WARRANTY | ||
436 | |||
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO | ||
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. | ||
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR | ||
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY | ||
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE | ||
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE | ||
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME | ||
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||
446 | |||
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN | ||
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY | ||
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU | ||
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR | ||
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE | ||
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | ||
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | ||
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | ||
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | ||
456 | DAMAGES. | ||
457 | |||
458 | END OF TERMS AND CONDITIONS | ||
459 | |||
460 | How to Apply These Terms to Your New Libraries | ||
461 | |||
462 | If you develop a new library, and you want it to be of the greatest | ||
463 | possible use to the public, we recommend making it free software that | ||
464 | everyone can redistribute and change. You can do so by permitting | ||
465 | redistribution under these terms (or, alternatively, under the terms of the | ||
466 | ordinary General Public License). | ||
467 | |||
468 | To apply these terms, attach the following notices to the library. It is | ||
469 | safest to attach them to the start of each source file to most effectively | ||
470 | convey the exclusion of warranty; and each file should have at least the | ||
471 | "copyright" line and a pointer to where the full notice is found. | ||
472 | |||
473 | <one line to give the library's name and a brief idea of what it does.> | ||
474 | Copyright (C) <year> <name of author> | ||
475 | |||
476 | This library is free software; you can redistribute it and/or | ||
477 | modify it under the terms of the GNU Lesser General Public | ||
478 | License as published by the Free Software Foundation; either | ||
479 | version 2 of the License, or (at your option) any later version. | ||
480 | |||
481 | This library is distributed in the hope that it will be useful, | ||
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
484 | Lesser General Public License for more details. | ||
485 | |||
486 | You should have received a copy of the GNU Lesser General Public | ||
487 | License along with this library; if not, write to the Free Software | ||
488 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
489 | |||
490 | Also add information on how to contact you by electronic and paper mail. | ||
491 | |||
492 | You should also get your employer (if you work as a programmer) or your | ||
493 | school, if any, to sign a "copyright disclaimer" for the library, if | ||
494 | necessary. Here is a sample; alter the names: | ||
495 | |||
496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the | ||
497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. | ||
498 | |||
499 | <signature of Ty Coon>, 1 April 1990 | ||
500 | Ty Coon, President of Vice | ||
501 | |||
502 | That's all there is to it! | ||
503 | |||
504 | |||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/README b/lib/rbcodec/codecs/libffmpegFLAC/README new file mode 100644 index 0000000000..9bc0f6ed8a --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/README | |||
@@ -0,0 +1,19 @@ | |||
1 | FFmpeg README | ||
2 | ------------- | ||
3 | |||
4 | 1) Documentation | ||
5 | ---------------- | ||
6 | |||
7 | * Read the documentation in the doc/ directory. | ||
8 | |||
9 | 2) Licensing | ||
10 | ------------ | ||
11 | |||
12 | * Read the file COPYING. ffmpeg and the associated libraries EXCEPT | ||
13 | liba52 and libpostproc are licensed under the Lesser GNU General | ||
14 | Public License. | ||
15 | |||
16 | * liba52 and libpostproc are distributed under the GNU General Public | ||
17 | License and their compilation and use is optional in ffmpeg. | ||
18 | |||
19 | Fabrice Bellard. \ No newline at end of file | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/README.rockbox b/lib/rbcodec/codecs/libffmpegFLAC/README.rockbox new file mode 100644 index 0000000000..850cdfcb7d --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/README.rockbox | |||
@@ -0,0 +1,46 @@ | |||
1 | Library: libffmpegFLAC | ||
2 | Imported: 2005-10-26 by Dave Chapman | ||
3 | |||
4 | This directory contains a FLAC decoder based on the flac.c (and a small | ||
5 | number of other files) from the ffmpeg project. | ||
6 | |||
7 | LICENSING INFORMATION | ||
8 | |||
9 | ffmpeg is licensed under the Lesser GNU General Public License and the | ||
10 | file flac.c is Copyright 2003 Alex Beregszaszi. | ||
11 | |||
12 | IMPORT DETAILS | ||
13 | |||
14 | The decoder is based on ffmpeg-cvs from 26 October 2005. | ||
15 | |||
16 | The file libavcodec/flac.c was renamed to decoder.c and all ffmpeg | ||
17 | related code was removed. It was also heavily modified to remove | ||
18 | debugging information and unused experiemental code. | ||
19 | |||
20 | It was also changed to provide output as 32-bit integers (with the | ||
21 | data left-shifted to 28 bit accuracy). The original flac.c provided | ||
22 | 16-bit output. | ||
23 | |||
24 | In order to minimise memory usage, a small number of hard-coded limits | ||
25 | are present in decoder.h - mainly limiting the supported blocksize | ||
26 | (number of samples in a frame) to 4608. This is the default value | ||
27 | used by the reference FLAC encoder at all standard compression | ||
28 | settings. | ||
29 | |||
30 | |||
31 | TESTING | ||
32 | |||
33 | A test program is contained in the file main.c and this should compile | ||
34 | in any Unix-like environment using the command "make -f Makefile.test". | ||
35 | |||
36 | Running "test file.flac" will decode the audio data to a WAV file | ||
37 | called "test.wav" in the current directory. This has been tested with | ||
38 | 16-bit and 24-bit mono and stereo FLAC files. | ||
39 | |||
40 | This can be used to test the accuracy of the decoder by comparing the | ||
41 | md5sum of the WAV file produced by this decoder with a WAV file | ||
42 | produced by the official libFLAC decoder. | ||
43 | |||
44 | This test program could be extended to perform an internal md5sum | ||
45 | calculation and comparing that against the md5sum stored in the FLAC | ||
46 | file's header. | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/SOURCES b/lib/rbcodec/codecs/libffmpegFLAC/SOURCES new file mode 100644 index 0000000000..63094b30a6 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/SOURCES | |||
@@ -0,0 +1,7 @@ | |||
1 | decoder.c | ||
2 | shndec.c | ||
3 | #if defined(CPU_COLDFIRE) | ||
4 | coldfire.S | ||
5 | #elif defined(CPU_ARM) | ||
6 | arm.S | ||
7 | #endif | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/arm.S b/lib/rbcodec/codecs/libffmpegFLAC/arm.S new file mode 100644 index 0000000000..8adca77ce5 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/arm.S | |||
@@ -0,0 +1,271 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Thom Johansen | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | |||
24 | /* The following is an assembler optimised version of the LPC filtering | ||
25 | routines needed for FLAC decoding. It is optimised for use with ARM | ||
26 | processors. | ||
27 | All LPC filtering up to order 9 is done in specially optimised unrolled | ||
28 | loops, while every order above this is handled by a slower default routine. | ||
29 | */ | ||
30 | #ifdef USE_IRAM | ||
31 | .section .icode,"ax",%progbits | ||
32 | #else | ||
33 | .text | ||
34 | #endif | ||
35 | .global lpc_decode_arm | ||
36 | lpc_decode_arm: | ||
37 | stmdb sp!, { r4-r11, lr } | ||
38 | ldr r4, [sp, #36] | ||
39 | /* r0 = blocksize, r1 = qlevel, r2 = pred_order | ||
40 | r3 = data, r4 = coeffs | ||
41 | */ | ||
42 | |||
43 | /* the data pointer always lags behind history pointer by 'pred_order' | ||
44 | samples. since we have one loop for each order, we can hard code this | ||
45 | and free a register by not saving data pointer. | ||
46 | */ | ||
47 | sub r3, r3, r2, lsl #2 @ r3 = history | ||
48 | cmp r0, #0 @ no samples to process | ||
49 | beq .exit | ||
50 | cmp r2, #9 @ check if order is too high for unrolled loops | ||
51 | addls pc, pc, r2, lsl #2 @ jump to our unrolled decode loop if it exists | ||
52 | @ jumptable: | ||
53 | b .default @ order too high, go to default routine | ||
54 | b .exit @ zero order filter isn't possible, exit function | ||
55 | b .order1 | ||
56 | b .order2 | ||
57 | b .order3 | ||
58 | b .order4 | ||
59 | b .order5 | ||
60 | b .order6 | ||
61 | b .order7 | ||
62 | b .order8 | ||
63 | |||
64 | @ last jump table entry coincides with target, so leave it out | ||
65 | .order9: | ||
66 | ldmia r4, { r5-r12, r14 } @ fetch coefs | ||
67 | .loop9: | ||
68 | ldr r4, [r3], #4 @ load first history sample | ||
69 | mul r2, r4, r14 @ multiply with last coef | ||
70 | ldr r4, [r3], #4 @ rinse and repeat while accumulating sum in r2 | ||
71 | mla r2, r4, r12, r2 | ||
72 | ldr r4, [r3], #4 | ||
73 | mla r2, r4, r11, r2 | ||
74 | ldr r4, [r3], #4 | ||
75 | mla r2, r4, r10, r2 | ||
76 | ldr r4, [r3], #4 | ||
77 | mla r2, r4, r9, r2 | ||
78 | ldr r4, [r3], #4 | ||
79 | mla r2, r4, r8, r2 | ||
80 | ldr r4, [r3], #4 | ||
81 | mla r2, r4, r7, r2 | ||
82 | ldr r4, [r3], #4 | ||
83 | mla r2, r4, r6, r2 | ||
84 | ldr r4, [r3], #4 | ||
85 | mla r2, r4, r5, r2 | ||
86 | ldr r4, [r3] @ r4 = residual | ||
87 | add r2, r4, r2, asr r1 @ shift sum by qlevel bits and add residual | ||
88 | str r2, [r3], #-8*4 @ save result and wrap history pointer back | ||
89 | subs r0, r0, #1 @ check if we're done | ||
90 | bne .loop9 @ nope, jump back | ||
91 | b .exit | ||
92 | |||
93 | .order8: | ||
94 | ldmia r4, { r5-r12 } | ||
95 | .loop8: | ||
96 | @ we have more registers to spare here, so start block reading | ||
97 | ldmia r3!, { r4, r14 } | ||
98 | mul r2, r4, r12 | ||
99 | mla r2, r14, r11, r2 | ||
100 | ldmia r3!, { r4, r14 } | ||
101 | mla r2, r4, r10, r2 | ||
102 | mla r2, r14, r9, r2 | ||
103 | ldmia r3!, { r4, r14 } | ||
104 | mla r2, r4, r8, r2 | ||
105 | mla r2, r14, r7, r2 | ||
106 | ldmia r3!, { r4, r14 } | ||
107 | mla r2, r4, r6, r2 | ||
108 | mla r2, r14, r5, r2 | ||
109 | ldr r4, [r3] | ||
110 | add r2, r4, r2, asr r1 | ||
111 | str r2, [r3], #-7*4 | ||
112 | subs r0, r0, #1 | ||
113 | bne .loop8 | ||
114 | b .exit | ||
115 | |||
116 | .order7: | ||
117 | ldmia r4, { r5-r11 } | ||
118 | .loop7: | ||
119 | ldmia r3!, { r4, r12, r14 } | ||
120 | mul r2, r4, r11 | ||
121 | mla r2, r12, r10, r2 | ||
122 | mla r2, r14, r9, r2 | ||
123 | ldmia r3!, { r4, r12, r14 } | ||
124 | mla r2, r4, r8, r2 | ||
125 | mla r2, r12, r7, r2 | ||
126 | mla r2, r14, r6, r2 | ||
127 | ldr r4, [r3], #4 | ||
128 | mla r2, r4, r5, r2 | ||
129 | ldr r4, [r3] | ||
130 | add r2, r4, r2, asr r1 | ||
131 | str r2, [r3], #-6*4 | ||
132 | subs r0, r0, #1 | ||
133 | bne .loop7 | ||
134 | b .exit | ||
135 | |||
136 | .order6: | ||
137 | ldmia r4, { r5-r10 } | ||
138 | .loop6: | ||
139 | ldmia r3!, { r4, r11-r12, r14 } | ||
140 | mul r2, r4, r10 | ||
141 | mla r2, r11, r9, r2 | ||
142 | mla r2, r12, r8, r2 | ||
143 | mla r2, r14, r7, r2 | ||
144 | ldmia r3!, { r4, r11 } | ||
145 | mla r2, r4, r6, r2 | ||
146 | mla r2, r11, r5, r2 | ||
147 | ldr r4, [r3] | ||
148 | add r2, r4, r2, asr r1 | ||
149 | str r2, [r3], #-5*4 | ||
150 | subs r0, r0, #1 | ||
151 | bne .loop6 | ||
152 | b .exit | ||
153 | |||
154 | .order5: | ||
155 | ldmia r4, { r5-r9 } | ||
156 | .loop5: | ||
157 | ldmia r3!, { r4, r10-r12, r14 } | ||
158 | mul r2, r4, r9 | ||
159 | mla r2, r10, r8, r2 | ||
160 | mla r2, r11, r7, r2 | ||
161 | mla r2, r12, r6, r2 | ||
162 | mla r2, r14, r5, r2 | ||
163 | ldr r4, [r3] | ||
164 | add r2, r4, r2, asr r1 | ||
165 | str r2, [r3], #-4*4 | ||
166 | subs r0, r0, #1 | ||
167 | bne .loop5 | ||
168 | b .exit | ||
169 | |||
170 | .order4: | ||
171 | ldmia r4, { r5-r8 } | ||
172 | .loop4: | ||
173 | ldmia r3!, { r4, r11-r12, r14 } | ||
174 | mul r2, r4, r8 | ||
175 | mla r2, r11, r7, r2 | ||
176 | mla r2, r12, r6, r2 | ||
177 | mla r2, r14, r5, r2 | ||
178 | ldr r4, [r3] | ||
179 | add r2, r4, r2, asr r1 | ||
180 | str r2, [r3], #-3*4 | ||
181 | subs r0, r0, #1 | ||
182 | bne .loop4 | ||
183 | b .exit | ||
184 | |||
185 | .order3: | ||
186 | ldmia r4, { r5-r7 } | ||
187 | .loop3: | ||
188 | ldmia r3!, { r4, r12, r14 } | ||
189 | mul r2, r4, r7 | ||
190 | mla r2, r12, r6, r2 | ||
191 | mla r2, r14, r5, r2 | ||
192 | ldr r4, [r3] | ||
193 | add r2, r4, r2, asr r1 | ||
194 | str r2, [r3], #-2*4 | ||
195 | subs r0, r0, #1 | ||
196 | bne .loop3 | ||
197 | b .exit | ||
198 | |||
199 | .order2: | ||
200 | ldmia r4, { r5-r6 } | ||
201 | .loop2: | ||
202 | ldmia r3!, { r4, r14 } | ||
203 | mul r2, r4, r6 | ||
204 | mla r2, r14, r5, r2 | ||
205 | ldr r4, [r3] | ||
206 | add r2, r4, r2, asr r1 | ||
207 | str r2, [r3], #-1*4 | ||
208 | subs r0, r0, #1 | ||
209 | bne .loop2 | ||
210 | b .exit | ||
211 | |||
212 | .order1: | ||
213 | ldr r5, [r4] @ load the one coef we need | ||
214 | ldr r4, [r3], #4 @ load one history sample, r3 now points to residual | ||
215 | .loop1: | ||
216 | mul r2, r4, r5 @ multiply coef by history sample | ||
217 | ldr r4, [r3] @ load residual | ||
218 | add r4, r4, r2, asr r1 @ add result to residual | ||
219 | str r4, [r3], #4 @ place r3 at next residual, we already have | ||
220 | subs r0, r0, #1 @ the current sample in r4 for the next iteration | ||
221 | bne .loop1 | ||
222 | b .exit | ||
223 | |||
224 | .default: | ||
225 | /* we do the filtering in an unrolled by 4 loop as far as we can, and then | ||
226 | do the rest by jump table. */ | ||
227 | add r5, r4, r2, lsl #2 @ need to start in the other end of coefs | ||
228 | mov r7, r2, lsr #2 @ r7 = coefs/4 | ||
229 | mov r14, #0 @ init accumulator | ||
230 | .dloop1: | ||
231 | ldmdb r5!, { r8-r11 } | ||
232 | ldmia r3!, { r6, r12 } | ||
233 | mla r14, r6, r11, r14 | ||
234 | mla r14, r12, r10, r14 | ||
235 | ldmia r3!, { r6, r12 } | ||
236 | mla r14, r6, r9, r14 | ||
237 | mla r14, r12, r8, r14 | ||
238 | subs r7, r7, #1 | ||
239 | bne .dloop1 | ||
240 | |||
241 | and r7, r2, #3 @ get remaining samples to be filtered | ||
242 | add pc, pc, r7, lsl #2 @ jump into accumulator chain | ||
243 | @ jumptable: | ||
244 | b .dsave @ padding | ||
245 | b .dsave | ||
246 | b .oneleft | ||
247 | b .twoleft | ||
248 | @ implicit .threeleft | ||
249 | ldr r12, [r5, #-4]! | ||
250 | ldr r8, [r3], #4 | ||
251 | mla r14, r12, r8, r14 | ||
252 | .twoleft: | ||
253 | ldr r12, [r5, #-4]! | ||
254 | ldr r8, [r3], #4 | ||
255 | mla r14, r12, r8, r14 | ||
256 | .oneleft: | ||
257 | ldr r12, [r5, #-4]! | ||
258 | ldr r8, [r3], #4 | ||
259 | mla r14, r12, r8, r14 | ||
260 | |||
261 | .dsave: | ||
262 | ldr r12, [r3] @ load residual | ||
263 | add r14, r12, r14, asr r1 @ shift sum by qlevel bits and add residual | ||
264 | str r14, [r3], #4 @ store result | ||
265 | sub r3, r3, r2, lsl #2 @ and wrap history pointer back to next first pos | ||
266 | subs r0, r0, #1 @ are we done? | ||
267 | bne .default @ no, prepare for next sample | ||
268 | |||
269 | .exit: | ||
270 | ldmpc regs=r4-r11 | ||
271 | |||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/arm.h b/lib/rbcodec/codecs/libffmpegFLAC/arm.h new file mode 100644 index 0000000000..39080d7f75 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/arm.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef _FLAC_ARM_H | ||
2 | #define _FLAC_ARM_H | ||
3 | |||
4 | #include "bitstream.h" | ||
5 | |||
6 | void lpc_decode_arm(int blocksize, int qlevel, int pred_order, int32_t* data, int* coeffs); | ||
7 | |||
8 | #endif | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/bitstream.h b/lib/rbcodec/codecs/libffmpegFLAC/bitstream.h new file mode 100644 index 0000000000..5fc3460c8e --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/bitstream.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /** | ||
2 | * @file bitstream.h | ||
3 | * bitstream api header. | ||
4 | */ | ||
5 | |||
6 | #ifndef BITSTREAM_H | ||
7 | #define BITSTREAM_H | ||
8 | |||
9 | #include <inttypes.h> | ||
10 | #include "ffmpeg_get_bits.h" | ||
11 | |||
12 | #ifndef BUILD_STANDALONE | ||
13 | #include <config.h> | ||
14 | #include <system.h> | ||
15 | #else | ||
16 | #include <stdio.h> | ||
17 | #define IBSS_ATTR | ||
18 | #define ICONST_ATTR | ||
19 | #define ICODE_ATTR | ||
20 | #endif | ||
21 | |||
22 | #if (CONFIG_CPU == MCF5250) || (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) | ||
23 | #define ICODE_ATTR_FLAC ICODE_ATTR | ||
24 | #define IBSS_ATTR_FLAC IBSS_ATTR | ||
25 | /* Enough IRAM to move additional data to it. */ | ||
26 | #define IBSS_ATTR_FLAC_LARGE_IRAM IBSS_ATTR | ||
27 | #define IBSS_ATTR_FLAC_XLARGE_IRAM | ||
28 | |||
29 | #elif defined(CPU_S5L870X) | ||
30 | #define ICODE_ATTR_FLAC ICODE_ATTR | ||
31 | #define IBSS_ATTR_FLAC IBSS_ATTR | ||
32 | /* Enough IRAM to move even more additional data to it. */ | ||
33 | #define IBSS_ATTR_FLAC_LARGE_IRAM IBSS_ATTR | ||
34 | #define IBSS_ATTR_FLAC_XLARGE_IRAM IBSS_ATTR | ||
35 | |||
36 | #else | ||
37 | #define ICODE_ATTR_FLAC ICODE_ATTR | ||
38 | #define IBSS_ATTR_FLAC IBSS_ATTR | ||
39 | /* Not enough IRAM available. */ | ||
40 | #define IBSS_ATTR_FLAC_LARGE_IRAM | ||
41 | #define IBSS_ATTR_FLAC_XLARGE_IRAM | ||
42 | #endif | ||
43 | |||
44 | /* Endian conversion routines for standalone compilation */ | ||
45 | #ifdef BUILD_STANDALONE | ||
46 | #ifdef BUILD_BIGENDIAN | ||
47 | #define betoh32(x) (x) | ||
48 | #define letoh32(x) swap32(x) | ||
49 | #else | ||
50 | #define letoh32(x) (x) | ||
51 | #define betoh32(x) swap32(x) | ||
52 | #endif | ||
53 | |||
54 | /* Taken from rockbox/firmware/export/system.h */ | ||
55 | |||
56 | static inline unsigned short swap16(unsigned short value) | ||
57 | /* | ||
58 | result[15..8] = value[ 7..0]; | ||
59 | result[ 7..0] = value[15..8]; | ||
60 | */ | ||
61 | { | ||
62 | return (value >> 8) | (value << 8); | ||
63 | } | ||
64 | |||
65 | static inline unsigned long swap32(unsigned long value) | ||
66 | /* | ||
67 | result[31..24] = value[ 7.. 0]; | ||
68 | result[23..16] = value[15.. 8]; | ||
69 | result[15.. 8] = value[23..16]; | ||
70 | result[ 7.. 0] = value[31..24]; | ||
71 | */ | ||
72 | { | ||
73 | unsigned long hi = swap16(value >> 16); | ||
74 | unsigned long lo = swap16(value & 0xffff); | ||
75 | return (lo << 16) | hi; | ||
76 | } | ||
77 | #endif | ||
78 | |||
79 | #endif /* BITSTREAM_H */ | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/coldfire.S b/lib/rbcodec/codecs/libffmpegFLAC/coldfire.S new file mode 100644 index 0000000000..efbb907874 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/coldfire.S | |||
@@ -0,0 +1,535 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Thom Johansen | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | /* The following are assembler optimised version of the LPC filtering | ||
23 | routines needed for FLAC decoding. They is optimised for use with the | ||
24 | MCF5249 processor, or any other similar ColdFire core with the EMAC unit. | ||
25 | */ | ||
26 | |||
27 | /* This routine deals with sample widths 16 and lower. All LPC filtering up to | ||
28 | order 10 is done in specially optimised unrolled loops, while every order | ||
29 | above this is handled by a slower default routine. | ||
30 | */ | ||
31 | .section .icode,"ax",@progbits | ||
32 | .global lpc_decode_emac | ||
33 | .align 2 | ||
34 | lpc_decode_emac: | ||
35 | lea.l (-44, %sp), %sp | ||
36 | movem.l %d2-%d7/%a2-%a6, (%sp) | ||
37 | movem.l (44+4, %sp), %d0-%d2/%a0-%a1 | ||
38 | /* d0 = blocksize, d1 = qlevel, d2 = pred_order | ||
39 | a0 = data, a1 = coeffs | ||
40 | */ | ||
41 | |||
42 | /* the data pointer always lags behind history pointer by 'pred_order' | ||
43 | samples. since we have one loop for each order, we can hard code this | ||
44 | and free a register by not saving data pointer. | ||
45 | */ | ||
46 | move.l %d2, %d3 | ||
47 | neg.l %d3 | ||
48 | lea.l (%a0, %d3.l*4), %a0 | history | ||
49 | clr.l %d3 | ||
50 | move.l %d3, %macsr | we'll need integer mode for this | ||
51 | tst.l %d0 | ||
52 | jeq .exit | zero samples to process, exit | ||
53 | moveq.l #10, %d3 | ||
54 | cmp.l %d3, %d2 | ||
55 | jgt .default | order is over 10, jump to default case | ||
56 | jmp.l (2, %pc, %d2.l*4) | jump to loop corresponding to pred_order | ||
57 | | jumptable: | ||
58 | bra.w .exit | zero order filter isn't possible, exit function | ||
59 | bra.w .order1 | ||
60 | bra.w .order2 | ||
61 | bra.w .order3 | ||
62 | bra.w .order4 | ||
63 | bra.w .order5 | ||
64 | bra.w .order6 | ||
65 | bra.w .order7 | ||
66 | bra.w .order8 | ||
67 | bra.w .order9 | ||
68 | |||
69 | | last jump table entry coincides with target, so leave it out | ||
70 | .order10: | ||
71 | movem.l (%a1), %d3-%d7/%a1-%a5 | load lpc coefs | ||
72 | move.l (%a0)+, %a6 | load first history sample | ||
73 | 1: | ||
74 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
75 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
76 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
77 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
78 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
79 | mac.l %a6, %d7, (%a0)+, %a6, %acc0 | ||
80 | mac.l %a6, %d6, (%a0)+, %a6, %acc0 | ||
81 | mac.l %a6, %d5, (%a0)+, %a6, %acc0 | ||
82 | mac.l %a6, %d4, (%a0)+, %a6, %acc0 | ||
83 | mac.l %a6, %d3, (-9*4, %a0), %a6, %acc0 | load for the next iteration | ||
84 | movclr.l %acc0, %d2 | get sum | ||
85 | asr.l %d1, %d2 | shift sum by qlevel bits | ||
86 | add.l %d2, (%a0) | add residual and save | ||
87 | lea.l (-8*4, %a0), %a0 | point history back at second element | ||
88 | subq.l #1, %d0 | decrement sample count | ||
89 | jne 1b | are we done? | ||
90 | jra .exit | ||
91 | |||
92 | .order9: | ||
93 | movem.l (%a1), %d4-%d7/%a1-%a5 | ||
94 | move.l (%a0)+, %a6 | ||
95 | 1: | ||
96 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
97 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
98 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
99 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
100 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
101 | mac.l %a6, %d7, (%a0)+, %a6, %acc0 | ||
102 | mac.l %a6, %d6, (%a0)+, %a6, %acc0 | ||
103 | mac.l %a6, %d5, (%a0)+, %a6, %acc0 | ||
104 | mac.l %a6, %d4, (-8*4, %a0), %a6, %acc0 | ||
105 | movclr.l %acc0, %d2 | ||
106 | asr.l %d1, %d2 | ||
107 | add.l %d2, (%a0) | ||
108 | lea.l (-7*4, %a0), %a0 | ||
109 | subq.l #1, %d0 | ||
110 | jne 1b | ||
111 | jra .exit | ||
112 | |||
113 | .order8: | ||
114 | movem.l (%a1), %d5-%d7/%a1-%a5 | ||
115 | move.l (%a0)+, %a6 | ||
116 | 1: | ||
117 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
118 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
119 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
120 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
121 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
122 | mac.l %a6, %d7, (%a0)+, %a6, %acc0 | ||
123 | mac.l %a6, %d6, (%a0)+, %a6, %acc0 | ||
124 | mac.l %a6, %d5, (-7*4, %a0), %a6, %acc0 | ||
125 | movclr.l %acc0, %d2 | ||
126 | asr.l %d1, %d2 | ||
127 | add.l %d2, (%a0) | ||
128 | lea.l (-6*4, %a0), %a0 | ||
129 | subq.l #1, %d0 | ||
130 | jne 1b | ||
131 | jra .exit | ||
132 | |||
133 | .order7: | ||
134 | movem.l (%a1), %d6-%d7/%a1-%a5 | ||
135 | move.l (%a0)+, %a6 | ||
136 | 1: | ||
137 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
138 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
139 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
140 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
141 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
142 | mac.l %a6, %d7, (%a0)+, %a6, %acc0 | ||
143 | mac.l %a6, %d6, (-6*4, %a0), %a6, %acc0 | ||
144 | movclr.l %acc0, %d2 | ||
145 | asr.l %d1, %d2 | ||
146 | add.l %d2, (%a0) | ||
147 | lea.l (-5*4, %a0), %a0 | ||
148 | subq.l #1, %d0 | ||
149 | jne 1b | ||
150 | jra .exit | ||
151 | |||
152 | .order6: | ||
153 | movem.l (%a1), %d7/%a1-%a5 | ||
154 | move.l (%a0)+, %a6 | ||
155 | 1: | ||
156 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
157 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
158 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
159 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
160 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
161 | mac.l %a6, %d7, (-5*4, %a0), %a6, %acc0 | ||
162 | movclr.l %acc0, %d2 | ||
163 | asr.l %d1, %d2 | ||
164 | add.l %d2, (%a0) | ||
165 | lea.l (-4*4, %a0), %a0 | ||
166 | subq.l #1, %d0 | ||
167 | jne 1b | ||
168 | jra .exit | ||
169 | |||
170 | .order5: | ||
171 | movem.l (%a1), %a1-%a5 | ||
172 | move.l (%a0)+, %a6 | ||
173 | 1: | ||
174 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
175 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
176 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
177 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
178 | mac.l %a6, %a1, (-4*4, %a0), %a6, %acc0 | ||
179 | movclr.l %acc0, %d2 | ||
180 | asr.l %d1, %d2 | ||
181 | add.l %d2, (%a0) | ||
182 | lea.l (-3*4, %a0), %a0 | ||
183 | subq.l #1, %d0 | ||
184 | jne 1b | ||
185 | jra .exit | ||
186 | |||
187 | .order4: | ||
188 | movem.l (%a1), %a2-%a5 | ||
189 | move.l (%a0)+, %a6 | ||
190 | 1: | ||
191 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
192 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
193 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
194 | mac.l %a6, %a2, (-3*4, %a0), %a6, %acc0 | ||
195 | movclr.l %acc0, %d2 | ||
196 | asr.l %d1, %d2 | ||
197 | add.l %d2, (%a0) | ||
198 | subq.l #8, %a0 | ||
199 | subq.l #1, %d0 | ||
200 | jne 1b | ||
201 | jra .exit | ||
202 | |||
203 | .order3: | ||
204 | movem.l (%a1), %a3-%a5 | ||
205 | move.l (%a0)+, %a6 | ||
206 | 1: | ||
207 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
208 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
209 | mac.l %a6, %a3, (-2*4, %a0), %a6, %acc0 | ||
210 | movclr.l %acc0, %d2 | ||
211 | asr.l %d1, %d2 | ||
212 | add.l %d2, (%a0) | ||
213 | subq.l #4, %a0 | ||
214 | subq.l #1, %d0 | ||
215 | jne 1b | ||
216 | jra .exit | ||
217 | |||
218 | .order2: | ||
219 | movem.l (%a1), %a4-%a5 | ||
220 | move.l (%a0)+, %a6 | ||
221 | 1: | ||
222 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
223 | mac.l %a6, %a4, %acc0 | data for next iteration is already loaded | ||
224 | movclr.l %acc0, %d2 | ||
225 | asr.l %d1, %d2 | ||
226 | add.l %d2, (%a0) | ||
227 | subq.l #1, %d0 | ||
228 | jne 1b | ||
229 | jra .exit | ||
230 | |||
231 | .order1: | ||
232 | | no point in using mac here | ||
233 | move.l (%a1), %a5 | ||
234 | 1: | ||
235 | move.l %a5, %d2 | ||
236 | muls.l (%a0)+, %d2 | ||
237 | asr.l %d1, %d2 | ||
238 | add.l %d2, (%a0) | ||
239 | subq.l #1, %d0 | ||
240 | jne 1b | ||
241 | jra .exit | ||
242 | |||
243 | .default: | ||
244 | /* we do the filtering in an unrolled by 4 loop as far as we can, and then | ||
245 | do the rest by jump table. */ | ||
246 | lea.l (%a1, %d2.l*4), %a2 | need to start in the other end of coefs | ||
247 | move.l %a0, %a3 | working copy of history pointer | ||
248 | move.l %d2, %d3 | ||
249 | lsr.l #2, %d3 | coefs/4, num of iterations needed in next loop | ||
250 | move.l (%a3)+, %a5 | preload data for loop | ||
251 | 1: | ||
252 | lea.l (-4*4, %a2), %a2 | move lpc coef pointer four samples backwards | ||
253 | movem.l (%a2), %d4-%d7 | load four coefs | ||
254 | mac.l %a5, %d7, (%a3)+, %a5, %acc0 | ||
255 | mac.l %a5, %d6, (%a3)+, %a5, %acc0 | ||
256 | mac.l %a5, %d5, (%a3)+, %a5, %acc0 | ||
257 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
258 | subq.l #1, %d3 | any more unrolled loop operations left? | ||
259 | jne 1b | ||
260 | |||
261 | moveq.l #3, %d3 | mask 0x00000003 | ||
262 | and.l %d2, %d3 | get the remaining samples to be filtered | ||
263 | jmp.l (2, %pc, %d3*2) | then jump into mac.l chain | ||
264 | | jumptable: | ||
265 | bra.b 3f | none left | ||
266 | bra.b 2f | one left | ||
267 | bra.b 1f | two left | ||
268 | | three left | ||
269 | move.l -(%a2), %d4 | ||
270 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
271 | 1: | ||
272 | move.l -(%a2), %d4 | ||
273 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
274 | 2: | ||
275 | move.l -(%a2), %d4 | ||
276 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
277 | 3: | ||
278 | movclr.l %acc0, %d3 | get result | ||
279 | asr.l %d1, %d3 | shift qlevel bits right | ||
280 | add.l %a5, %d3 | add residual, which is in a5 by now | ||
281 | move.l %d3, -(%a3) | save, a3 is also one past save location | ||
282 | addq.l #4, %a0 | increment history pointer | ||
283 | subq.l #1, %d0 | decrement sample count | ||
284 | jne .default | are we done? | ||
285 | jra .exit | if so, fall through to exit | ||
286 | |||
287 | |||
288 | /* This routine deals with sample widths 24 and lower. All LPC filtering up to | ||
289 | order 8 is done in specially optimised unrolled loops, while every order | ||
290 | above this is handled by a slower default routine. | ||
291 | */ | ||
292 | .global lpc_decode_emac_wide | ||
293 | .align 2 | ||
294 | lpc_decode_emac_wide: | ||
295 | lea.l (-44, %sp), %sp | ||
296 | movem.l %d2-%d7/%a2-%a6, (%sp) | ||
297 | movem.l (44+4, %sp), %d0-%d1/%d3/%a0-%a1 | ||
298 | /* d0 = blocksize, d1 = qlevel, d3 = pred_order | ||
299 | a0 = data, a1 = coeffs | ||
300 | */ | ||
301 | |||
302 | /* the data pointer always lags behind history pointer by 'pred_order' | ||
303 | samples. since we have one loop for each order, we can hard code this | ||
304 | and free a register by not saving data pointer. | ||
305 | */ | ||
306 | move.l %d3, %d2 | ||
307 | neg.l %d2 | ||
308 | lea.l (%a0, %d2.l*4), %a0 | history | ||
309 | clr.l %d2 | ||
310 | move.l %d2, %macsr | we'll need integer mode for this | ||
311 | tst.l %d0 | ||
312 | jeq .exit | zero samples to process, exit | ||
313 | moveq.l #32, %d2 | ||
314 | sub.l %d1, %d2 | calculate shift amount for extension byte | ||
315 | moveq.l #8, %d4 | ||
316 | cmp.l %d4, %d3 | ||
317 | jgt .wdefault | order is over 8, jump to default case | ||
318 | jmp.l (2, %pc, %d3.l*4) | jump to loop corresponding to pred_order | ||
319 | | jumptable: | ||
320 | bra.w .exit | zero order filter isn't possible, exit function | ||
321 | bra.w .worder1 | ||
322 | bra.w .worder2 | ||
323 | bra.w .worder3 | ||
324 | bra.w .worder4 | ||
325 | bra.w .worder5 | ||
326 | bra.w .worder6 | ||
327 | bra.w .worder7 | ||
328 | |||
329 | | last jump table entry coincides with target, so leave it out | ||
330 | .worder8: | ||
331 | movem.l (%a1), %d5-%d7/%a1-%a5 | load lpc coefs | ||
332 | move.l (%a0)+, %a6 | load first history sample | ||
333 | 1: | ||
334 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
335 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
336 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
337 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
338 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
339 | mac.l %a6, %d7, (%a0)+, %a6, %acc0 | ||
340 | mac.l %a6, %d6, (%a0)+, %a6, %acc0 | ||
341 | mac.l %a6, %d5, (-7*4, %a0), %a6, %acc0 | load for the next iteration | ||
342 | move.l %accext01, %d4 | get top 8 bits of sum | ||
343 | movclr.l %acc0, %d3 | then botten 32 bits | ||
344 | lsr.l %d1, %d3 | shift bottom bits qlevel bits right | ||
345 | asl.l %d2, %d4 | shift top bits 32 - qlevel bits left | ||
346 | or.l %d4, %d3 | now combine results | ||
347 | add.l %d3, (%a0) | add residual and save | ||
348 | lea.l (-6*4, %a0), %a0 | point history back at second element | ||
349 | subq.l #1, %d0 | decrement sample count | ||
350 | jne 1b | are we done? | ||
351 | jra .exit | ||
352 | |||
353 | .worder7: | ||
354 | movem.l (%a1), %d6-%d7/%a1-%a5 | ||
355 | move.l (%a0)+, %a6 | ||
356 | 1: | ||
357 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
358 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
359 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
360 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
361 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
362 | mac.l %a6, %d7, (%a0)+, %a6, %acc0 | ||
363 | mac.l %a6, %d6, (-6*4, %a0), %a6, %acc0 | ||
364 | move.l %accext01, %d4 | ||
365 | movclr.l %acc0, %d3 | ||
366 | lsr.l %d1, %d3 | ||
367 | asl.l %d2, %d4 | ||
368 | or.l %d4, %d3 | ||
369 | add.l %d3, (%a0) | ||
370 | lea.l (-5*4, %a0), %a0 | ||
371 | subq.l #1, %d0 | ||
372 | jne 1b | ||
373 | jra .exit | ||
374 | |||
375 | .worder6: | ||
376 | movem.l (%a1), %d7/%a1-%a5 | ||
377 | move.l (%a0)+, %a6 | ||
378 | 1: | ||
379 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
380 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
381 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
382 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
383 | mac.l %a6, %a1, (%a0)+, %a6, %acc0 | ||
384 | mac.l %a6, %d7, (-5*4, %a0), %a6, %acc0 | ||
385 | move.l %accext01, %d4 | ||
386 | movclr.l %acc0, %d3 | ||
387 | lsr.l %d1, %d3 | ||
388 | asl.l %d2, %d4 | ||
389 | or.l %d4, %d3 | ||
390 | add.l %d3, (%a0) | ||
391 | lea.l (-4*4, %a0), %a0 | ||
392 | subq.l #1, %d0 | ||
393 | jne 1b | ||
394 | jra .exit | ||
395 | |||
396 | .worder5: | ||
397 | movem.l (%a1), %a1-%a5 | ||
398 | move.l (%a0)+, %a6 | ||
399 | 1: | ||
400 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
401 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
402 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
403 | mac.l %a6, %a2, (%a0)+, %a6, %acc0 | ||
404 | mac.l %a6, %a1, (-4*4, %a0), %a6, %acc0 | ||
405 | move.l %accext01, %d4 | ||
406 | movclr.l %acc0, %d3 | ||
407 | lsr.l %d1, %d3 | ||
408 | asl.l %d2, %d4 | ||
409 | or.l %d4, %d3 | ||
410 | add.l %d3, (%a0) | ||
411 | lea.l (-3*4, %a0), %a0 | ||
412 | subq.l #1, %d0 | ||
413 | jne 1b | ||
414 | jra .exit | ||
415 | |||
416 | .worder4: | ||
417 | movem.l (%a1), %a2-%a5 | ||
418 | move.l (%a0)+, %a6 | ||
419 | 1: | ||
420 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
421 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
422 | mac.l %a6, %a3, (%a0)+, %a6, %acc0 | ||
423 | mac.l %a6, %a2, (-3*4, %a0), %a6, %acc0 | ||
424 | move.l %accext01, %d4 | ||
425 | movclr.l %acc0, %d3 | ||
426 | lsr.l %d1, %d3 | ||
427 | asl.l %d2, %d4 | ||
428 | or.l %d4, %d3 | ||
429 | add.l %d3, (%a0) | ||
430 | subq.l #8, %a0 | ||
431 | subq.l #1, %d0 | ||
432 | jne 1b | ||
433 | jra .exit | ||
434 | |||
435 | .worder3: | ||
436 | movem.l (%a1), %a3-%a5 | ||
437 | move.l (%a0)+, %a6 | ||
438 | 1: | ||
439 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
440 | mac.l %a6, %a4, (%a0)+, %a6, %acc0 | ||
441 | mac.l %a6, %a3, (-2*4, %a0), %a6, %acc0 | ||
442 | move.l %accext01, %d4 | ||
443 | movclr.l %acc0, %d3 | ||
444 | lsr.l %d1, %d3 | ||
445 | asl.l %d2, %d4 | ||
446 | or.l %d4, %d3 | ||
447 | add.l %d3, (%a0) | ||
448 | subq.l #4, %a0 | ||
449 | subq.l #1, %d0 | ||
450 | jne 1b | ||
451 | jra .exit | ||
452 | |||
453 | .worder2: | ||
454 | movem.l (%a1), %a4-%a5 | ||
455 | move.l (%a0)+, %a6 | ||
456 | 1: | ||
457 | mac.l %a6, %a5, (%a0)+, %a6, %acc0 | ||
458 | mac.l %a6, %a4, %acc0 | data for next iteration is already loaded | ||
459 | move.l %accext01, %d4 | ||
460 | movclr.l %acc0, %d3 | ||
461 | lsr.l %d1, %d3 | ||
462 | asl.l %d2, %d4 | ||
463 | or.l %d4, %d3 | ||
464 | add.l %d3, (%a0) | ||
465 | subq.l #1, %d0 | ||
466 | jne 1b | ||
467 | jra .exit | ||
468 | |||
469 | .worder1: | ||
470 | move.l (%a1), %a5 | ||
471 | move.l (%a0)+, %a6 | ||
472 | 1: | ||
473 | mac.l %a6, %a5, (%a0), %a6, %acc0 | ||
474 | move.l %accext01, %d4 | ||
475 | movclr.l %acc0, %d3 | ||
476 | lsr.l %d1, %d3 | ||
477 | asl.l %d2, %d4 | ||
478 | or.l %d4, %d3 | ||
479 | add.l %a6, %d3 | residual is already in a6 | ||
480 | move.l %d3, (%a0)+ | ||
481 | subq.l #1, %d0 | ||
482 | jne 1b | ||
483 | jra .exit | ||
484 | |||
485 | .wdefault: | ||
486 | /* we do the filtering in an unrolled by 4 loop as far as we can, and then | ||
487 | do the rest by jump table. */ | ||
488 | lea.l (%a1, %d3.l*4), %a2 | need to start in the other end of coefs | ||
489 | move.l %a0, %a3 | working copy of history pointer | ||
490 | move.l %d3, %d4 | ||
491 | lsr.l #2, %d4 | coefs/4, num of iterations needed in next loop | ||
492 | move.l (%a3)+, %a5 | preload data for loop | ||
493 | 1: | ||
494 | lea.l (-4*4, %a2), %a2 | move lpc coef pointer four samples backwards | ||
495 | movem.l (%a2), %d5-%d7/%a4 | load four coefs | ||
496 | mac.l %a5, %a4, (%a3)+, %a5, %acc0 | ||
497 | mac.l %a5, %d7, (%a3)+, %a5, %acc0 | ||
498 | mac.l %a5, %d6, (%a3)+, %a5, %acc0 | ||
499 | mac.l %a5, %d5, (%a3)+, %a5, %acc0 | ||
500 | subq.l #1, %d4 | any more unrolled loop operations left? | ||
501 | jne 1b | ||
502 | |||
503 | moveq.l #3, %d4 | mask 0x00000003 | ||
504 | and.l %d3, %d4 | get the remaining samples to be filtered | ||
505 | jmp.l (2, %pc, %d4*2) | then jump into mac.l chain | ||
506 | | jumptable: | ||
507 | bra.b 3f | none left | ||
508 | bra.b 2f | one left | ||
509 | bra.b 1f | two left | ||
510 | | three left | ||
511 | move.l -(%a2), %d4 | ||
512 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
513 | 1: | ||
514 | move.l -(%a2), %d4 | ||
515 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
516 | 2: | ||
517 | move.l -(%a2), %d4 | ||
518 | mac.l %a5, %d4, (%a3)+, %a5, %acc0 | ||
519 | 3: | ||
520 | move.l %accext01, %d5 | get high 32 bits of result | ||
521 | movclr.l %acc0, %d4 | get low 32 bits of result | ||
522 | lsr.l %d1, %d4 | shift qlevel bits right | ||
523 | asl.l %d2, %d5 | shift 32 - qlevel bits left | ||
524 | or.l %d5, %d4 | combine top and low bits after shift | ||
525 | add.l %a5, %d4 | add residual, which is in a5 by now | ||
526 | move.l %d4, -(%a3) | save, a3 is also one past save location | ||
527 | addq.l #4, %a0 | increment history pointer | ||
528 | subq.l #1, %d0 | decrement sample count | ||
529 | jne .wdefault | are we done? | ||
530 | | if so, fall through to exit | ||
531 | |||
532 | .exit: | ||
533 | movem.l (%sp), %d2-%d7/%a2-%a6 | ||
534 | lea.l (44, %sp), %sp | ||
535 | rts | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/coldfire.h b/lib/rbcodec/codecs/libffmpegFLAC/coldfire.h new file mode 100644 index 0000000000..d6f0996935 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/coldfire.h | |||
@@ -0,0 +1,11 @@ | |||
1 | #ifndef _FLAC_COLDFIRE_H | ||
2 | #define _FLAC_COLDFIRE_H | ||
3 | |||
4 | #include "bitstream.h" | ||
5 | |||
6 | void lpc_decode_emac(int blocksize, int qlevel, int pred_order, int32_t* data, | ||
7 | int* coeffs); | ||
8 | void lpc_decode_emac_wide(int blocksize, int qlevel, int pred_order, | ||
9 | int32_t* data, int* coeffs); | ||
10 | |||
11 | #endif | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/decoder.c b/lib/rbcodec/codecs/libffmpegFLAC/decoder.c new file mode 100644 index 0000000000..2e92c4b90d --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/decoder.c | |||
@@ -0,0 +1,627 @@ | |||
1 | /* | ||
2 | * FLAC (Free Lossless Audio Codec) decoder | ||
3 | * Copyright (c) 2003 Alex Beregszaszi | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file flac.c | ||
22 | * FLAC (Free Lossless Audio Codec) decoder | ||
23 | * @author Alex Beregszaszi | ||
24 | * | ||
25 | * For more information on the FLAC format, visit: | ||
26 | * http://flac.sourceforge.net/ | ||
27 | * | ||
28 | * This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed | ||
29 | * through, starting from the initial 'fLaC' signature; or by passing the | ||
30 | * 34-byte streaminfo structure through avctx->extradata[_size] followed | ||
31 | * by data starting with the 0xFFF8 marker. | ||
32 | */ | ||
33 | |||
34 | #include <inttypes.h> | ||
35 | #include <stdbool.h> | ||
36 | #ifndef BUILD_STANDALONE | ||
37 | #include "codeclib.h" | ||
38 | #endif | ||
39 | |||
40 | #include "bitstream.h" | ||
41 | #include "golomb.h" | ||
42 | |||
43 | #include "decoder.h" | ||
44 | |||
45 | #if defined(CPU_COLDFIRE) | ||
46 | #include "coldfire.h" | ||
47 | #elif defined(CPU_ARM) | ||
48 | #include "arm.h" | ||
49 | #endif | ||
50 | |||
51 | static const int sample_rate_table[] ICONST_ATTR = | ||
52 | { 0, 88200, 176400, 192000, | ||
53 | 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, | ||
54 | 0, 0, 0, 0 }; | ||
55 | |||
56 | static const int sample_size_table[] ICONST_ATTR = | ||
57 | { 0, 8, 12, 0, 16, 20, 24, 0 }; | ||
58 | |||
59 | static const int blocksize_table[] ICONST_ATTR = { | ||
60 | 0, 192, 576<<0, 576<<1, 576<<2, 576<<3, 0, 0, | ||
61 | 256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7 | ||
62 | }; | ||
63 | |||
64 | static const uint8_t table_crc8[256] ICONST_ATTR = { | ||
65 | 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, | ||
66 | 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, | ||
67 | 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, | ||
68 | 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, | ||
69 | 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, | ||
70 | 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, | ||
71 | 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, | ||
72 | 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, | ||
73 | 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, | ||
74 | 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea, | ||
75 | 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, | ||
76 | 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, | ||
77 | 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, | ||
78 | 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, | ||
79 | 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, | ||
80 | 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, | ||
81 | 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, | ||
82 | 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, | ||
83 | 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, | ||
84 | 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4, | ||
85 | 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, | ||
86 | 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, | ||
87 | 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, | ||
88 | 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, | ||
89 | 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, | ||
90 | 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, | ||
91 | 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, | ||
92 | 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, | ||
93 | 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, | ||
94 | 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, | ||
95 | 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, | ||
96 | 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 | ||
97 | }; | ||
98 | |||
99 | static int64_t get_utf8(GetBitContext *gb) ICODE_ATTR_FLAC; | ||
100 | static int64_t get_utf8(GetBitContext *gb) | ||
101 | { | ||
102 | uint64_t val; | ||
103 | int ones=0, bytes; | ||
104 | |||
105 | while(get_bits1(gb)) | ||
106 | ones++; | ||
107 | |||
108 | if (ones==0) bytes=0; | ||
109 | else if(ones==1) return -1; | ||
110 | else bytes= ones - 1; | ||
111 | |||
112 | val= get_bits(gb, 7-ones); | ||
113 | while(bytes--){ | ||
114 | const int tmp = get_bits(gb, 8); | ||
115 | |||
116 | if((tmp>>6) != 2) | ||
117 | return -2; | ||
118 | val<<=6; | ||
119 | val|= tmp&0x3F; | ||
120 | } | ||
121 | return val; | ||
122 | } | ||
123 | |||
124 | static int get_crc8(const uint8_t *buf, int count) ICODE_ATTR_FLAC; | ||
125 | static int get_crc8(const uint8_t *buf, int count) | ||
126 | { | ||
127 | int crc=0; | ||
128 | int i; | ||
129 | |||
130 | for(i=0; i<count; i++){ | ||
131 | crc = table_crc8[crc ^ buf[i]]; | ||
132 | } | ||
133 | |||
134 | return crc; | ||
135 | } | ||
136 | |||
137 | static int decode_residuals(FLACContext *s, int32_t* decoded, int pred_order) ICODE_ATTR_FLAC; | ||
138 | static int decode_residuals(FLACContext *s, int32_t* decoded, int pred_order) | ||
139 | { | ||
140 | int i, tmp, partition, method_type, rice_order; | ||
141 | int sample = 0, samples; | ||
142 | |||
143 | method_type = get_bits(&s->gb, 2); | ||
144 | if (method_type > 1){ | ||
145 | //fprintf(stderr,"illegal residual coding method %d\n", method_type); | ||
146 | return -3; | ||
147 | } | ||
148 | |||
149 | rice_order = get_bits(&s->gb, 4); | ||
150 | |||
151 | samples= s->blocksize >> rice_order; | ||
152 | |||
153 | sample= | ||
154 | i= pred_order; | ||
155 | for (partition = 0; partition < (1 << rice_order); partition++) | ||
156 | { | ||
157 | tmp = get_bits(&s->gb, method_type == 0 ? 4 : 5); | ||
158 | if (tmp == (method_type == 0 ? 15 : 31)) | ||
159 | { | ||
160 | //fprintf(stderr,"fixed len partition\n"); | ||
161 | tmp = get_bits(&s->gb, 5); | ||
162 | for (; i < samples; i++, sample++) | ||
163 | decoded[sample] = get_sbits(&s->gb, tmp); | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | for (; i < samples; i++, sample++){ | ||
168 | decoded[sample] = get_sr_golomb_flac(&s->gb, tmp, INT_MAX, 0); | ||
169 | } | ||
170 | } | ||
171 | i= 0; | ||
172 | } | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static int decode_subframe_fixed(FLACContext *s, int32_t* decoded, int pred_order) ICODE_ATTR_FLAC; | ||
178 | static int decode_subframe_fixed(FLACContext *s, int32_t* decoded, int pred_order) | ||
179 | { | ||
180 | const int blocksize = s->blocksize; | ||
181 | int a, b, c, d, i; | ||
182 | |||
183 | /* warm up samples */ | ||
184 | for (i = 0; i < pred_order; i++) | ||
185 | { | ||
186 | decoded[i] = get_sbits(&s->gb, s->curr_bps); | ||
187 | } | ||
188 | |||
189 | if (decode_residuals(s, decoded, pred_order) < 0) | ||
190 | return -4; | ||
191 | |||
192 | a = decoded[pred_order-1]; | ||
193 | b = a - decoded[pred_order-2]; | ||
194 | c = b - decoded[pred_order-2] + decoded[pred_order-3]; | ||
195 | d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4]; | ||
196 | |||
197 | switch(pred_order) | ||
198 | { | ||
199 | case 0: | ||
200 | break; | ||
201 | case 1: | ||
202 | for (i = pred_order; i < blocksize; i++) | ||
203 | decoded[i] = a += decoded[i]; | ||
204 | break; | ||
205 | case 2: | ||
206 | for (i = pred_order; i < blocksize; i++) | ||
207 | decoded[i] = a += b += decoded[i]; | ||
208 | break; | ||
209 | case 3: | ||
210 | for (i = pred_order; i < blocksize; i++) | ||
211 | decoded[i] = a += b += c += decoded[i]; | ||
212 | break; | ||
213 | case 4: | ||
214 | for (i = pred_order; i < blocksize; i++) | ||
215 | decoded[i] = a += b += c += d += decoded[i]; | ||
216 | break; | ||
217 | default: | ||
218 | return -5; | ||
219 | } | ||
220 | |||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | static int decode_subframe_lpc(FLACContext *s, int32_t* decoded, int pred_order) ICODE_ATTR_FLAC; | ||
225 | static int decode_subframe_lpc(FLACContext *s, int32_t* decoded, int pred_order) | ||
226 | { | ||
227 | int sum, i, j; | ||
228 | int64_t wsum; | ||
229 | int coeff_prec, qlevel; | ||
230 | int coeffs[pred_order]; | ||
231 | |||
232 | /* warm up samples */ | ||
233 | for (i = 0; i < pred_order; i++) | ||
234 | { | ||
235 | decoded[i] = get_sbits(&s->gb, s->curr_bps); | ||
236 | } | ||
237 | |||
238 | coeff_prec = get_bits(&s->gb, 4) + 1; | ||
239 | if (coeff_prec == 16) | ||
240 | { | ||
241 | //fprintf(stderr,"invalid coeff precision\n"); | ||
242 | return -6; | ||
243 | } | ||
244 | qlevel = get_sbits(&s->gb, 5); | ||
245 | if (qlevel < 0) | ||
246 | { | ||
247 | //fprintf(stderr,"qlevel %d not supported, maybe buggy stream\n", qlevel); | ||
248 | return -7; | ||
249 | } | ||
250 | |||
251 | for (i = 0; i < pred_order; i++) | ||
252 | { | ||
253 | coeffs[i] = get_sbits(&s->gb, coeff_prec); | ||
254 | } | ||
255 | |||
256 | if (decode_residuals(s, decoded, pred_order) < 0) | ||
257 | return -8; | ||
258 | |||
259 | if ((s->bps + coeff_prec + av_log2(pred_order)) <= 32) { | ||
260 | #if defined(CPU_COLDFIRE) | ||
261 | (void)sum; | ||
262 | lpc_decode_emac(s->blocksize - pred_order, qlevel, pred_order, | ||
263 | decoded + pred_order, coeffs); | ||
264 | #elif defined(CPU_ARM) | ||
265 | (void)sum; | ||
266 | lpc_decode_arm(s->blocksize - pred_order, qlevel, pred_order, | ||
267 | decoded + pred_order, coeffs); | ||
268 | #else | ||
269 | for (i = pred_order; i < s->blocksize; i++) | ||
270 | { | ||
271 | sum = 0; | ||
272 | for (j = 0; j < pred_order; j++) | ||
273 | sum += coeffs[j] * decoded[i-j-1]; | ||
274 | decoded[i] += sum >> qlevel; | ||
275 | } | ||
276 | #endif | ||
277 | } else { | ||
278 | #if defined(CPU_COLDFIRE) | ||
279 | (void)wsum; | ||
280 | (void)j; | ||
281 | lpc_decode_emac_wide(s->blocksize - pred_order, qlevel, pred_order, | ||
282 | decoded + pred_order, coeffs); | ||
283 | #else | ||
284 | for (i = pred_order; i < s->blocksize; i++) | ||
285 | { | ||
286 | wsum = 0; | ||
287 | for (j = 0; j < pred_order; j++) | ||
288 | wsum += (int64_t)coeffs[j] * (int64_t)decoded[i-j-1]; | ||
289 | decoded[i] += wsum >> qlevel; | ||
290 | } | ||
291 | #endif | ||
292 | } | ||
293 | |||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | static inline int decode_subframe(FLACContext *s, int channel, int32_t* decoded) | ||
298 | { | ||
299 | int type, wasted = 0; | ||
300 | int i, tmp; | ||
301 | |||
302 | s->curr_bps = s->bps; | ||
303 | if(channel == 0){ | ||
304 | if(s->decorrelation == RIGHT_SIDE) | ||
305 | s->curr_bps++; | ||
306 | }else{ | ||
307 | if(s->decorrelation == LEFT_SIDE || s->decorrelation == MID_SIDE) | ||
308 | s->curr_bps++; | ||
309 | } | ||
310 | |||
311 | if (get_bits1(&s->gb)) | ||
312 | { | ||
313 | //fprintf(stderr,"invalid subframe padding\n"); | ||
314 | return -9; | ||
315 | } | ||
316 | type = get_bits(&s->gb, 6); | ||
317 | // wasted = get_bits1(&s->gb); | ||
318 | |||
319 | // if (wasted) | ||
320 | // { | ||
321 | // while (!get_bits1(&s->gb)) | ||
322 | // wasted++; | ||
323 | // if (wasted) | ||
324 | // wasted++; | ||
325 | // s->curr_bps -= wasted; | ||
326 | // } | ||
327 | #if 0 | ||
328 | wasted= 16 - av_log2(show_bits(&s->gb, 17)); | ||
329 | skip_bits(&s->gb, wasted+1); | ||
330 | s->curr_bps -= wasted; | ||
331 | #else | ||
332 | if (get_bits1(&s->gb)) | ||
333 | { | ||
334 | wasted = 1; | ||
335 | while (!get_bits1(&s->gb)) | ||
336 | wasted++; | ||
337 | s->curr_bps -= wasted; | ||
338 | //fprintf(stderr,"%d wasted bits\n", wasted); | ||
339 | } | ||
340 | #endif | ||
341 | //FIXME use av_log2 for types | ||
342 | if (type == 0) | ||
343 | { | ||
344 | //fprintf(stderr,"coding type: constant\n"); | ||
345 | tmp = get_sbits(&s->gb, s->curr_bps); | ||
346 | for (i = 0; i < s->blocksize; i++) | ||
347 | decoded[i] = tmp; | ||
348 | } | ||
349 | else if (type == 1) | ||
350 | { | ||
351 | //fprintf(stderr,"coding type: verbatim\n"); | ||
352 | for (i = 0; i < s->blocksize; i++) | ||
353 | decoded[i] = get_sbits(&s->gb, s->curr_bps); | ||
354 | } | ||
355 | else if ((type >= 8) && (type <= 12)) | ||
356 | { | ||
357 | //fprintf(stderr,"coding type: fixed\n"); | ||
358 | if (decode_subframe_fixed(s, decoded, type & ~0x8) < 0) | ||
359 | return -10; | ||
360 | } | ||
361 | else if (type >= 32) | ||
362 | { | ||
363 | //fprintf(stderr,"coding type: lpc\n"); | ||
364 | if (decode_subframe_lpc(s, decoded, (type & ~0x20)+1) < 0) | ||
365 | return -11; | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | //fprintf(stderr,"Unknown coding type: %d\n",type); | ||
370 | return -12; | ||
371 | } | ||
372 | |||
373 | if (wasted) | ||
374 | { | ||
375 | int i; | ||
376 | for (i = 0; i < s->blocksize; i++) | ||
377 | decoded[i] <<= wasted; | ||
378 | } | ||
379 | |||
380 | return 0; | ||
381 | } | ||
382 | |||
383 | static int decode_frame(FLACContext *s, | ||
384 | void (*yield)(void)) ICODE_ATTR_FLAC; | ||
385 | static int decode_frame(FLACContext *s, | ||
386 | void (*yield)(void)) | ||
387 | { | ||
388 | int blocksize_code, sample_rate_code, sample_size_code, assignment, crc8; | ||
389 | int decorrelation, bps, blocksize, samplerate; | ||
390 | int res, ch; | ||
391 | |||
392 | blocksize_code = get_bits(&s->gb, 4); | ||
393 | |||
394 | sample_rate_code = get_bits(&s->gb, 4); | ||
395 | |||
396 | assignment = get_bits(&s->gb, 4); /* channel assignment */ | ||
397 | if (assignment < 8 && s->channels == assignment+1) | ||
398 | decorrelation = INDEPENDENT; | ||
399 | else if (assignment >=8 && assignment < 11 && s->channels == 2) | ||
400 | decorrelation = LEFT_SIDE + assignment - 8; | ||
401 | else | ||
402 | { | ||
403 | return -13; | ||
404 | } | ||
405 | |||
406 | sample_size_code = get_bits(&s->gb, 3); | ||
407 | if(sample_size_code == 0) | ||
408 | bps= s->bps; | ||
409 | else if((sample_size_code != 3) && (sample_size_code != 7)) | ||
410 | bps = sample_size_table[sample_size_code]; | ||
411 | else | ||
412 | { | ||
413 | return -14; | ||
414 | } | ||
415 | |||
416 | if (get_bits1(&s->gb)) | ||
417 | { | ||
418 | return -15; | ||
419 | } | ||
420 | |||
421 | /* Get the samplenumber of the first sample in this block */ | ||
422 | s->samplenumber=get_utf8(&s->gb); | ||
423 | |||
424 | /* samplenumber actually contains the frame number for streams | ||
425 | with a constant block size - so we multiply by blocksize to | ||
426 | get the actual sample number */ | ||
427 | if (s->min_blocksize == s->max_blocksize) { | ||
428 | s->samplenumber*=s->min_blocksize; | ||
429 | } | ||
430 | |||
431 | #if 0 | ||
432 | if (/*((blocksize_code == 6) || (blocksize_code == 7)) &&*/ | ||
433 | (s->min_blocksize != s->max_blocksize)){ | ||
434 | }else{ | ||
435 | } | ||
436 | #endif | ||
437 | |||
438 | if (blocksize_code == 0) | ||
439 | blocksize = s->min_blocksize; | ||
440 | else if (blocksize_code == 6) | ||
441 | blocksize = get_bits(&s->gb, 8)+1; | ||
442 | else if (blocksize_code == 7) | ||
443 | blocksize = get_bits(&s->gb, 16)+1; | ||
444 | else | ||
445 | blocksize = blocksize_table[blocksize_code]; | ||
446 | |||
447 | if(blocksize > s->max_blocksize){ | ||
448 | return -16; | ||
449 | } | ||
450 | |||
451 | if (sample_rate_code == 0){ | ||
452 | samplerate= s->samplerate; | ||
453 | }else if ((sample_rate_code < 12)) | ||
454 | samplerate = sample_rate_table[sample_rate_code]; | ||
455 | else if (sample_rate_code == 12) | ||
456 | samplerate = get_bits(&s->gb, 8) * 1000; | ||
457 | else if (sample_rate_code == 13) | ||
458 | samplerate = get_bits(&s->gb, 16); | ||
459 | else if (sample_rate_code == 14) | ||
460 | samplerate = get_bits(&s->gb, 16) * 10; | ||
461 | else{ | ||
462 | return -17; | ||
463 | } | ||
464 | |||
465 | skip_bits(&s->gb, 8); | ||
466 | crc8= get_crc8(s->gb.buffer, get_bits_count(&s->gb)/8); | ||
467 | if(crc8){ | ||
468 | return -18; | ||
469 | } | ||
470 | |||
471 | s->blocksize = blocksize; | ||
472 | s->samplerate = samplerate; | ||
473 | s->bps = bps; | ||
474 | s->decorrelation= decorrelation; | ||
475 | |||
476 | for (ch=0; ch<s->channels; ++ch) { | ||
477 | yield(); | ||
478 | if ((res=decode_subframe(s, ch, s->decoded[ch])) < 0) | ||
479 | return res-100; | ||
480 | } | ||
481 | |||
482 | yield(); | ||
483 | align_get_bits(&s->gb); | ||
484 | |||
485 | /* frame footer */ | ||
486 | skip_bits(&s->gb, 16); /* data crc */ | ||
487 | |||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | static int flac_downmix(FLACContext *s) ICODE_ATTR_FLAC; | ||
492 | static int flac_downmix(FLACContext *s) | ||
493 | { | ||
494 | int32_t *FL, *FR, *FC, *SB, *RL, *RR; | ||
495 | int32_t *outL = s->decoded[0]; | ||
496 | int32_t *outR = s->decoded[1]; | ||
497 | int i, scale=FLAC_OUTPUT_DEPTH-s->bps; | ||
498 | |||
499 | switch(s->channels) | ||
500 | { | ||
501 | case 3: /* 3.0 channel order: FL FR FC */ | ||
502 | FL = s->decoded[0]; | ||
503 | FR = s->decoded[1]; | ||
504 | FC = s->decoded[2]; | ||
505 | /* LF = 0.66 LF + 0.33 FC | ||
506 | LR = 0.66 LR + 0.33 FC */ | ||
507 | for (i=0; i<s->blocksize; ++i) { | ||
508 | int32_t a = *(FL)*2 + *(FC); | ||
509 | int32_t b = *(FR)*2 + *(FC); | ||
510 | *outL++ = ((a + (a<<2))>>4) << scale; /* 1/3 ~= 5>>4 */ | ||
511 | *outR++ = ((b + (b<<2))>>4) << scale; /* 1/3 ~= 5>>4 */ | ||
512 | FL++; FR++; FC++; | ||
513 | } | ||
514 | break; | ||
515 | case 4: /* 4.0 channel order: FL FR RL RR */ | ||
516 | FL = s->decoded[0]; | ||
517 | FR = s->decoded[1]; | ||
518 | RL = s->decoded[2]; | ||
519 | RR = s->decoded[3]; | ||
520 | /* LF = 0.50 LF + 0.50 RL + 0.00 RR | ||
521 | LR = 0.50 LR + 0.00 RL + 0.50 RR */ | ||
522 | for (i=0; i<s->blocksize; ++i) { | ||
523 | int32_t a = *(FL) + *(RL); | ||
524 | int32_t b = *(FR) + *(RR); | ||
525 | *outL++ = (a>>1) << scale; | ||
526 | *outR++ = (b>>1) << scale; | ||
527 | FL++; FR++; RL++; RR++; | ||
528 | } | ||
529 | break; | ||
530 | case 5: /* 5.0 channel order: FL FR FC RL RR */ | ||
531 | FL = s->decoded[0]; | ||
532 | FR = s->decoded[1]; | ||
533 | FC = s->decoded[2]; | ||
534 | RL = s->decoded[3]; | ||
535 | RR = s->decoded[4]; | ||
536 | /* LF = 0.40 LF + 0.20 FC + 0.40 RL + 0.00 RR | ||
537 | LR = 0.40 LR + 0.20 FC + 0.00 RL + 0.40 RR */ | ||
538 | for (i=0; i<s->blocksize; ++i) { | ||
539 | int32_t a = *(FL)*2 + *(FC) + *(RL)*2; | ||
540 | int32_t b = *(FR)*2 + *(FC) + *(RR)*2; | ||
541 | *outL++ = ((a + (a<<1))>>4) << scale; /* 3>>4 ~= 1/5 */ | ||
542 | *outR++ = ((b + (b<<1))>>4) << scale; /* 3>>4 ~= 1/5 */ | ||
543 | FL++; FR++; FC++; RL++; RR++; | ||
544 | } | ||
545 | break; | ||
546 | case 6: /* 5.1 channel order: FL FR FC SUB RL RR */ | ||
547 | FL = s->decoded[0]; | ||
548 | FR = s->decoded[1]; | ||
549 | FC = s->decoded[2]; | ||
550 | SB = s->decoded[3]; | ||
551 | RL = s->decoded[4]; | ||
552 | RR = s->decoded[5]; | ||
553 | /* LF = 0.33 LF + 0.16 SUB + 0.16 FC + 0.33 RL + 0.00 RR | ||
554 | LR = 0.33 LR + 0.16 SUB + 0.16 FC + 0.00 RL + 0.33 RR */ | ||
555 | for (i=0; i<s->blocksize; ++i) { | ||
556 | int32_t a = *(FL)*2 + *(SB) + *(FC) + *(RL)*2; | ||
557 | int32_t b = *(FR)*2 + *(SB) + *(FC) + *(RR)*2; | ||
558 | *outL++ = ((a + (a<<2))>>5) << scale; /* 5>>5 ~= 1/6 */ | ||
559 | *outR++ = ((b + (b<<2))>>5) << scale; /* 5>>5 ~= 1/6 */ | ||
560 | FL++; FR++; SB++; FC++; RL++; RR++; | ||
561 | } | ||
562 | break; | ||
563 | default: /* 1.0 and 2.0 do not need downmix, other formats unknown. */ | ||
564 | return -501; | ||
565 | break; | ||
566 | } | ||
567 | return 0; | ||
568 | } | ||
569 | |||
570 | int flac_decode_frame(FLACContext *s, | ||
571 | uint8_t *buf, int buf_size, | ||
572 | void (*yield)(void)) | ||
573 | { | ||
574 | int tmp; | ||
575 | int i; | ||
576 | int framesize; | ||
577 | int scale; | ||
578 | |||
579 | init_get_bits(&s->gb, buf, buf_size*8); | ||
580 | |||
581 | tmp = get_bits(&s->gb, 16); | ||
582 | if ((tmp & 0xFFFE) != 0xFFF8){ | ||
583 | return -41; | ||
584 | } | ||
585 | |||
586 | if ((framesize=decode_frame(s,yield)) < 0){ | ||
587 | s->bitstream_size=0; | ||
588 | s->bitstream_index=0; | ||
589 | return framesize; | ||
590 | } | ||
591 | |||
592 | yield(); | ||
593 | |||
594 | #define DECORRELATE(left, right)\ | ||
595 | for (i = 0; i < s->blocksize; i++) {\ | ||
596 | int32_t a = s->decoded[0][i];\ | ||
597 | int32_t b = s->decoded[1][i];\ | ||
598 | s->decoded[0][i] = (left) << scale;\ | ||
599 | s->decoded[1][i] = (right) << scale;\ | ||
600 | }\ | ||
601 | |||
602 | scale=FLAC_OUTPUT_DEPTH-s->bps; | ||
603 | switch(s->decorrelation) | ||
604 | { | ||
605 | case INDEPENDENT: | ||
606 | if (s->channels <= 2) { | ||
607 | DECORRELATE(a, b) /* Always decorrelate exactly the two supported channels. */ | ||
608 | } else { | ||
609 | if ((tmp=flac_downmix(s)) != 0) | ||
610 | return tmp; | ||
611 | } | ||
612 | break; | ||
613 | case LEFT_SIDE: | ||
614 | DECORRELATE(a, a-b) | ||
615 | break; | ||
616 | case RIGHT_SIDE: | ||
617 | DECORRELATE(a+b, b) | ||
618 | break; | ||
619 | case MID_SIDE: | ||
620 | DECORRELATE( (a-=b>>1) + b, a) | ||
621 | break; | ||
622 | } | ||
623 | |||
624 | s->framesize = (get_bits_count(&s->gb)+7)>>3; | ||
625 | |||
626 | return 0; | ||
627 | } | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/decoder.h b/lib/rbcodec/codecs/libffmpegFLAC/decoder.h new file mode 100644 index 0000000000..677a21ac98 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/decoder.h | |||
@@ -0,0 +1,49 @@ | |||
1 | #ifndef _FLAC_DECODER_H | ||
2 | #define _FLAC_DECODER_H | ||
3 | |||
4 | #include "bitstream.h" | ||
5 | |||
6 | #define MAX_CHANNELS 6 /* Maximum supported channels, only left/right will be played back */ | ||
7 | #define MAX_BLOCKSIZE 4608 /* Maxsize in samples of one uncompressed frame */ | ||
8 | #define MAX_FRAMESIZE 65536 /* Maxsize in bytes of one compressed frame */ | ||
9 | |||
10 | #define FLAC_OUTPUT_DEPTH 29 /* Provide samples left-shifted to 28 bits+sign */ | ||
11 | |||
12 | enum decorrelation_type { | ||
13 | INDEPENDENT, | ||
14 | LEFT_SIDE, | ||
15 | RIGHT_SIDE, | ||
16 | MID_SIDE, | ||
17 | }; | ||
18 | |||
19 | typedef struct FLACContext { | ||
20 | GetBitContext gb; | ||
21 | |||
22 | int min_blocksize, max_blocksize; | ||
23 | int min_framesize, max_framesize; | ||
24 | int samplerate, channels; | ||
25 | int blocksize/*, last_blocksize*/; | ||
26 | int bps, curr_bps; | ||
27 | unsigned long samplenumber; | ||
28 | unsigned long totalsamples; | ||
29 | enum decorrelation_type decorrelation; | ||
30 | |||
31 | int filesize; | ||
32 | int length; | ||
33 | int bitrate; | ||
34 | int metadatalength; | ||
35 | |||
36 | int bitstream_size; | ||
37 | int bitstream_index; | ||
38 | |||
39 | int sample_skip; | ||
40 | int framesize; | ||
41 | |||
42 | int32_t *decoded[MAX_CHANNELS]; | ||
43 | } FLACContext; | ||
44 | |||
45 | int flac_decode_frame(FLACContext *s, | ||
46 | uint8_t *buf, int buf_size, | ||
47 | void (*yield)(void)) ICODE_ATTR_FLAC; | ||
48 | |||
49 | #endif | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/golomb.h b/lib/rbcodec/codecs/libffmpegFLAC/golomb.h new file mode 100644 index 0000000000..197b78ee1c --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/golomb.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * exp golomb vlc stuff | ||
3 | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | ||
4 | * Copyright (c) 2004 Alex Beregszaszi | ||
5 | * | ||
6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <limits.h> | ||
23 | #include "codeclib.h" | ||
24 | |||
25 | /** | ||
26 | * @file golomb.h | ||
27 | * @brief | ||
28 | * exp golomb vlc stuff | ||
29 | * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi | ||
30 | */ | ||
31 | |||
32 | |||
33 | /** | ||
34 | * read unsigned golomb rice code (jpegls). | ||
35 | */ | ||
36 | static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){ | ||
37 | unsigned int buf; | ||
38 | int log; | ||
39 | |||
40 | OPEN_READER(re, gb); | ||
41 | UPDATE_CACHE(re, gb); | ||
42 | buf=GET_CACHE(re, gb); | ||
43 | |||
44 | log= av_log2(buf); | ||
45 | |||
46 | if(log - k >= 32-MIN_CACHE_BITS+(MIN_CACHE_BITS==32) && 32-log < limit){ | ||
47 | buf >>= log - k; | ||
48 | buf += (30-log)<<k; | ||
49 | LAST_SKIP_BITS(re, gb, 32 + k - log); | ||
50 | CLOSE_READER(re, gb); | ||
51 | |||
52 | return buf; | ||
53 | }else{ | ||
54 | int i; | ||
55 | for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ | ||
56 | LAST_SKIP_BITS(re, gb, 1); | ||
57 | UPDATE_CACHE(re, gb); | ||
58 | } | ||
59 | SKIP_BITS(re, gb, 1); | ||
60 | |||
61 | if(i < limit - 1){ | ||
62 | if(k){ | ||
63 | buf = SHOW_UBITS(re, gb, k); | ||
64 | LAST_SKIP_BITS(re, gb, k); | ||
65 | }else{ | ||
66 | buf=0; | ||
67 | } | ||
68 | |||
69 | CLOSE_READER(re, gb); | ||
70 | return buf + (i<<k); | ||
71 | }else if(i == limit - 1){ | ||
72 | buf = SHOW_UBITS(re, gb, esc_len); | ||
73 | LAST_SKIP_BITS(re, gb, esc_len); | ||
74 | CLOSE_READER(re, gb); | ||
75 | |||
76 | return buf + 1; | ||
77 | }else | ||
78 | return -1; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * read signed golomb rice code (flac). | ||
84 | */ | ||
85 | static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | ||
86 | int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | ||
87 | return (v>>1) ^ -(v&1); | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * read unsigned golomb rice code (shorten). | ||
92 | */ | ||
93 | #define get_ur_golomb_shorten(gb, k) get_ur_golomb_jpegls(gb, k, INT_MAX, 0) | ||
94 | /* | ||
95 | static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ | ||
96 | return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); | ||
97 | } | ||
98 | */ | ||
99 | |||
100 | /** | ||
101 | * read signed golomb rice code (shorten). | ||
102 | */ | ||
103 | static inline int get_sr_golomb_shorten(GetBitContext* gb, int k) | ||
104 | { | ||
105 | int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); | ||
106 | if (uvar & 1) | ||
107 | return ~(uvar >> 1); | ||
108 | else | ||
109 | return uvar >> 1; | ||
110 | } | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/libffmpegFLAC.make b/lib/rbcodec/codecs/libffmpegFLAC/libffmpegFLAC.make new file mode 100644 index 0000000000..7ae7e96b26 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/libffmpegFLAC.make | |||
@@ -0,0 +1,18 @@ | |||
1 | # __________ __ ___. | ||
2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
6 | # \/ \/ \/ \/ \/ | ||
7 | # $Id$ | ||
8 | # | ||
9 | |||
10 | # libffmpegFLAC | ||
11 | FFMPEGFLACLIB := $(CODECDIR)/libffmpegFLAC.a | ||
12 | FFMPEGFLACLIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/libffmpegFLAC/SOURCES) | ||
13 | FFMPEGFLACLIB_OBJ := $(call c2obj, $(FFMPEGFLACLIB_SRC)) | ||
14 | OTHER_SRC += $(FFMPEGFLACLIB_SRC) | ||
15 | |||
16 | $(FFMPEGFLACLIB): $(FFMPEGFLACLIB_OBJ) | ||
17 | $(SILENT)$(shell rm -f $@) | ||
18 | $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/shndec.c b/lib/rbcodec/codecs/libffmpegFLAC/shndec.c new file mode 100644 index 0000000000..40e7211b87 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/shndec.c | |||
@@ -0,0 +1,481 @@ | |||
1 | /* | ||
2 | * Shorten decoder | ||
3 | * Copyright (c) 2005 Jeff Muizelaar | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file shorten.c | ||
22 | * Shorten decoder | ||
23 | * @author Jeff Muizelaar | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include "bitstream.h" | ||
28 | #include "golomb.h" | ||
29 | #include "shndec.h" | ||
30 | #include "codeclib.h" | ||
31 | |||
32 | #define ULONGSIZE 2 | ||
33 | |||
34 | #define WAVE_FORMAT_PCM 0x0001 | ||
35 | |||
36 | #define TYPESIZE 4 | ||
37 | #define CHANSIZE 0 | ||
38 | #define LPCQSIZE 2 | ||
39 | #define ENERGYSIZE 3 | ||
40 | #define BITSHIFTSIZE 2 | ||
41 | |||
42 | #define TYPE_S16HL 3 /* signed 16 bit shorts: high-low */ | ||
43 | #define TYPE_S16LH 5 /* signed 16 bit shorts: low-high */ | ||
44 | |||
45 | #define NWRAP 3 | ||
46 | #define NSKIPSIZE 1 | ||
47 | |||
48 | #define LPCQUANT 5 | ||
49 | #define V2LPCQOFFSET (1 << LPCQUANT) | ||
50 | |||
51 | #define FNSIZE 2 | ||
52 | |||
53 | #define VERBATIM_CKSIZE_SIZE 5 | ||
54 | #define VERBATIM_BYTE_SIZE 8 | ||
55 | #define CANONICAL_HEADER_SIZE 44 | ||
56 | |||
57 | #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) | ||
58 | |||
59 | #define get_le16(gb) bswap_16(get_bits_long(gb, 16)) | ||
60 | #define get_le32(gb) bswap_32(get_bits_long(gb, 32)) | ||
61 | |||
62 | /* converts fourcc string to int */ | ||
63 | static unsigned int ff_get_fourcc(const char *s){ | ||
64 | //assert( strlen(s)==4 ); | ||
65 | return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); | ||
66 | } | ||
67 | |||
68 | static unsigned int get_uint(ShortenContext *s, int k) | ||
69 | { | ||
70 | if (s->version != 0) | ||
71 | k = get_ur_golomb_shorten(&s->gb, ULONGSIZE); | ||
72 | return get_ur_golomb_shorten(&s->gb, k); | ||
73 | } | ||
74 | |||
75 | #if defined(CPU_COLDFIRE) | ||
76 | static inline void coldfire_lshift_samples(int n, int shift, int32_t *samples) | ||
77 | { | ||
78 | /* | ||
79 | for (i = 0; i < n; i++) | ||
80 | samples[i] =<< shift; | ||
81 | */ | ||
82 | asm volatile ( | ||
83 | "move.l %[n], %%d0 \n" /* d0 = loop counter */ | ||
84 | "asr.l #2, %%d0 \n" | ||
85 | "beq 1f \n" | ||
86 | "2:" /* main loop (unroll by 4) */ | ||
87 | "movem.l (%[x]), %%d4-%%d7 \n" | ||
88 | "asl.l %[s], %%d4 \n" | ||
89 | "asl.l %[s], %%d5 \n" | ||
90 | "asl.l %[s], %%d6 \n" | ||
91 | "asl.l %[s], %%d7 \n" | ||
92 | "movem.l %%d4-%%d7, (%[x]) \n" | ||
93 | "lea.l (16, %[x]), %[x] \n" | ||
94 | |||
95 | "subq.l #1, %%d0 \n" | ||
96 | "bne 2b \n" | ||
97 | "1:" /* any loops left? */ | ||
98 | "and.l #3, %[n] \n" | ||
99 | "beq 4f \n" | ||
100 | "3:" /* remaining loops */ | ||
101 | "move.l (%[x]), %%d4 \n" | ||
102 | "asl.l %[s], %%d4 \n" | ||
103 | "move.l %%d4, (%[x])+ \n" | ||
104 | |||
105 | "subq.l #1, %[n] \n" | ||
106 | "bne 3b \n" | ||
107 | "4:" /* exit */ | ||
108 | : [n] "+d" (n), | ||
109 | [x] "+a" (samples) | ||
110 | : [s] "d" (shift) | ||
111 | : "%d0", "%d4", "%d5", "%d6", "%d7", "cc", "memory" | ||
112 | ); | ||
113 | } | ||
114 | #endif | ||
115 | |||
116 | static inline void fix_bitshift(ShortenContext *s, int32_t *samples) | ||
117 | { | ||
118 | int i; | ||
119 | |||
120 | /* Wrapped samples don't get bitshifted, so we'll do them during | ||
121 | the next iteration. */ | ||
122 | if (s->bitshift != 0) { | ||
123 | #if defined(CPU_COLDFIRE) | ||
124 | coldfire_lshift_samples(s->blocksize, s->bitshift, samples - s->nwrap); | ||
125 | #else | ||
126 | for (i = -s->nwrap; i < (s->blocksize - s->nwrap); i++) | ||
127 | samples[i] <<= s->bitshift; | ||
128 | #endif | ||
129 | } | ||
130 | |||
131 | /* Also, when we have to remember to fix the wrapped samples when | ||
132 | the bitshift changes.*/ | ||
133 | if (s->bitshift != s->last_bitshift) { | ||
134 | if (s->last_bitshift != 0) | ||
135 | for (i = -s->nwrap; i < 0; i++) | ||
136 | samples[i] <<= s->last_bitshift; | ||
137 | |||
138 | s->last_bitshift = s->bitshift; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | static inline void decode_subframe_lpc(ShortenContext *s, int32_t *decoded, | ||
143 | int residual_size, int pred_order) | ||
144 | { | ||
145 | int sum, i, j; | ||
146 | int coeffs[MAX_PRED_ORDER]; | ||
147 | |||
148 | for (i=0; i<pred_order; i++) { | ||
149 | coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT); | ||
150 | } | ||
151 | |||
152 | for (i=0; i < s->blocksize; i++) { | ||
153 | sum = s->lpcqoffset; | ||
154 | for (j=0; j<pred_order; j++) | ||
155 | sum += coeffs[j] * decoded[i-j-1]; | ||
156 | |||
157 | decoded[i] = | ||
158 | get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | static inline int shorten_decode_frame(ShortenContext *s, int32_t *decoded, | ||
163 | int32_t *offset) | ||
164 | { | ||
165 | int i; | ||
166 | int32_t sum; | ||
167 | |||
168 | int cmd = get_ur_golomb_shorten(&s->gb, FNSIZE); | ||
169 | switch (cmd) { | ||
170 | case FN_ZERO: | ||
171 | case FN_DIFF0: | ||
172 | case FN_DIFF1: | ||
173 | case FN_DIFF2: | ||
174 | case FN_DIFF3: | ||
175 | case FN_QLPC: | ||
176 | { | ||
177 | int residual_size = 0; | ||
178 | int32_t coffset; | ||
179 | if (cmd != FN_ZERO) { | ||
180 | residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); | ||
181 | /* this is a hack as version 0 differed in defintion of | ||
182 | get_sr_golomb_shorten */ | ||
183 | if (s->version == 0) | ||
184 | residual_size--; | ||
185 | } | ||
186 | |||
187 | if (s->nmean == 0) { | ||
188 | coffset = offset[0]; | ||
189 | } else { | ||
190 | sum = (s->version < 2) ? 0 : s->nmean / 2; | ||
191 | for (i=0; i<s->nmean; i++) | ||
192 | sum += offset[i]; | ||
193 | |||
194 | coffset = sum / s->nmean; | ||
195 | if (s->version >= 2) | ||
196 | coffset >>= FFMIN(1, s->bitshift); | ||
197 | } | ||
198 | |||
199 | switch (cmd) { | ||
200 | case FN_ZERO: | ||
201 | for (i=0; i<s->blocksize; i++) | ||
202 | decoded[i] = 0; | ||
203 | break; | ||
204 | |||
205 | case FN_DIFF0: | ||
206 | for (i=0; i<s->blocksize; i++) | ||
207 | decoded[i] = | ||
208 | get_sr_golomb_shorten(&s->gb, residual_size) + | ||
209 | coffset; | ||
210 | break; | ||
211 | |||
212 | case FN_DIFF1: | ||
213 | for (i=0; i<s->blocksize; i++) | ||
214 | decoded[i] = | ||
215 | get_sr_golomb_shorten(&s->gb, residual_size) + | ||
216 | decoded[i - 1]; | ||
217 | break; | ||
218 | |||
219 | case FN_DIFF2: | ||
220 | for (i=0; i<s->blocksize; i++) | ||
221 | decoded[i] = | ||
222 | get_sr_golomb_shorten(&s->gb, residual_size) + | ||
223 | 2*decoded[i-1] - decoded[i-2]; | ||
224 | break; | ||
225 | |||
226 | case FN_DIFF3: | ||
227 | for (i=0; i<s->blocksize; i++) | ||
228 | decoded[i] = | ||
229 | get_sr_golomb_shorten(&s->gb, residual_size) + | ||
230 | 3*decoded[i-1] - 3*decoded[i-2] + decoded[i-3]; | ||
231 | break; | ||
232 | |||
233 | case FN_QLPC: | ||
234 | { | ||
235 | int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); | ||
236 | for (i=0; i<pred_order; i++) | ||
237 | decoded[i - pred_order] -= coffset; | ||
238 | decode_subframe_lpc(s, decoded, residual_size, pred_order); | ||
239 | if (coffset != 0) { | ||
240 | for (i=0; i < s->blocksize; i++) | ||
241 | decoded[i] += coffset; | ||
242 | } | ||
243 | } | ||
244 | } | ||
245 | |||
246 | if (s->nmean > 0) { | ||
247 | sum = (s->version < 2) ? 0 : s->blocksize / 2; | ||
248 | for (i=0; i<s->blocksize; i++) | ||
249 | sum += decoded[i]; | ||
250 | |||
251 | for (i=1; i<s->nmean; i++) | ||
252 | offset[i-1] = offset[i]; | ||
253 | |||
254 | if (s->version < 2) { | ||
255 | offset[s->nmean - 1] = sum / s->blocksize; | ||
256 | } else { | ||
257 | offset[s->nmean - 1] = | ||
258 | (sum / s->blocksize) << s->bitshift; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | fix_bitshift(s, decoded); | ||
263 | break; | ||
264 | } | ||
265 | |||
266 | case FN_VERBATIM: | ||
267 | i = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); | ||
268 | while (i--) | ||
269 | get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); | ||
270 | break; | ||
271 | |||
272 | case FN_BITSHIFT: | ||
273 | s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); | ||
274 | break; | ||
275 | |||
276 | case FN_BLOCKSIZE: | ||
277 | s->blocksize = get_uint(s, av_log2(s->blocksize)); | ||
278 | break; | ||
279 | |||
280 | case FN_QUIT: | ||
281 | break; | ||
282 | |||
283 | default: | ||
284 | return FN_ERROR; | ||
285 | break; | ||
286 | } | ||
287 | |||
288 | return cmd; | ||
289 | } | ||
290 | |||
291 | int shorten_decode_frames(ShortenContext *s, int *nsamples, | ||
292 | int32_t *decoded0, int32_t *decoded1, | ||
293 | int32_t *offset0, int32_t *offset1, | ||
294 | uint8_t *buf, int buf_size, | ||
295 | void (*yield)(void)) | ||
296 | { | ||
297 | int32_t *decoded, *offset; | ||
298 | int cmd; | ||
299 | |||
300 | *nsamples = 0; | ||
301 | |||
302 | init_get_bits(&s->gb, buf, buf_size*8); | ||
303 | get_bits(&s->gb, s->bitindex); | ||
304 | |||
305 | int n = 0; | ||
306 | while (n < NUM_DEC_LOOPS) { | ||
307 | int chan = n%2; | ||
308 | if (chan == 0) { | ||
309 | decoded = decoded0 + s->nwrap + *nsamples; | ||
310 | offset = offset0; | ||
311 | } else { | ||
312 | decoded = decoded1 + s->nwrap + *nsamples; | ||
313 | offset = offset1; | ||
314 | } | ||
315 | |||
316 | yield(); | ||
317 | |||
318 | cmd = shorten_decode_frame(s, decoded, offset); | ||
319 | |||
320 | if (cmd == FN_VERBATIM || cmd == FN_BITSHIFT || cmd == FN_BLOCKSIZE) { | ||
321 | continue; | ||
322 | } else if (cmd == FN_QUIT || cmd == FN_ERROR) { | ||
323 | break; | ||
324 | } | ||
325 | |||
326 | *nsamples += chan * s->blocksize; | ||
327 | n++; | ||
328 | } | ||
329 | |||
330 | if (*nsamples) { | ||
331 | /* Wrap the samples for the next loop */ | ||
332 | int i; | ||
333 | for (i = 0; i < s->nwrap; i++) { | ||
334 | decoded0[i] = decoded0[*nsamples + i]; | ||
335 | decoded1[i] = decoded1[*nsamples + i]; | ||
336 | } | ||
337 | |||
338 | /* Scale the samples for the pcmbuf */ | ||
339 | int scale = SHN_OUTPUT_DEPTH - s->bits_per_sample; | ||
340 | #if defined(CPU_COLDFIRE) | ||
341 | coldfire_lshift_samples(*nsamples, scale, decoded0 + s->nwrap); | ||
342 | coldfire_lshift_samples(*nsamples, scale, decoded1 + s->nwrap); | ||
343 | #else | ||
344 | for (i = 0; i < *nsamples; i++) { | ||
345 | decoded0[i + s->nwrap] <<= scale; | ||
346 | decoded1[i + s->nwrap] <<= scale; | ||
347 | } | ||
348 | #endif | ||
349 | } | ||
350 | |||
351 | return cmd; | ||
352 | } | ||
353 | |||
354 | static int decode_wave_header(ShortenContext *s, | ||
355 | uint8_t *header, | ||
356 | int header_size) | ||
357 | { | ||
358 | GetBitContext hb; | ||
359 | int len; | ||
360 | |||
361 | init_get_bits(&hb, header, header_size*8); | ||
362 | if (get_le32(&hb) != MKTAG('R','I','F','F')) { | ||
363 | return -8; | ||
364 | } | ||
365 | |||
366 | int chunk_size = get_le32(&hb); | ||
367 | |||
368 | if (get_le32(&hb) != MKTAG('W','A','V','E')) { | ||
369 | return -9; | ||
370 | } | ||
371 | |||
372 | while (get_le32(&hb) != MKTAG('f','m','t',' ')) { | ||
373 | len = get_le32(&hb); | ||
374 | skip_bits(&hb, 8*len); | ||
375 | } | ||
376 | |||
377 | len = get_le32(&hb); | ||
378 | if (len < 16) { | ||
379 | return -10; | ||
380 | } | ||
381 | |||
382 | if (get_le16(&hb) != WAVE_FORMAT_PCM ) { | ||
383 | return -11; | ||
384 | } | ||
385 | |||
386 | s->channels = get_le16(&hb); | ||
387 | if (s->channels > MAX_CHANNELS) { | ||
388 | return -3; | ||
389 | } | ||
390 | |||
391 | s->sample_rate = get_le32(&hb); | ||
392 | |||
393 | skip_bits(&hb, 32); | ||
394 | //s->bit_rate = 8*get_le32(&hb); | ||
395 | |||
396 | int block_align = get_le16(&hb); | ||
397 | s->totalsamples = (chunk_size - 36) / block_align; | ||
398 | |||
399 | s->bits_per_sample = get_le16(&hb); | ||
400 | if (s->bits_per_sample != 16) { | ||
401 | return -12; | ||
402 | } | ||
403 | |||
404 | len -= 16; | ||
405 | if (len > 0) { | ||
406 | return len; | ||
407 | } | ||
408 | |||
409 | return 0; | ||
410 | } | ||
411 | |||
412 | int shorten_init(ShortenContext* s, uint8_t *buf, int buf_size) | ||
413 | { | ||
414 | int i; | ||
415 | |||
416 | s->blocksize = DEFAULT_BLOCK_SIZE; | ||
417 | s->channels = 1; | ||
418 | s->nmean = -1; | ||
419 | |||
420 | init_get_bits(&s->gb, buf, buf_size*8); | ||
421 | get_bits(&s->gb, s->bitindex); | ||
422 | |||
423 | /* shorten signature */ | ||
424 | if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("ajkg"))) { | ||
425 | return -1; | ||
426 | } | ||
427 | |||
428 | s->version = get_bits(&s->gb, 8); | ||
429 | |||
430 | int internal_ftype = get_uint(s, TYPESIZE); | ||
431 | if ((internal_ftype != TYPE_S16HL) && (internal_ftype != TYPE_S16LH)) { | ||
432 | return -2; | ||
433 | } | ||
434 | |||
435 | s->channels = get_uint(s, CHANSIZE); | ||
436 | if (s->channels > MAX_CHANNELS) { | ||
437 | return -3; | ||
438 | } | ||
439 | |||
440 | /* get blocksize if version > 0 */ | ||
441 | int maxnlpc = 0; | ||
442 | if (s->version > 0) { | ||
443 | s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); | ||
444 | maxnlpc = get_uint(s, LPCQSIZE); | ||
445 | s->nmean = get_uint(s, 0); | ||
446 | |||
447 | int skip_bytes = get_uint(s, NSKIPSIZE); | ||
448 | for (i=0; i<skip_bytes; i++) { | ||
449 | skip_bits(&s->gb, 8); | ||
450 | } | ||
451 | } | ||
452 | |||
453 | if (s->nmean > MAX_NMEAN) { | ||
454 | return -4; | ||
455 | } | ||
456 | |||
457 | s->nwrap = FFMAX(NWRAP, maxnlpc); | ||
458 | if (s->nwrap > MAX_NWRAP) { | ||
459 | return -5; | ||
460 | } | ||
461 | |||
462 | if (s->version > 1) | ||
463 | s->lpcqoffset = V2LPCQOFFSET; | ||
464 | |||
465 | if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { | ||
466 | return -6; | ||
467 | } | ||
468 | |||
469 | uint8_t header[MAX_HEADER_SIZE]; | ||
470 | int header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); | ||
471 | if (header_size >= MAX_HEADER_SIZE || header_size < CANONICAL_HEADER_SIZE) { | ||
472 | return -7; | ||
473 | } | ||
474 | |||
475 | for (i=0; i<header_size; i++) | ||
476 | header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); | ||
477 | |||
478 | s->header_bits = s->gb.index; | ||
479 | |||
480 | return decode_wave_header(s, header, header_size); | ||
481 | } | ||
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/shndec.h b/lib/rbcodec/codecs/libffmpegFLAC/shndec.h new file mode 100644 index 0000000000..068f4faf28 --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/shndec.h | |||
@@ -0,0 +1,52 @@ | |||
1 | #include "bitstream.h" | ||
2 | |||
3 | #define SHN_OUTPUT_DEPTH 29 /* 28 bits + sign */ | ||
4 | |||
5 | #define MAX_CHANNELS 2 | ||
6 | #define MAX_PRED_ORDER 16 | ||
7 | #define MAX_NWRAP MAX_PRED_ORDER | ||
8 | #define MAX_NMEAN 4 | ||
9 | |||
10 | /* NUM_DEC_LOOPS should be even number */ | ||
11 | #define NUM_DEC_LOOPS 26 | ||
12 | #define DEFAULT_BLOCK_SIZE 256 | ||
13 | #define MAX_HEADER_SIZE DEFAULT_BLOCK_SIZE*4 | ||
14 | #define MAX_BUFFER_SIZE 2*DEFAULT_BLOCK_SIZE*NUM_DEC_LOOPS | ||
15 | #define MAX_DECODE_SIZE ((DEFAULT_BLOCK_SIZE*NUM_DEC_LOOPS/2) + MAX_NWRAP) | ||
16 | #define MAX_OFFSET_SIZE MAX_NMEAN | ||
17 | |||
18 | #define FN_DIFF0 0 | ||
19 | #define FN_DIFF1 1 | ||
20 | #define FN_DIFF2 2 | ||
21 | #define FN_DIFF3 3 | ||
22 | #define FN_QUIT 4 | ||
23 | #define FN_BLOCKSIZE 5 | ||
24 | #define FN_BITSHIFT 6 | ||
25 | #define FN_QLPC 7 | ||
26 | #define FN_ZERO 8 | ||
27 | #define FN_VERBATIM 9 | ||
28 | #define FN_ERROR 10 | ||
29 | |||
30 | typedef struct ShortenContext { | ||
31 | GetBitContext gb; | ||
32 | int32_t lpcqoffset; | ||
33 | uint32_t totalsamples; | ||
34 | int header_bits; | ||
35 | int channels; | ||
36 | int sample_rate; | ||
37 | int bits_per_sample; | ||
38 | int version; | ||
39 | int bitshift; | ||
40 | int last_bitshift; | ||
41 | int nmean; | ||
42 | int nwrap; | ||
43 | int blocksize; | ||
44 | int bitindex; | ||
45 | } ShortenContext; | ||
46 | |||
47 | int shorten_init(ShortenContext* s, uint8_t *buf, int buf_size); | ||
48 | int shorten_decode_frames(ShortenContext *s, int *nsamples, | ||
49 | int32_t *decoded0, int32_t *decoded1, | ||
50 | int32_t *offset0, int32_t *offset1, | ||
51 | uint8_t *buf, int buf_size, | ||
52 | void (*yield)(void)) ICODE_ATTR; | ||