Update ptformat to upstream 72bd66b
- Fix a wrong assumption in the xor code - Find start of wav list more consistently - Fix long long constants
This commit is contained in:
parent
f0f822feff
commit
124092d139
@ -57,6 +57,26 @@ PTFFormat::~PTFFormat() {
|
||||
}
|
||||
}
|
||||
|
||||
int64_t
|
||||
PTFFormat::foundat(unsigned char *haystack, uint64_t n, const char *needle) {
|
||||
int64_t found = 0;
|
||||
uint64_t i, j, needle_n;
|
||||
needle_n = strlen(needle);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
found = i;
|
||||
for (j = 0; j < needle_n; j++) {
|
||||
if (haystack[i+j] != needle[j]) {
|
||||
found = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found > 0)
|
||||
return found;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool
|
||||
PTFFormat::foundin(std::string haystack, std::string needle) {
|
||||
size_t found = haystack.find(needle);
|
||||
@ -111,17 +131,16 @@ PTFFormat::load(std::string path, int64_t targetsr) {
|
||||
|
||||
xor_type = ptfunxored[0x12];
|
||||
xor_value = ptfunxored[0x13];
|
||||
xor_len = 256;
|
||||
|
||||
// xor_type 0x01 = ProTools 5, 6, 7, 8 and 9
|
||||
// xor_type 0x05 = ProTools 10, 11, 12
|
||||
switch(xor_type) {
|
||||
case 0x01:
|
||||
xor_delta = gen_xor_delta(xor_value, 53, false);
|
||||
xor_len = 256;
|
||||
break;
|
||||
case 0x05:
|
||||
xor_delta = gen_xor_delta(xor_value, 11, true);
|
||||
xor_len = 128;
|
||||
break;
|
||||
default:
|
||||
fclose(fp);
|
||||
@ -138,7 +157,7 @@ PTFFormat::load(std::string path, int64_t targetsr) {
|
||||
i = 0x14;
|
||||
fseek(fp, i, SEEK_SET);
|
||||
while (fread(&ct, 1, 1, fp) != 0) {
|
||||
uint8_t xor_index = (xor_type == 0x01) ? i & 0xff : (i >> 12) & 0x7f;
|
||||
uint8_t xor_index = (xor_type == 0x01) ? i & 0xff : (i >> 12) & 0xff;
|
||||
ptfunxored[i++] = ct ^ xxor[xor_index];
|
||||
}
|
||||
fclose(fp);
|
||||
@ -798,9 +817,13 @@ PTFFormat::parsemidi(void) {
|
||||
void
|
||||
PTFFormat::parseaudio(void) {
|
||||
uint64_t i,j,k,l;
|
||||
int64_t index = foundat(ptfunxored, len, "Audio Files");
|
||||
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
// Find end of wav file list
|
||||
k = 0;
|
||||
k = (uint64_t)index;
|
||||
while (k < len) {
|
||||
if ( (ptfunxored[k ] == 0xff) &&
|
||||
(ptfunxored[k+1] == 0xff) &&
|
||||
@ -815,11 +838,11 @@ PTFFormat::parseaudio(void) {
|
||||
bool first = true;
|
||||
uint16_t numberofwavs;
|
||||
char wavname[256];
|
||||
for (i = k; i > 4; i--) {
|
||||
if ( ((ptfunxored[i ] == 'W') || (ptfunxored[i ] == 'A')) &&
|
||||
((ptfunxored[i-1] == 'A') || (ptfunxored[i-1] == 'I')) &&
|
||||
((ptfunxored[i-2] == 'V') || (ptfunxored[i-2] == 'F')) &&
|
||||
((ptfunxored[i-3] == 'E') || (ptfunxored[i-3] == 'F'))) {
|
||||
for (i = k-2; i > 4; i--) {
|
||||
if ( ((ptfunxored[i ] == 'W') || (ptfunxored[i ] == 'A') || ptfunxored[i ] == '\0') &&
|
||||
((ptfunxored[i-1] == 'A') || (ptfunxored[i-1] == 'I') || ptfunxored[i-1] == '\0') &&
|
||||
((ptfunxored[i-2] == 'V') || (ptfunxored[i-2] == 'F') || ptfunxored[i-2] == '\0') &&
|
||||
((ptfunxored[i-3] == 'E') || (ptfunxored[i-3] == 'F') || ptfunxored[i-3] == '\0')) {
|
||||
j = i-4;
|
||||
l = 0;
|
||||
while (ptfunxored[j] != '\0') {
|
||||
@ -828,10 +851,10 @@ PTFFormat::parseaudio(void) {
|
||||
j--;
|
||||
}
|
||||
wavname[l] = 0;
|
||||
if (ptfunxored[i] == 'W') {
|
||||
extension = string(".wav");
|
||||
} else {
|
||||
if (ptfunxored[i] == 'A') {
|
||||
extension = string(".aif");
|
||||
} else {
|
||||
extension = string(".wav");
|
||||
}
|
||||
//uint8_t playlist = ptfunxored[j-8];
|
||||
|
||||
|
@ -128,6 +128,7 @@ public:
|
||||
|
||||
private:
|
||||
bool foundin(std::string haystack, std::string needle);
|
||||
int64_t foundat(unsigned char *haystack, uint64_t n, const char *needle);
|
||||
int parse(void);
|
||||
bool parse_version();
|
||||
uint8_t gen_xor_delta(uint8_t xor_value, uint8_t mul, bool negative);
|
||||
|
Loading…
Reference in New Issue
Block a user