Compression

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Need help using Arithmetic Code

    8 answers - 834 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I am trying to learn arithmetic coding, but the code I am using which
    prolly works, but when I use it with some modification now doesn't :(.
    The code is well known I believe, Mark Nelson's Arithmetic code in C -
    previously a remake of some CACM article (?). The changes I made are
    basically :
    1) change the shorts to unsigned longs to accomdate values larger then
    65k.
    2) Instead of reading from a file it reads from an array of bytes.
    The error I get is that in the function get_count the range varible
    manages to be 0. meaning "High" is one less then "Low". My
    understanding of the implementation of AC is bad. I understand the
    concept but not the bit shifting and all that good stuff. Anybody think
    they can help me?
    Thanks agian
    T. Jackson
  • No.1 | | 502 bytes | |

    Good news, I am continuely working on this so any suggestions are
    welcome. I got it to go "further" but still end up with the same error.
    Simply by removing some casting that effected the numbers. Also another
    question, since the global "high" goes below the "low" is that a safe
    time to "reset" them?

    Well like I said any suggestions are appreciated, I gotta put it away
    and do more work in the morning with some freash eyes.

    Thanks again,
    T. Jackson

  • No.2 | | 878 bytes | |


    Tjackson.1982@gmail.com wrote:
    Good news, I am continuely working on this so any suggestions are
    welcome. I got it to go "further" but still end up with the same error.
    Simply by removing some casting that effected the numbers. Also another
    question, since the global "high" goes below the "low" is that a safe
    time to "reset" them?

    Well like I said any suggestions are appreciated, I gotta put it away
    and do more work in the morning with some freash eyes.

    You might want to take a look at

    I have modified that same code to use 64-bit variables. You are
    planning to use 32-bit variables, I think it will be easy to see
    correlations between what all needs to be edited.

    Link to download the code is near the bottom of the page.

    Best of luck

    Sachin Garg [India]
    http://www.sachingarg.com

  • No.3 | | 676 bytes | |


    <Tjackson.1982@gmail.comwrote in message
    news:1144722622.763225.114000@
    The error I get is that in the function get_count the range varible
    manages to be 0. meaning "High" is one less then "Low". My
    understanding of the implementation of AC is bad. I understand the
    concept but not the bit shifting and all that good stuff. Anybody think
    they can help me?

    It sounds like when you are calculating the range that the variable is
    rolling over to zero again. If you are using the full 32 bits where low =
    0x0 and high = 0xFFFFFFFF , high - low = 0xFFFFFFFF. When you add 1 a 32
    bit value will equal .

    Randy McNabb

  • No.4 | | 824 bytes | |


    "Randy McNabb" <the_frog_man@hotmail.comwrote in message
    news:123msnpb93u9eac@corp.supernews.com

    <Tjackson.1982@gmail.comwrote in message
    news:1144722622.763225.114000@
    The error I get is that in the function get_count the range varible
    manages to be 0. meaning "High" is one less then "Low". My
    understanding of the implementation of AC is bad. I understand the
    concept but not the bit shifting and all that good stuff. Anybody think
    they can help me?

    It sounds like when you are calculating the range that the variable is
    rolling over to zero again. If you are using the full 32 bits where low =
    0x0 and high = 0xFFFFFFFF , high - low = 0xFFFFFFFF. When you add 1 a 32
    bit value will equal .
    correction:
    will equal 0.

    Randy McNabb
    --

  • No.5 | | 1134 bytes | |


    Randy McNabb wrote:
    "Randy McNabb" <the_frog_man@hotmail.comwrote in message
    news:123msnpb93u9eac@corp.supernews.com

    <Tjackson.1982@gmail.comwrote in message
    news:1144722622.763225.114000@
    The error I get is that in the function get_count the range varible
    manages to be 0. meaning "High" is one less then "Low". My
    understanding of the implementation of AC is bad. I understand the
    concept but not the bit shifting and all that good stuff. Anybody think
    they can help me?

    It sounds like when you are calculating the range that the variable is
    rolling over to zero again. If you are using the full 32 bits where low =
    0x0 and high = 0xFFFFFFFF , high - low = 0xFFFFFFFF. When you add 1 a 32
    bit value will equal .
    correction:
    will equal 0.

    My guess on what he has done is that he has only changed data type of
    count variables from short to long and had expected that now he can use
    larger range.

    To use larger range, precision of arithmetic coder needs to be
    increased too.

    Sachin Garg [India]
    http://www.sachingarg.com

  • No.6 | | 450 bytes | |

    Hey thanks everyone.

    Sachin- I actually saw your code, and tried to "merge" the two. I
    suppose I did a half ass job of it. lol I gotta keep hacking away at it
    I suppose.

    Randy - I think that is what happens, but what do I do when that
    happens? Its funny I was thinking it was -1 but since they are unsigned
    long I suppose it would be 0xFFFFFFFF. I will review code and keep
    trying.

    Thanks again.

  • No.7 | | 454 bytes | |

    Hey yes, Good news. what I did was I divided all occurence by 2, thus
    making the scale half. I was then able to retrive some but not all the
    original data. I think after my class ( Master student) I will upgrade
    to 64 integers. I think that will fix the accuracy problems. see the
    scale sometimes is 100k but some ranges are only by 1 so I think
    somtimes the wrong symbol are found.

    Thanks again guys.
    TJackson

  • No.8 | | 797 bytes | |


    <Tjackson.1982@gmail.comwrote in message
    news:1144758803.187519.200350@
    Hey thanks everyone.

    Sachin- I actually saw your code, and tried to "merge" the two. I
    suppose I did a half ass job of it. lol I gotta keep hacking away at it
    I suppose.

    Randy - I think that is what happens, but what do I do when that
    happens? Its funny I was thinking it was -1 but since they are unsigned
    long I suppose it would be 0xFFFFFFFF. I will review code and keep
    trying.

    Thanks again.

    The easiest solution would be to use 64 bit unsigned integers for range. I
    used inline assembly to handle the 32 bit values directly which is a lot
    faster. You must also take care when calculating the new high and low
    values.

    Randy McNabb

Re: Need help using Arithmetic Code


max 4000 letters.
Your nickname that display:
In order to stop the spam: 2 + 1 =
QUESTION ON "Compression"

EMSDN.COM