No, getWordsLossless is still incomplete...
authorPHO <pho@cielonegro.org>
Fri, 15 Jul 2011 18:16:58 +0000 (03:16 +0900)
committerPHO <pho@cielonegro.org>
Fri, 15 Jul 2011 18:16:58 +0000 (03:16 +0900)
Codec/Audio/WavPack/Words.hs

index a8677fe41437faefa335b69634a66cafa9420e53..ae61d8a6e8e097e88f37d8a77ff4448ba2faf8ec 100644 (file)
@@ -90,8 +90,7 @@ getWordsLossless isMono w0 bs0 nSamples0
                     let w' = w { wdZeroesAcc = wdZeroesAcc w - 1 }
                     in
                       if wdZeroesAcc w' > 0 then
-                          let v' = New.modify (\mv → MV.unsafeWrite mv n 0) v
-                              n' = n + 1
+                          let (# n', v' #) = appendWord 0 n v
                           in
                             go0 w' bs n' v'
                       else
@@ -111,8 +110,8 @@ getWordsLossless isMono w0 bs0 nSamples0
                                                 ( clearMedian $ fst $ wdEntropyData w'
                                                 , clearMedian $ snd $ wdEntropyData w' )
                                           }
-                                    v'  = New.modify (\mv → MV.unsafeWrite mv n 0) v
-                                    n'  = n + 1
+                                    (# n', v' #)
+                                        = appendWord 0 n v
                                 in
                                   go0 w'' bs'' n' v'
                             else
@@ -199,16 +198,23 @@ getWordsLossless isMono w0 bs0 nSamples0
           = let (# code, bs' #)
                      = readCode bs (high - low)
                 low' = low + code
-                a    = if B.head bs' then
+                word = if B.head bs' then
                            fromIntegral $ complement low'
                        else
                            fromIntegral low'
                 bs'' = B.tail bs'
-                v'   = New.modify (\mv → MV.unsafeWrite mv n a) v
-                n'   = n + 1
+                (# n', v' #)
+                     = appendWord word n v
             in
               go0 w bs'' n' v'
 
+      appendWord ∷ Int32 → Int → New v Int32 → (# Int, New v Int32 #)
+      appendWord word n v
+          = let v' = New.modify (\mv → MV.unsafeWrite mv n word) v
+                n' = n + 1
+            in
+              (# n', v' #)
+
       getEntropy ∷ Int → WordsData → EntropyData
       getEntropy n w
           | isMono        = fst $ wdEntropyData w