-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheaxas.cpp
186 lines (166 loc) · 5.1 KB
/
eaxas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include "WavParser.h"
#include "AsfWriter.h"
#include "MaxisXaWriter.h"
#include "XasWriter.h"
using namespace std;
namespace fs = std::filesystem;
#define VERSION "1.0.0"
#define OPTION_HELP "-h"
#define OPTION_R1 "--xa-r1"
#define OPTION_R2 "--xa-r2"
#define OPTION_R3 "--xa-r3"
#define OPTION_MAXIS_XA "--maxis-xa"
#define OPTION_XAS "--xas"
#define OPTION_XAS_LOOP "--loop"
#define OPTION_OUTPUT_FILE "-o"
enum WriterType {
Unknown,
Asf,
MaxisXa,
Xas
};
void printHelp() {
cout << "EaXas " VERSION << endl;
cout << endl;
cout << "Usage: eaxas InputWavFile [Options]" << endl;
cout << endl;
cout << "Options:" << endl;
cout << " " OPTION_HELP "\t\t\t Show this help" << endl;
cout << " " OPTION_OUTPUT_FILE " OutputFile\t Specify output filepath (optional)" << endl;
cout << " " OPTION_R1 "\t\t Output to EA XA ADPCM R1 (\"SCxl\" file)" << endl;
cout << " " OPTION_R2 "\t\t Output to EA XA ADPCM R2" << endl;
cout << " " OPTION_R3 "\t\t Output to EA XA ADPCM R3" << endl;
cout << " " OPTION_MAXIS_XA "\t\t Output to EA Maxis CDROM XA ADPCM" << endl;
cout << " " OPTION_XAS "\t\t Output to EA XAS ADPCM (snr/cdata file)" << endl;
cout << " " OPTION_XAS_LOOP "\t\t For XAS only: mark the file as loop" << endl;
}
int main(int Argc, char** Argv)
{
bool showHelp = Argc <= 1;
fs::path inputPath, outputPath;
int asfRevision;
bool xasLoop = false;
WriterType writerType = Unknown;
for (int a = 1; a < Argc; a++) {
string arg(Argv[a]);
if (arg[0] == '-') {
if (arg == OPTION_HELP) {
showHelp = true;
break;
}
if (arg == OPTION_R1) {
asfRevision = 1;
writerType = Asf;
continue;
}
if (arg == OPTION_R2) {
asfRevision = 2;
writerType = Asf;
continue;
}
if (arg == OPTION_R3) {
asfRevision = 3;
writerType = Asf;
continue;
}
if (arg == OPTION_MAXIS_XA) {
writerType = MaxisXa;
continue;
}
if (arg == OPTION_XAS) {
writerType = Xas;
continue;
}
if (arg == OPTION_XAS_LOOP) {
xasLoop = true;
continue;
}
if (arg == OPTION_OUTPUT_FILE) {
a++;
if (a == Argc) {
cerr << "No output file given with option" << endl;
return 1;
}
outputPath = Argv[a];
continue;
}
cerr << "Unknown option: " << arg << endl;
return 1;
} else {
if (inputPath.empty()) {
inputPath = arg;
}
}
}
if (showHelp) {
printHelp();
return 0;
}
if (writerType == Unknown) {
cerr << "No format chosen. See help with option -h." << endl;
return 1;
}
if (inputPath.empty()) {
cerr << "No input file given" << endl;
return 1;
}
fstream inFile;
inFile.open(inputPath, ios::in | ios::binary);
if (!inFile.good()) {
cerr << "Could not open input file " << inputPath << endl;
perror(nullptr);
return 1;
}
cout << "Input file: " << inputPath.filename() << endl;
WavParser wavPa(inFile);
if (!wavPa.initFile()) {
return 1;
}
if (outputPath.empty()) {
outputPath = inputPath;
const char* outExt = "asf";
if (writerType == MaxisXa) outExt = "xa";
else if (writerType == Xas) outExt = "snr";
outputPath.replace_extension(outExt);
}
fstream outFile;
outFile.open(outputPath, ios::out | ios::binary);
if (!outFile.good()) {
cerr << "Could not create output file " << outputPath << endl;
perror(nullptr);
return 1;
}
cout << "Output file: " << outputPath.filename() << endl;
bool successEncoding;
switch (writerType) {
case Asf: {
AsfWriter writer(asfRevision, wavPa);
successEncoding = writer.writeFile(outFile);
break;
}
case MaxisXa: {
MaxisXaWriter writer(wavPa);
successEncoding = writer.writeFile(outFile);
break;
}
default: {
XasWriter writer(xasLoop, wavPa);
successEncoding = writer.writeFile(outFile);
}
}
if (!successEncoding) {
if (!inFile.good()) cerr << "Error reading input file" << endl;
return 1;
}
if (!outFile.good()) {
cerr << "Error writing to output file" << endl;
return 1;
}
cout << "Done." << endl;
return 0;
}