diff options
author | Damien Zammit <damien@zamaudio.com> | 2015-07-24 20:08:50 +1000 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2015-07-24 20:08:50 +1000 |
commit | ef2aac70376b5b19ede006cda6f5deb7c62d049b (patch) | |
tree | 58a16c857638291fdc420676da1f60a8b0477224 | |
parent | 83003a6d706fbf46433f5089d12f221b2e792974 (diff) |
Restricted output to only include valid wav files
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r-- | ptfformat.cc | 20 | ||||
-rw-r--r-- | 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<files_t>::iterator start = this->actualwavs.begin(); + vector<files_t>::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 <inttypes.h> #include <stdlib.h> #include <string> +#include <cstring> +#include <algorithm> #include <vector> #include <cstdio> @@ -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<files_t> audiofiles; + std::vector<files_t> actualwavs; private: void parse(void); @@ -931,3 +941,5 @@ private: unsigned char c1; int len; }; + +#endif |