Hi,
Wanted to try and write some code that could deal with Flac files. (http://flac.sourceforge.net/)
The problem I have now is when I load the Metadata blocks.
Inside the blockheader is 24 bits that shows how long the block is. If I'm not mistaken, 24 bits is equal to 3 bytes. So I need to load these three bytes to get the length. If I use ReadInt( filestream ) it will read four bytes, so I guess I must use ReadByte() and do some bitshifts to get the correct length of the block.
This is what I have at the moment and it's not working at all since it gives me some strange sizes:
The first block (StreamInfo) is reported to be 18 bytes. I guess that could be right since a block can be from 16 to 65535 bytes long.
The next block is reported to be 14483481 bytes long. That doesn't seems right to me, and then the app freezes while trying to jump to the next block after that.
So... What did I do wrong? I have tried to rearrange the b1,b2,b3 vars and then 0,8,16 values but can't get anything that works right. changing Shr to Shl doesn't help either.
The Flac files is written in BigEndian format. (edit: and i load the file using bigendian:: in front of the filename)
Or am I overcomplicating things here?
Wanted to try and write some code that could deal with Flac files. (http://flac.sourceforge.net/)
The problem I have now is when I load the Metadata blocks.
Inside the blockheader is 24 bits that shows how long the block is. If I'm not mistaken, 24 bits is equal to 3 bytes. So I need to load these three bytes to get the length. If I use ReadInt( filestream ) it will read four bytes, so I guess I must use ReadByte() and do some bitshifts to get the correct length of the block.
This is what I have at the moment and it's not working at all since it gives me some strange sizes:
' Length of this block Local b1:Byte = ReadByte(fs) Local b2:Byte = ReadByte(fs) Local b3:Byte = ReadByte(fs) Local blen:Int = (b3 Shr 0) | (b2 Shr 8) | (b1 Shr 16) Print " Block length in bytes: "+blen
The first block (StreamInfo) is reported to be 18 bytes. I guess that could be right since a block can be from 16 to 65535 bytes long.
The next block is reported to be 14483481 bytes long. That doesn't seems right to me, and then the app freezes while trying to jump to the next block after that.
So... What did I do wrong? I have tried to rearrange the b1,b2,b3 vars and then 0,8,16 values but can't get anything that works right. changing Shr to Shl doesn't help either.
The Flac files is written in BigEndian format. (edit: and i load the file using bigendian:: in front of the filename)
Or am I overcomplicating things here?