summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2015-08-06 17:25:51 +1000
committerDamien Zammit <damien@zamaudio.com>2015-08-06 17:26:51 +1000
commitc3cdc096cbe0ac178cc537e82208089020d75204 (patch)
tree26da3a3ee7dba5b3bd608e4499ca45c1f722656b
parent78b7229f028978216a7d2217894fbe4909181c11 (diff)
Added target samplerate setting, and fixed bug with start offset
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r--ptfformat.cc35
-rw-r--r--ptfformat.h7
-rw-r--r--ptftool.cc4
-rw-r--r--ptunxor.cc2
4 files changed, 31 insertions, 17 deletions
diff --git a/ptfformat.cc b/ptfformat.cc
index dde7367..0af15fc 100644
--- a/ptfformat.cc
+++ b/ptfformat.cc
@@ -102,7 +102,7 @@ PTFFormat::foundin(std::string haystack, std::string needle) {
-1 could not open file as ptf
*/
int
-PTFFormat::load(std::string path) {
+PTFFormat::load(std::string path, int64_t targetsr) {
FILE *fp;
unsigned char xxor[256];
unsigned char ct;
@@ -254,6 +254,7 @@ PTFFormat::load(std::string path) {
break;
}
fclose(fp);
+ this->targetrate = targetsr;
parse();
return 0;
}
@@ -264,9 +265,11 @@ PTFFormat::parse(void) {
if (this->version == 8) {
parse8header();
+ setrates();
parserest();
} else if (this->version == 9) {
parse9header();
+ setrates();
parserest();
} else {
// Should not occur
@@ -274,6 +277,14 @@ PTFFormat::parse(void) {
}
void
+PTFFormat::setrates(void) {
+ this->ratefactor = 1.f;
+ if (sessionrate != 0) {
+ this->ratefactor = (float)this->targetrate / this->sessionrate;
+ }
+}
+
+void
PTFFormat::parse8header(void) {
int k;
@@ -502,8 +513,8 @@ PTFFormat::parserest(void) {
wav_t f = {
filename,
0,
- (int64_t)start,
- (int64_t)length,
+ (int64_t)(start*this->ratefactor),
+ (int64_t)(length*this->ratefactor),
};
f.index = findex;
@@ -519,9 +530,9 @@ PTFFormat::parserest(void) {
region_t r = {
name,
rindex,
- start,
- sampleoffset,
- length,
+ (int64_t)(start*this->ratefactor),
+ (int64_t)(sampleoffset*this->ratefactor),
+ (int64_t)(length*this->ratefactor),
f
};
this->regions.push_back(r);
@@ -533,9 +544,9 @@ PTFFormat::parserest(void) {
region_t r = {
name,
rindex,
- start,
- sampleoffset,
- length,
+ (int64_t)(start*this->ratefactor),
+ (int64_t)(sampleoffset*this->ratefactor),
+ (int64_t)(length*this->ratefactor),
f
};
this->regions.push_back(r);
@@ -612,8 +623,8 @@ PTFFormat::parserest(void) {
if ((found = std::find(begin, finish, tr.reg)) != finish) {
tr.reg = (*found);
}
- startbytes = (ptfunxored[l+3] & 0xf0) >> 4;
-
+ //startbytes = (ptfunxored[l+3] & 0xf0) >> 4;
+ startbytes = 4;
i = l+16;
offset = 0;
switch (startbytes) {
@@ -628,7 +639,7 @@ PTFFormat::parserest(void) {
default:
break;
}
- tr.reg.startpos = (int64_t)offset;
+ tr.reg.startpos = (int64_t)(offset*this->ratefactor);
if (tr.reg.length > 0) {
this->tracks.push_back(tr);
}
diff --git a/ptfformat.h b/ptfformat.h
index 0f60dc3..394b727 100644
--- a/ptfformat.h
+++ b/ptfformat.h
@@ -28,7 +28,7 @@ public:
/* Return values: 0 success
-1 could not open file as ptf
*/
- int load(std::string path);
+ int load(std::string path, int64_t targetsr);
typedef struct wav {
std::string filename;
@@ -110,7 +110,8 @@ public:
return false;
}
- uint32_t sessionrate;
+ int64_t sessionrate;
+ int64_t targetrate;
uint8_t version;
unsigned char c0;
@@ -121,10 +122,12 @@ public:
private:
bool foundin(std::string haystack, std::string needle);
void parse(void);
+ void setrates(void);
void parse8header(void);
void parse9header(void);
void parserest(void);
std::vector<wav_t> actualwavs;
+ float ratefactor;
};
diff --git a/ptftool.cc b/ptftool.cc
index b99a38a..55a19d8 100644
--- a/ptftool.cc
+++ b/ptftool.cc
@@ -28,7 +28,7 @@ int main (int argc, char **argv) {
exit(0);
}
- ok = ptf.load(argv[1]);
+ ok = ptf.load(argv[1], 48000);
switch (ok) {
case -1:
@@ -36,7 +36,7 @@ int main (int argc, char **argv) {
exit(-1);
break;
case 0:
- printf("ProTools %d Session: Samplerate = %dHz\n\n", ptf.version, ptf.sessionrate);
+ printf("ProTools %d Session: Samplerate = %ldHz\nTarget samplerate = 48000\n\n", ptf.version, ptf.sessionrate);
if (ptf.audiofiles.size() > 0) {
printf("%lu wavs, %lu regions, %lu active regions\n\n",
ptf.audiofiles.size(),
diff --git a/ptunxor.cc b/ptunxor.cc
index 584c04a..99a2b26 100644
--- a/ptunxor.cc
+++ b/ptunxor.cc
@@ -21,7 +21,7 @@ int main(int argc, char** argv) {
int i, li;
PTFFormat ptf;
- if (argc < 2 || ptf.load(argv[1]) == -1) {
+ if (argc < 2 || ptf.load(argv[1], 48000) == -1) {
fprintf(stderr, "Can't open ptf file, quit\n");
exit(1);
}