Fixed pt import start offsets and samplerate mismatch offsets
Signed-off-by: Damien Zammit <damien@zamaudio.com>
This commit is contained in:
parent
b75a38089b
commit
1d6e8f6681
@ -127,7 +127,7 @@ Editor::do_ptimport (std::string ptpath,
|
|||||||
vector<ptflookup_t> ptfwavpair;
|
vector<ptflookup_t> ptfwavpair;
|
||||||
vector<ptflookup_t> ptfregpair;
|
vector<ptflookup_t> ptfregpair;
|
||||||
|
|
||||||
if (ptf.load(ptpath) == -1) {
|
if (ptf.load(ptpath, _session->frame_rate()) == -1) {
|
||||||
MessageDialog msg (_("Doesn't seem to be a valid PT session file (.ptf only currently supported)"));
|
MessageDialog msg (_("Doesn't seem to be a valid PT session file (.ptf only currently supported)"));
|
||||||
msg.run ();
|
msg.run ();
|
||||||
return;
|
return;
|
||||||
|
@ -102,7 +102,7 @@ PTFFormat::foundin(std::string haystack, std::string needle) {
|
|||||||
-1 could not open file as ptf
|
-1 could not open file as ptf
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
PTFFormat::load(std::string path) {
|
PTFFormat::load(std::string path, int64_t targetsr) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
unsigned char xxor[256];
|
unsigned char xxor[256];
|
||||||
unsigned char ct;
|
unsigned char ct;
|
||||||
@ -254,6 +254,7 @@ PTFFormat::load(std::string path) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
this->targetrate = targetsr;
|
||||||
parse();
|
parse();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -264,15 +265,25 @@ PTFFormat::parse(void) {
|
|||||||
|
|
||||||
if (this->version == 8) {
|
if (this->version == 8) {
|
||||||
parse8header();
|
parse8header();
|
||||||
|
setrates();
|
||||||
parserest();
|
parserest();
|
||||||
} else if (this->version == 9) {
|
} else if (this->version == 9) {
|
||||||
parse9header();
|
parse9header();
|
||||||
|
setrates();
|
||||||
parserest();
|
parserest();
|
||||||
} else {
|
} else {
|
||||||
// Should not occur
|
// Should not occur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PTFFormat::setrates(void) {
|
||||||
|
this->ratefactor = 1.f;
|
||||||
|
if (sessionrate != 0) {
|
||||||
|
this->ratefactor = (float)this->targetrate / this->sessionrate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PTFFormat::parse8header(void) {
|
PTFFormat::parse8header(void) {
|
||||||
int k;
|
int k;
|
||||||
@ -502,8 +513,8 @@ PTFFormat::parserest(void) {
|
|||||||
wav_t f = {
|
wav_t f = {
|
||||||
filename,
|
filename,
|
||||||
0,
|
0,
|
||||||
(int64_t)start,
|
(int64_t)(start*this->ratefactor),
|
||||||
(int64_t)length,
|
(int64_t)(length*this->ratefactor),
|
||||||
};
|
};
|
||||||
|
|
||||||
f.index = findex;
|
f.index = findex;
|
||||||
@ -519,9 +530,9 @@ PTFFormat::parserest(void) {
|
|||||||
region_t r = {
|
region_t r = {
|
||||||
name,
|
name,
|
||||||
rindex,
|
rindex,
|
||||||
start,
|
(int64_t)(start*this->ratefactor),
|
||||||
sampleoffset,
|
(int64_t)(sampleoffset*this->ratefactor),
|
||||||
length,
|
(int64_t)(length*this->ratefactor),
|
||||||
f
|
f
|
||||||
};
|
};
|
||||||
this->regions.push_back(r);
|
this->regions.push_back(r);
|
||||||
@ -533,9 +544,9 @@ PTFFormat::parserest(void) {
|
|||||||
region_t r = {
|
region_t r = {
|
||||||
name,
|
name,
|
||||||
rindex,
|
rindex,
|
||||||
start,
|
(int64_t)(start*this->ratefactor),
|
||||||
sampleoffset,
|
(int64_t)(sampleoffset*this->ratefactor),
|
||||||
length,
|
(int64_t)(length*this->ratefactor),
|
||||||
f
|
f
|
||||||
};
|
};
|
||||||
this->regions.push_back(r);
|
this->regions.push_back(r);
|
||||||
@ -612,23 +623,13 @@ PTFFormat::parserest(void) {
|
|||||||
if ((found = std::find(begin, finish, tr.reg)) != finish) {
|
if ((found = std::find(begin, finish, tr.reg)) != finish) {
|
||||||
tr.reg = (*found);
|
tr.reg = (*found);
|
||||||
}
|
}
|
||||||
startbytes = (ptfunxored[l+3] & 0xf0) >> 4;
|
|
||||||
|
|
||||||
i = l+16;
|
i = l+16;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
switch (startbytes) {
|
offset |= (uint32_t)(ptfunxored[i+3] << 24);
|
||||||
case 4:
|
offset |= (uint32_t)(ptfunxored[i+2] << 16);
|
||||||
offset |= (uint32_t)(ptfunxored[i+3] << 24);
|
offset |= (uint32_t)(ptfunxored[i+1] << 8);
|
||||||
case 3:
|
offset |= (uint32_t)(ptfunxored[i]);
|
||||||
offset |= (uint32_t)(ptfunxored[i+2] << 16);
|
tr.reg.startpos = (int64_t)(offset*this->ratefactor);
|
||||||
case 2:
|
|
||||||
offset |= (uint32_t)(ptfunxored[i+1] << 8);
|
|
||||||
case 1:
|
|
||||||
offset |= (uint32_t)(ptfunxored[i]);
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
tr.reg.startpos = (int64_t)offset;
|
|
||||||
if (tr.reg.length > 0) {
|
if (tr.reg.length > 0) {
|
||||||
this->tracks.push_back(tr);
|
this->tracks.push_back(tr);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
/* Return values: 0 success
|
/* Return values: 0 success
|
||||||
-1 could not open file as ptf
|
-1 could not open file as ptf
|
||||||
*/
|
*/
|
||||||
int load(std::string path);
|
int load(std::string path, int64_t targetsr);
|
||||||
|
|
||||||
typedef struct wav {
|
typedef struct wav {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
@ -110,7 +110,8 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sessionrate;
|
int64_t sessionrate;
|
||||||
|
int64_t targetrate;
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
|
|
||||||
unsigned char c0;
|
unsigned char c0;
|
||||||
@ -121,10 +122,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool foundin(std::string haystack, std::string needle);
|
bool foundin(std::string haystack, std::string needle);
|
||||||
void parse(void);
|
void parse(void);
|
||||||
|
void setrates(void);
|
||||||
void parse8header(void);
|
void parse8header(void);
|
||||||
void parse9header(void);
|
void parse9header(void);
|
||||||
void parserest(void);
|
void parserest(void);
|
||||||
std::vector<wav_t> actualwavs;
|
std::vector<wav_t> actualwavs;
|
||||||
|
float ratefactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user