summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2015-08-09 15:14:55 +1000
committerDamien Zammit <damien@zamaudio.com>2015-08-09 15:14:55 +1000
commit20c0da073145e635ec0cef04674c586d4759f89c (patch)
tree1adf9dfcd60f4862c5499c4d723986ba22ef9919
parent862df2fe130ca754bb6fdb2ccf0638007c955d93 (diff)
Experimenting with pt5pt5experiment
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r--ptfformat.cc177
1 files changed, 146 insertions, 31 deletions
diff --git a/ptfformat.cc b/ptfformat.cc
index 97a18c1..5e05a5e 100644
--- a/ptfformat.cc
+++ b/ptfformat.cc
@@ -438,64 +438,172 @@ PTFFormat::parse10header(void) {
void
PTFFormat::parserest5(void) {
int i, j, k;
- int regionspertrack, lengthofname;
+ int totalregions, regionspertrack, lengthofname;
int startbytes, lengthbytes, offsetbytes, somethingbytes;
uint16_t tracknumber = 0;
uint16_t findex;
uint16_t rindex;
k = 0;
- for (i = 0; i < 5; i++) {
+ while (k < len) {
+ if ( (ptfunxored[k ] == 0x5a) &&
+ (ptfunxored[k+1] == 0x00) &&
+ (ptfunxored[k+2] == 0x05)) {
+ break;
+ }
+ k++;
+ }
+ k++;
+
+ rindex = 0;
+ while (k < len) {
+ if ( (ptfunxored[k ] == 0xff) &&
+ (ptfunxored[k+1] == 0xff)) {
+ break;
+ }
while (k < len) {
if ( (ptfunxored[k ] == 0x5a) &&
(ptfunxored[k+1] == 0x00) &&
- (ptfunxored[k+2] == 0x03)) {
+ (ptfunxored[k+2] == 0x02)) {
break;
}
k++;
}
- k++;
- }
- k--;
- for (i = 0; i < 2; i++) {
- while (k > 0) {
- if ( (ptfunxored[k ] == 0x5a) &&
- (ptfunxored[k+1] == 0x00) &&
- (ptfunxored[k+2] == 0x01)) {
+ lengthofname = ptfunxored[k+12];
+ if (lengthofname == 0 || lengthofname == 0x5a || ptfunxored[k+13] < 30) {
+ k++;
+ continue;
+ }
+
+ char name[256] = {0};
+ for (j = 0; j < lengthofname; j++) {
+ name[j] = ptfunxored[k+13+j];
+ }
+ name[j] = '\0';
+ j = k+14;
+ startbytes = (ptfunxored[j+3] & 0xf0) >> 4;
+ lengthbytes = (ptfunxored[j+2] & 0xf0) >> 4;
+ offsetbytes = (ptfunxored[j+1] & 0xf0) >> 4;
+ somethingbytes = (ptfunxored[j+1] & 0xf);
+ findex = ptfunxored[j+4
+ +startbytes
+ +lengthbytes
+ +offsetbytes
+ +somethingbytes
+ +3];
+ j--;
+ uint32_t start = 0;
+ switch (startbytes) {
+ case 4:
+ start |= (uint32_t)(ptfunxored[j+8] << 24);
+ case 3:
+ start |= (uint32_t)(ptfunxored[j+7] << 16);
+ case 2:
+ start |= (uint32_t)(ptfunxored[j+6] << 8);
+ case 1:
+ start |= (uint32_t)(ptfunxored[j+5]);
+ default:
+ break;
+ }
+ j+=startbytes;
+ uint32_t length = 0;
+ switch (lengthbytes) {
+ case 4:
+ length |= (uint32_t)(ptfunxored[j+8] << 24);
+ case 3:
+ length |= (uint32_t)(ptfunxored[j+7] << 16);
+ case 2:
+ length |= (uint32_t)(ptfunxored[j+6] << 8);
+ case 1:
+ length |= (uint32_t)(ptfunxored[j+5]);
+ default:
+ break;
+ }
+ j+=lengthbytes;
+ uint32_t sampleoffset = 0;
+ switch (offsetbytes) {
+ case 4:
+ sampleoffset |= (uint32_t)(ptfunxored[j+8] << 24);
+ case 3:
+ sampleoffset |= (uint32_t)(ptfunxored[j+7] << 16);
+ case 2:
+ sampleoffset |= (uint32_t)(ptfunxored[j+6] << 8);
+ case 1:
+ sampleoffset |= (uint32_t)(ptfunxored[j+5]);
+ default:
break;
}
- k--;
+ j+=offsetbytes;
+
+ if (length == 0) {
+ k++;
+ continue;
+ }
+ std::string filename = string(name) + extension;
+ wav_t f = {
+ filename,
+ 0,
+ start,
+ length
+ };
+ printf("n = %s ln = %d\n", name, lengthofname);
+ vector<wav_t>::iterator begin = actualwavs.begin();
+ vector<wav_t>::iterator finish = actualwavs.end();
+ vector<wav_t>::iterator found;
+ // Add file to lists
+ if ((found = std::find(begin, finish, f)) != finish) {
+ printf("found.index = %d\n", (*found).index);
+ audiofiles.push_back(*found);
+ region_t r = {
+ name,
+ rindex,
+ (int64_t)((*found).posabsolute*ratefactor),
+ (int64_t)(sampleoffset*ratefactor),
+ (int64_t)((*found).length*ratefactor),
+ *found
+ };
+ regions.push_back(r);
+ rindex++;
+ actualwavs.erase(found);
+ } else {
+ region_t r = {
+ name,
+ rindex,
+ (int64_t)(start*ratefactor),
+ (int64_t)(sampleoffset*ratefactor),
+ (int64_t)(length*ratefactor),
+ f
+ };
+ regions.push_back(r);
+ rindex++;
}
- k--;
+ k++;
}
- k++;
-
- rindex = 0;
+ /*
+ // Tracks
while (k < len) {
- if ( (ptfunxored[k ] == 0xff) &&
- (ptfunxored[k+1] == 0xff)) {
- break;
- }
while (k < len) {
if ( (ptfunxored[k ] == 0x5a) &&
(ptfunxored[k+1] == 0x00) &&
- (ptfunxored[k+2] == 0x01)) {
+ (ptfunxored[k+2] == 0x03)) {
break;
}
k++;
}
-
+ printf("k=%x\n", k);
lengthofname = ptfunxored[k+12];
- if (ptfunxored[k+13] == 0x5a) {
+ if (lengthofname == 0 || lengthofname == 0x5a || ptfunxored[k+13] < 30) {
k++;
- break;
+ continue;
}
+
char name[256] = {0};
for (j = 0; j < lengthofname; j++) {
name[j] = ptfunxored[k+13+j];
}
name[j] = '\0';
+
regionspertrack = ptfunxored[k+13+j+3];
for (i = 0; i < regionspertrack; i++) {
while (k < len) {
@@ -561,7 +669,11 @@ PTFFormat::parserest5(void) {
}
j+=offsetbytes;
- //printf("name=`%s` start=%04x length=%04x offset=%04x findex=%d\n", name,start,length,sampleoffset,findex);
+ if (length == 0) {
+ k++;
+ continue;
+ }
+ printf("start=%04x length=%04x offset=%04x findex=%d\n", start,length,sampleoffset,findex);
std::string filename = string(name) + extension;
wav_t f = {
@@ -634,6 +746,7 @@ PTFFormat::parserest5(void) {
}
k++;
}
+ */
}
void
@@ -654,7 +767,7 @@ PTFFormat::parseaudio5(void) {
// Find actual wav names
bool first = true;
uint16_t numberofwavs;
- char wavname[256];
+ char wavname[256] = {0};
for (i = k; i > 4; i--) {
if ( ((ptfunxored[i ] == 'W') || (ptfunxored[i ] == 'F')) &&
((ptfunxored[i-1] == 'A') || (ptfunxored[i-1] == 'F')) &&
@@ -662,16 +775,18 @@ PTFFormat::parseaudio5(void) {
((ptfunxored[i-3] == 'E') || (ptfunxored[i-3] == 'A'))) {
j = i-4;
l = 0;
- while (ptfunxored[j] != '\0') {
+ while (ptfunxored[j] >= 30) {
wavname[l] = ptfunxored[j];
l++;
j--;
}
wavname[l] = 0;
- if (ptfunxored[i] == 'W') {
+ if (foundin(wavname, "vaw.")) {
extension = string(".wav");
- } else {
+ } else if (foundin(wavname, "fia.")) {
extension = string(".aif");
+ } else {
+ extension = string("");
}
//uint8_t playlist = ptfunxored[j-8];
@@ -687,7 +802,7 @@ PTFFormat::parseaudio5(void) {
numberofwavs |= (uint32_t)(ptfunxored[j-5] << 16);
numberofwavs |= (uint32_t)(ptfunxored[j-4] << 8);
numberofwavs |= (uint32_t)(ptfunxored[j-3]);
- //printf("%d wavs\n", numberofwavs);
+ printf("%d wavs\n", numberofwavs);
break;
}
k--;
@@ -703,7 +818,7 @@ PTFFormat::parseaudio5(void) {
}
actualwavs.push_back(f);
- //printf("done\n");
+ printf("wav=`%s`\n", wave.c_str());
numberofwavs--;
if (numberofwavs <= 0)
break;