Last active
June 2, 2017 03:26
-
-
Save lxfly2000/52b1ff8cb97c96258389946f222eb3f5 to your computer and use it in GitHub Desktop.
Convert FM voices defined in MML file to FF format. (FM voices definition file: https://pan.baidu.com/s/1mh6gGre )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<sstream> | |
#include<fstream> | |
int main() | |
{ | |
std::fstream f("voice.ff",std::ios::out|std::ios::binary); | |
std::stringstream ss; | |
std::string s; | |
int ar[4],dr[4],sr[4],rr[4],sl[4], | |
tl[4],ks[4],ml[4],dt1[4],dt2[4], | |
ame[4],alg,fbl,vnum; | |
int order[4] = { 0,2,1,3 }; | |
char atchar; | |
std::string semicommachar; | |
std::string name; | |
unsigned char eachbyte; | |
while(1) | |
{ | |
std::getline(std::cin, s); | |
if (s[0] != '@')break; | |
ss.clear(); | |
ss.str(s); | |
ss >> atchar >> vnum >> alg >> fbl >> | |
ar[0] >> dr[0] >> sr[0] >> rr[0] >> sl[0] >> tl[0] >> ks[0] >> ml[0] >> dt1[0] >> dt2[0] >> ame[0] >> | |
ar[1] >> dr[1] >> sr[1] >> rr[1] >> sl[1] >> tl[1] >> ks[1] >> ml[1] >> dt1[1] >> dt2[1] >> ame[1] >> | |
ar[2] >> dr[2] >> sr[2] >> rr[2] >> sl[2] >> tl[2] >> ks[2] >> ml[2] >> dt1[2] >> dt2[2] >> ame[2] >> | |
ar[3] >> dr[3] >> sr[3] >> rr[3] >> sl[3] >> tl[3] >> ks[3] >> ml[3] >> dt1[3] >> dt2[3] >> ame[3]; | |
if (ss.eof()) | |
name.assign(7, '\0'); | |
else | |
{ | |
ss >> semicommachar >> name; | |
while (name.length() < 7)name.append(1, '\0'); | |
} | |
#define LOOP(statement) for(int i=0;i<4;i++){statement} | |
LOOP( | |
eachbyte = (dt1[order[i]] << 4) + ml[order[i]]; | |
f << eachbyte; | |
); | |
LOOP( | |
eachbyte = tl[order[i]]; | |
f << eachbyte; | |
); | |
LOOP( | |
eachbyte = (ks[order[i]] << 6) + ar[order[i]]; | |
f << eachbyte; | |
); | |
LOOP( | |
eachbyte = (ame[order[i]] << 7) + dr[order[i]]; | |
f << eachbyte; | |
); | |
LOOP( | |
eachbyte = (dt2[order[i]] << 6) + sr[order[i]]; | |
f << eachbyte; | |
); | |
LOOP( | |
eachbyte = (sl[order[i]] << 4) + rr[order[i]]; | |
f << eachbyte; | |
); | |
eachbyte = (fbl << 3) + alg; | |
f << eachbyte; | |
f.write(name.data(), 7); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment