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: Extra byte in frame header (Read 5203 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Extra byte in frame header

Alright, well I'm almost done with my decoder but there's some twilight zone stuff going on.  I'm working on decoding a .flac file and when it gets to frame 0x80 I read:


[Sync][Block Size ][Sample Rate][Ch. Assign][Sample Size]          [Frame #][CRC8]
FF F8    3           9                  0                   8            C2        80              AF

and the subsequent frame headers have the extra c2 in front of the frame number.

Once I get to frame 0xC0 i get:

FF F8    3           9             0                     8          C3        80            BA         

What am I supposed to do with the extra byte, and when should I expect it?  I encoded with the front end encoder and I also noticed these flac files won't work with my windows media player codec, while all the other flac files I've had would.  I encoded with max lpc order = 0 if that makes any difference.

Extra byte in frame header

Reply #1
The frame number is stored as a UTF-8 encoded value, which takes up a variable amount of bytes as it grows.  You can use something like the following in order to decode it:
Code: [Select]
int read_utf8(bitstream) {
  int total_bytes = read_unary(bitstream, 0);   /*count the number of 1 bits before the next 0 bit*/
  int value = read(bitstream, 7 - total_bytes); /*grab the remainder of the first byte as our initial value*/
  for (; total_bytes > 1; total_bytes--) {
     assert(read(bitstream, 2) == 2);           /*the top 2 bits of each subsequent byte should be 10b*/
     value = (value << 6) | read(bitstream, 6); /*prepend the remaining 6 bits to our value*/
  }

  return value;
}

Extra byte in frame header

Reply #2
Thanks for the help again.  I hope I can return the favor.

The frame number is stored as a UTF-8 encoded value, which takes up a variable amount of bytes as it grows.  You can use something like the following in order to decode it:
Code: [Select]
int read_utf8(bitstream) {
  int total_bytes = read_unary(bitstream, 0);   /*count the number of 1 bits before the next 0 bit*/
  int value = read(bitstream, 7 - total_bytes); /*grab the remainder of the first byte as our initial value*/
  for (; total_bytes > 1; total_bytes--) {
     assert(read(bitstream, 2) == 2);           /*the top 2 bits of each subsequent byte should be 10b*/
     value = (value << 6) | read(bitstream, 6); /*prepend the remaining 6 bits to our value*/
  }

  return value;
}