summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/libtremor/ffmpeg_render_line.h73
-rw-r--r--apps/codecs/libtremor/floor1.c52
2 files changed, 74 insertions, 51 deletions
diff --git a/apps/codecs/libtremor/ffmpeg_render_line.h b/apps/codecs/libtremor/ffmpeg_render_line.h
new file mode 100644
index 0000000000..c429c274e6
--- /dev/null
+++ b/apps/codecs/libtremor/ffmpeg_render_line.h
@@ -0,0 +1,73 @@
1/**
2 * @file
3 * Common code for Vorbis I encoder and decoder
4 * @author Denes Balatoni ( dbalatoni programozo hu )
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/* render_line and friend taken from ffmpeg (libavcodec/vorbis.c) */
24static inline void render_line_unrolled(int x, int y, int x1,
25 int sy, int ady, int adx,
26 ogg_int32_t *buf)
27{
28 int err = -adx;
29 x -= x1 - 1;
30 buf += x1 - 1;
31 while (++x < 0) {
32 err += ady;
33 if (err >= 0) {
34 err += ady - adx;
35 y += sy;
36 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
37 x++;
38 }
39 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
40 }
41 if (x <= 0) {
42 if (err + ady >= 0)
43 y += sy;
44 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
45 }
46}
47
48static void render_line(int x0, int y0, int x1, int y1, ogg_int32_t *buf)
49{
50 int dy = y1 - y0;
51 int adx = x1 - x0;
52 int ady = abs(dy);
53 int sy = dy < 0 ? -1 : 1;
54 buf[x0] = MULT31_SHIFT15(buf[x0],FLOOR_fromdB_LOOKUP[y0]);
55 if (ady*2 <= adx) { // optimized common case
56 render_line_unrolled(x0, y0, x1, sy, ady, adx, buf);
57 } else {
58 int base = dy / adx;
59 int x = x0;
60 int y = y0;
61 int err = -adx;
62 ady -= abs(base) * adx;
63 while (++x < x1) {
64 y += base;
65 err += ady;
66 if (err >= 0) {
67 err -= adx;
68 y += sy;
69 }
70 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
71 }
72 }
73}
diff --git a/apps/codecs/libtremor/floor1.c b/apps/codecs/libtremor/floor1.c
index 1ea7ee99b5..0d3828c816 100644
--- a/apps/codecs/libtremor/floor1.c
+++ b/apps/codecs/libtremor/floor1.c
@@ -274,57 +274,7 @@ static const ogg_int32_t FLOOR_fromdB_LOOKUP[256] ICONST_ATTR = {
274 XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff), 274 XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff),
275}; 275};
276 276
277/* render_line and friend taken from ffmpeg (libavcodec/vorbis.c) */ 277#include "ffmpeg_render_line.h"
278static inline void render_line_unrolled(int x, int y, int x1,
279 int sy, int ady, int adx,
280 ogg_int32_t *buf)
281{
282 int err = -adx;
283 x -= x1 - 1;
284 buf += x1 - 1;
285 while (++x < 0) {
286 err += ady;
287 if (err >= 0) {
288 err += ady - adx;
289 y += sy;
290 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
291 x++;
292 }
293 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
294 }
295 if (x <= 0) {
296 if (err + ady >= 0)
297 y += sy;
298 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
299 }
300}
301
302static void render_line(int x0, int y0, int x1, int y1, ogg_int32_t *buf)
303{
304 int dy = y1 - y0;
305 int adx = x1 - x0;
306 int ady = abs(dy);
307 int sy = dy < 0 ? -1 : 1;
308 buf[x0] = MULT31_SHIFT15(buf[x0],FLOOR_fromdB_LOOKUP[y0]);
309 if (ady*2 <= adx) { // optimized common case
310 render_line_unrolled(x0, y0, x1, sy, ady, adx, buf);
311 } else {
312 int base = dy / adx;
313 int x = x0;
314 int y = y0;
315 int err = -adx;
316 ady -= abs(base) * adx;
317 while (++x < x1) {
318 y += base;
319 err += ady;
320 if (err >= 0) {
321 err -= adx;
322 y += sy;
323 }
324 buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]);
325 }
326 }
327}
328 278
329static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in) 279static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in)
330 ICODE_ATTR_TREMOR_NOT_MDCT; 280 ICODE_ATTR_TREMOR_NOT_MDCT;