From ef2aac70376b5b19ede006cda6f5deb7c62d049b Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Fri, 24 Jul 2015 20:08:50 +1000 Subject: Restricted output to only include valid wav files Signed-off-by: Damien Zammit --- ptfformat.cc | 20 ++++++++++++-------- ptfformat.h | 14 +++++++++++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ptfformat.cc b/ptfformat.cc index e4da62e..c443b72 100644 --- a/ptfformat.cc +++ b/ptfformat.cc @@ -15,7 +15,6 @@ #include "ptfformat.h" using namespace std; -using std::string; PTFFormat::PTFFormat() { } @@ -200,7 +199,7 @@ PTFFormat::parse(void) { int i; int j; int k; - //int l; + int l; int type; // Find end of wav file list @@ -216,9 +215,9 @@ PTFFormat::parse(void) { } j = 0; - //l = 0; -/* - unsigned char wavname[256] = {0}; + l = 0; + + char wavname[256]; for (i = k; i > 4; i--) { if ( (ptfunxored[i ] == 'W') && (ptfunxored[i-1] == 'A') && @@ -233,10 +232,11 @@ PTFFormat::parse(void) { } wavname[l] = 0; std::string wav = string(wavname); - wav.reverse(); + std::reverse(wav.begin(), wav.end()); + files_t f = { wav, (int64_t)0 }; + actualwavs.push_back(f); } } -*/ while ( (ptfunxored[k ] != 0x5a) && (ptfunxored[k+1] != 0x01) && @@ -288,7 +288,11 @@ PTFFormat::parse(void) { //printf("%s\t%u\n", name, offset); std::string filename = string(name) + ".wav"; files_t f = { filename, (int64_t)offset }; - this->audiofiles.push_back(f); + vector::iterator start = this->actualwavs.begin(); + vector::iterator finish = this->actualwavs.end(); + if (std::find(start, finish, f) != finish) { + this->audiofiles.push_back(f); + } } } } diff --git a/ptfformat.h b/ptfformat.h index 63208dc..ac3dd4f 100644 --- a/ptfformat.h +++ b/ptfformat.h @@ -12,10 +12,14 @@ GNU General Public License for more details. */ +#ifndef PTFFORMAT_H +#define PTFFORMAT_H #include #include #include +#include +#include #include #include @@ -906,6 +910,7 @@ static const unsigned char ptflut[256][64] = { } }; + class PTFFormat { public: PTFFormat(); @@ -917,12 +922,17 @@ public: */ int load(std::string path); - typedef struct { + typedef struct files { std::string filename; int64_t posabsolute; + bool operator ==(const struct files& other) { + return (this->filename == other.filename); + } } files_t; + std::vector audiofiles; + std::vector actualwavs; private: void parse(void); @@ -931,3 +941,5 @@ private: unsigned char c1; int len; }; + +#endif -- cgit v1.2.3