summaryrefslogtreecommitdiff
path: root/libavcodec/adpcm.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2010-11-12 12:30:27 +0000
committerMartin Storsjö <martin@martin.st>2010-11-12 12:30:27 +0000
commit38b3bda18f07a1a8dd18437105a12427c5a90c1c (patch)
treeb381272f230504ee0001d64da1e529a412910ed9 /libavcodec/adpcm.c
parent4106b7f1cd7151804e1138c473550cf20354c39b (diff)
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
Diffstat (limited to 'libavcodec/adpcm.c')
-rw-r--r--libavcodec/adpcm.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index bdcd985949..60adebe8d0 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -387,18 +387,10 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
if (heap_pos < frontier) {\
pos = heap_pos++;\
} else {\
- /* Find the largest node in the heap, which is one \
- * of the leaf nodes. */\
- int maxpos = 0;\
- uint32_t max_ssd = 0;\
- 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)\
+ /* Try to replace one of the leaf nodes with the new \
+ * one, but try a different slot each time. */\
+ pos = (frontier >> 1) + (heap_pos++ & ((frontier >> 1) - 1));\
+ if (ssd > nodes_next[pos]->ssd)\
goto next_##NAME;\
}\
u = nodes_next[pos];\