Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Generating a CRC for my OGG header (Read 2336 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Generating a CRC for my OGG header

Hi there,
I have a small app which writes id3 tags and I am expanding it to write vorbis tags as well, but I have hit a snag. I am having difficult computing the CRC value of my Ogg stream headers.

To test my code, I am trying to generate a CRC on the first Ogg header in an ogg file which plays fine in winamp. Unfortunately it is never correct.

My polynomial generator is: 0x04C11DB7
and my initial val and XOR are set to 0

I have tested the CRC function against several published CRC test values so I am sure it is right. I am wondering if I am not reading in the correct part of the header.

Can someone please confirm for me which part of the header the CRC is calculated over? Currently I am using the first 58 bytes of the file which, according to the documentation, is the length of the first header and its page contents.

Does this seem right?

Cheers,
BJW

 

Generating a CRC for my OGG header

Reply #1
If I remember correctly the Vorbis format uses a different bit order. Try reversing the bit order of each byte before updating the CRC state. Also, the CRC checksum is stored in the little endian (intel byte order).

Code: [Select]
unsigned reverse8bits(unsigned v) {
   v = ((v & 0xF0) >> 4) | ((v & 0x0F) << 4);
   v = ((v & 0xCC) >> 2) | ((v & 0x33) << 2);
   v = ((v & 0xAA) >> 1) | ((v & 0x55) << 1);
   return v;
}


This is admittedly a very unusual variant of computing CRC checksums. Be sure to check out the source code which is available.

Cheers,
SG