From fca326f1368d44e0bc63aa2b79c7babf35509260 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sat, 8 Aug 2015 14:34:17 +1000 Subject: PT5 initial commit Signed-off-by: Damien Zammit --- Makefile | 6 ++++-- ptfformat.cc | 36 +++++++++++++++++++++++++++++++----- ptfformat.h | 12 ++++++++---- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 4f76078..c11adbd 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ +STRICT=-Wall -Wcast-align -Wextra -Wwrite-strings -Wunsafe-loop-optimizations -Wlogical-op + all: - $(CXX) -o ptftool -g -Wall ptftool.cc ptfformat.cc - $(CXX) -o ptunxor -g -Wall ptunxor.cc ptfformat.cc + $(CXX) -o ptftool -g ${STRICT} ptftool.cc ptfformat.cc + $(CXX) -o ptunxor -g ${STRICT} ptunxor.cc ptfformat.cc clean: rm ptftool ptunxor diff --git a/ptfformat.cc b/ptfformat.cc index 652024e..dbe0539 100644 --- a/ptfformat.cc +++ b/ptfformat.cc @@ -37,7 +37,7 @@ static const uint32_t xorlut[16] = { 0xbab0b0ba, 0xb0abaaba, 0xba0aabaa, 0xbaaaaaaa }; -static const uint32_t swapbytes32 (const uint32_t v) { +static uint32_t swapbytes32 (const uint32_t v) { uint32_t rv = 0; rv |= ((v >> 0) & 0xf) << 28; rv |= ((v >> 4) & 0xf) << 24; @@ -50,7 +50,7 @@ static const uint32_t swapbytes32 (const uint32_t v) { return rv; } -static const uint64_t gen_secret (int i) { +static uint64_t gen_secret (int i) { assert (i > 0 && i < 256); int iwrap = i & 0x7f; // wrap at 0x80; uint32_t xor_lo = 0; // 0x40 flag @@ -128,7 +128,7 @@ PTFFormat::load(std::string path, int64_t targetsr) { fread(&c0, 1, 1, fp); fread(&c1, 1, 1, fp); - // For version 7 support: + // For version <= 7 support: version = c0 & 0x0f; c0 = c0 & 0xc0; @@ -296,7 +296,12 @@ void PTFFormat::parse(void) { version = (version == 0) ? ptfunxored[61] : version; - if (version == 7) { + if (version == 5) { + parse5header(); + setrates(); + parseaudio(); + parserest89(); + } else if (version == 7) { parse7header(); setrates(); parseaudio(); @@ -330,6 +335,27 @@ PTFFormat::setrates(void) { } } +void +PTFFormat::parse5header(void) { + int k; + + // Find session sample rate + k = 0x100; + while (k < len) { + if ( (ptfunxored[k ] == 0x5a) && + (ptfunxored[k+1] == 0x00) && + (ptfunxored[k+2] == 0x02)) { + break; + } + k++; + } + + sessionrate = 0; + sessionrate |= ptfunxored[k+12] << 16; + sessionrate |= ptfunxored[k+13] << 8; + sessionrate |= ptfunxored[k+14]; +} + void PTFFormat::parse7header(void) { int k; @@ -474,7 +500,7 @@ PTFFormat::parseaudio(void) { std::string wave = string(wavname); std::reverse(wave.begin(), wave.end()); - wav_t f = { wave, (uint16_t)(numberofwavs - 1), 0 }; + wav_t f = { wave, (uint16_t)(numberofwavs - 1), 0, 0 }; if (foundin(wave, string(".grp"))) { continue; diff --git a/ptfformat.h b/ptfformat.h index 2cd855f..156a5bf 100644 --- a/ptfformat.h +++ b/ptfformat.h @@ -75,8 +75,10 @@ public: std::vector::iterator begin = tr.begin(); std::vector::iterator finish = tr.end(); std::vector::iterator found; - - track_t f = { std::string(""), index }; + + wav_t w = { std::string(""), 0, 0, 0 }; + region_t r = { std::string(""), 0, 0, 0, 0, w }; + track_t f = { std::string(""), index, 0, r }; if ((found = std::find(begin, finish, f)) != finish) { return true; @@ -89,7 +91,8 @@ public: std::vector::iterator finish = reg.end(); std::vector::iterator found; - region_t r = { std::string(""), index }; + wav_t w = { std::string(""), 0, 0, 0 }; + region_t r = { std::string(""), index, 0, 0, 0, w }; if ((found = std::find(begin, finish, r)) != finish) { return true; @@ -102,7 +105,7 @@ public: std::vector::iterator finish = wv.end(); std::vector::iterator found; - wav_t w = { std::string(""), index }; + wav_t w = { std::string(""), index, 0, 0 }; if ((found = std::find(begin, finish, w)) != finish) { return true; @@ -124,6 +127,7 @@ private: void parse(void); void unxor10(void); void setrates(void); + void parse5header(void); void parse7header(void); void parse8header(void); void parse9header(void); -- cgit v1.2.3