-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
843 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <crc32.h> | ||
#include <zlib.h> | ||
|
||
|
||
int CRC32FromFile(FILE *file, long from, long to, unsigned long *crc) | ||
{ | ||
if(from >= to) | ||
{ | ||
fprintf(stderr, "Invalid span of data for CRC: from = %li; to = %li!\n", from, to); | ||
return -1; | ||
} | ||
|
||
// Create Buffer | ||
unsigned char *buffer; | ||
size_t buffersize = to-from; | ||
|
||
buffer = malloc(buffersize * sizeof(char)); | ||
if(buffer == NULL) | ||
{ | ||
fprintf(stderr, "%s, %i: ", __FILE__, __LINE__); | ||
fprintf(stderr, "Fatal Error! - malloc returned NULL!\n"); | ||
return -1; | ||
} | ||
|
||
// Go to begin of relevant data | ||
int error; | ||
error = fseek(file, from, SEEK_SET); | ||
if(error != 0) | ||
{ | ||
fprintf(stderr, "%s, %i: ", __FILE__, __LINE__); | ||
fprintf(stderr, "Fatal Error! - Setting correct file position failed!\n"); | ||
return -1; | ||
} | ||
|
||
// Read File | ||
size_t bytesread; | ||
bytesread = fread(buffer, 1, buffersize, file); | ||
if(bytesread != buffersize) | ||
{ | ||
fprintf(stderr, "%s, %i: ", __FILE__, __LINE__); | ||
fprintf(stderr, "Fatal Error! - Only %zu of %zu bytes read from file!\n", bytesread, buffersize); | ||
return -1; | ||
} | ||
|
||
// Calculate CRC32 | ||
if(crc == NULL) | ||
return 0; | ||
*crc = crc32(0x00000000, buffer, buffersize); | ||
|
||
// Clean up | ||
free(buffer); | ||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef CRC32_H | ||
#define CRC32_H | ||
|
||
#include <stdio.h> | ||
|
||
int CRC32FromFile(FILE *file, long from, long to, unsigned long *crc); | ||
|
||
|
||
#endif | ||
|
||
|
||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <stdlib.h> | ||
#include <endian.h> | ||
#include <encoding/crc.h> | ||
|
||
|
||
void ID3V2_EncodeCRC(unsigned long crc, unsigned char enccrc[5]) | ||
{ | ||
if(enccrc == NULL) | ||
return; | ||
|
||
// 1.: LE -> BE | ||
unsigned long becrc; | ||
//becrc = htobe32(crc); | ||
becrc = crc; | ||
|
||
// 1.: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
// -> 0000xxxx0xxxxxxx0xxxxxxx0xxxxxxx0xxxxxxx | ||
unsigned int byte = 0; | ||
for(int i=0; i<5; i++) | ||
{ | ||
byte = becrc >> ((4-i)*7); | ||
byte &= 0x7F; | ||
enccrc[i] = byte; | ||
} | ||
|
||
return; | ||
} | ||
|
||
void ID3V2_DecodeCRC(unsigned long *crc, const unsigned char enccrc[5]) | ||
{ | ||
if(crc == NULL || enccrc == NULL) | ||
return; | ||
|
||
// 1.: 0000xxxx0xxxxxxx0xxxxxxx0xxxxxxx0xxxxxxx | ||
// -> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
unsigned int byte = 0; | ||
unsigned long tmp = 0; | ||
for(int i=0; i<5; i++) | ||
{ | ||
byte = enccrc[i]; | ||
byte &= 0x7F; | ||
tmp |= byte << ((4-i)*7); | ||
} | ||
|
||
*crc = tmp; | ||
return; | ||
} | ||
|
||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef ENCODING_CRC_H | ||
#define ENCODING_CRC_H | ||
|
||
|
||
void ID3V2_EncodeCRC(unsigned long crc, unsigned char enccrc[5]); | ||
void ID3V2_DecodeCRC(unsigned long *crc, const unsigned char enccrc[5]); | ||
|
||
|
||
#endif | ||
|
||
|
||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <errno.h> | ||
#include <endian.h> | ||
#include <encoding/size.h> | ||
|
||
|
||
unsigned int ID3V2_EncodeSize(unsigned int size) | ||
{ | ||
// 1.: 0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
// -> 0xxxxxxx0xxxxxxx0xxxxxxx0xxxxxxx | ||
unsigned int byte = 0; | ||
unsigned int tmp = 0; | ||
for(int i=0; i<4; i++) | ||
{ | ||
byte = size >> (i*7); | ||
byte &= 0x7F; | ||
tmp |= byte << (i*8); | ||
} | ||
|
||
// 2.: LE -> BE | ||
unsigned int encsize; | ||
encsize = htobe32(tmp); | ||
|
||
return encsize; | ||
} | ||
|
||
unsigned int ID3V2_DecodeSize(unsigned int encsize) | ||
{ | ||
// 1.: BE -> LE | ||
unsigned int tmp; | ||
tmp = be32toh(encsize); | ||
|
||
// 2.: 0xxxxxxx0xxxxxxx0xxxxxxx0xxxxxxx | ||
// -> 0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
unsigned int byte = 0; | ||
unsigned int size = 0; | ||
for(int i=0; i<4; i++) | ||
{ | ||
byte = tmp >> (i*8); | ||
byte &= 0x7F; | ||
size |= byte << (i*7); | ||
} | ||
|
||
return size; | ||
} | ||
|
||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef ENCODING_SIZE_H | ||
#define ENCODING_SIZE_H | ||
|
||
|
||
unsigned int ID3V2_EncodeSize(unsigned int size); | ||
unsigned int ID3V2_DecodeSize(unsigned int encsize); | ||
|
||
|
||
#endif | ||
|
||
|
||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.