Commit 38b3bda1 authored by Martin Storsjö's avatar Martin Storsjö

adpcm: Replace any of the leaf nodes in the heap

By not looking for the exactly largest node, we avoid an O(n) seek through
the leaf nodes. Just pick one (not the same one every time) and try replacing
that node with the new one.

For -trellis 8, this lowers the run time from 190 to 158 seconds,
for a 30 second 44 kHz mono sample, on my machine.

Originally committed as revision 25733 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 4106b7f1
...@@ -387,18 +387,10 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, ...@@ -387,18 +387,10 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
if (heap_pos < frontier) {\ if (heap_pos < frontier) {\
pos = heap_pos++;\ pos = heap_pos++;\
} else {\ } else {\
/* Find the largest node in the heap, which is one \ /* Try to replace one of the leaf nodes with the new \
* of the leaf nodes. */\ * one, but try a different slot each time. */\
int maxpos = 0;\ pos = (frontier >> 1) + (heap_pos++ & ((frontier >> 1) - 1));\
uint32_t max_ssd = 0;\ if (ssd > nodes_next[pos]->ssd)\
for (k = frontier >> 1; k < frontier; k++) {\
if (nodes_next[k]->ssd > max_ssd) {\
maxpos = k;\
max_ssd = nodes_next[k]->ssd;\
}\
}\
pos = maxpos;\
if (ssd > max_ssd)\
goto next_##NAME;\ goto next_##NAME;\
}\ }\
u = nodes_next[pos];\ u = nodes_next[pos];\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment