Fixed support for >64 bit FS for good, fixed init bug
authorMathis Rosenhauer <rosenhauer@dkrz.de>
Wed, 15 Aug 2012 14:34:03 +0000 (16:34 +0200)
committerMathis Rosenhauer <rosenhauer@dkrz.de>
Wed, 15 Aug 2012 14:34:03 +0000 (16:34 +0200)
src/aed.c
src/aee.c

index adadfad..e2ae370 100644 (file)
--- a/src/aed.c
+++ b/src/aed.c
@@ -329,6 +329,7 @@ int ae_decode_init(ae_streamp strm)
 
     state->samples_out = 0;
     state->bitp = 0;
+    state->fs = 0;
     state->pp = strm->flags & AE_DATA_PREPROCESS;
     state->mode = M_ID;
     return AE_OK;
@@ -363,21 +364,34 @@ int ae_decode_end(ae_streamp strm)
 
 #define DROP(n) state->bitp -= (unsigned)(n)
 
-#define ASKFS()                          \
-    do {                                 \
-        ASK(1);                          \
-        while (GET(1) == 0)              \
-        {                                \
-            state->fs++;                 \
-            DROP(1);                     \
-            ASK(1);                      \
-        }                                \
-        DROP(1);                         \
-    } while(0)
+#define ASKFS()                                                 \
+    do {                                                        \
+        ASK(1);                                                 \
+        while ((state->acc & (1ULL << (state->bitp - 1))) == 0) \
+        {                                                       \
+            if (state->bitp == 1)                               \
+            {                                                   \
+                if (strm->avail_in == 0) goto req_buffer;       \
+                strm->avail_in--;                               \
+                strm->total_in++;                               \
+                state->acc <<= 8;                               \
+                state->acc |= *strm->next_in++;                 \
+                state->bitp += 8;                               \
+            }                                                   \
+            state->fs++;                                        \
+            state->bitp--;                                      \
+        }                                                       \
+    } while (0)
 
 #define GETFS() state->fs
 
-#define DROPFS() state->fs = 0;
+#define DROPFS()                                \
+    do {                                        \
+        state->fs = 0;                          \
+        /* Needs to be here for                 \
+           ASK/GET/PUT/DROP interleaving. */    \
+        state->bitp--;                          \
+    } while (0)
 
 #define PUT(sample)                                \
     do {                                           \
index 4c36d30..4c7ef7b 100644 (file)
--- a/src/aee.c
+++ b/src/aee.c
@@ -193,6 +193,7 @@ int ae_encode_init(ae_streamp strm)
         return AE_MEM_ERROR;
     }
     state->bp_out = state->block_out;
+    *state->bp_out = 0;
     state->bitp = 8;
 
     strm->total_in = 0;