-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f7d748
commit 9db0dfa
Showing
7 changed files
with
1,260 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
|
||
//-------------------------------------------------- | ||
// インクルード | ||
//-------------------------------------------------- | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#include <stdio.h> | ||
#include <direct.h> // _mkdir | ||
#include "clCRID.h" | ||
#ifndef _countof | ||
#define _countof(_array) (sizeof(_array)/sizeof(_array[0])) | ||
#endif | ||
|
||
//-------------------------------------------------- | ||
// 文字列を16進数とみなして数値に変換 | ||
//-------------------------------------------------- | ||
int atoi16(const char *s){ | ||
int r=0; | ||
bool sign=false;if(*s=='+'){s++;}else if(*s=='-'){sign=true;s++;} | ||
while(*s){ | ||
if(*s>='0'&&*s<='9')r=(r<<4)|(*s-'0'); | ||
else if(*s>='A'&&*s<='F')r=(r<<4)|(*s-'A'+10); | ||
else if(*s>='a'&&*s<='f')r=(r<<4)|(*s-'a'+10); | ||
else break; | ||
s++; | ||
} | ||
return sign?-r:r; | ||
} | ||
|
||
//-------------------------------------------------- | ||
// ディレクトリを取得 | ||
//-------------------------------------------------- | ||
char *GetDirectory(char *directory,int size,const char *path){ | ||
if(size>0)directory[0]='\0'; | ||
for(int i=strlen(path)-1;i>=0;i--){ | ||
if(path[i]=='\\'){ | ||
if(i>size-1)i=size-1; | ||
memcpy(directory,path,i); | ||
directory[i]='\0'; | ||
break; | ||
} | ||
} | ||
return directory; | ||
} | ||
|
||
//-------------------------------------------------- | ||
// ディレクトリ作成 | ||
//-------------------------------------------------- | ||
bool DirectoryCreate(const char *directory){ | ||
|
||
// チェック | ||
if(!(directory&&*directory))return false; | ||
|
||
// 相対パス(ディレクトリ名のみ) | ||
if(!(strchr(directory,'\\')||strchr(directory,'/'))){ | ||
return _mkdir(directory)==0; | ||
} | ||
|
||
// ディレクトリ名チェック | ||
if(directory[1]!=':'||directory[2]!='\\')return false; // ドライブ記述のチェック | ||
if(!directory[3])return false; // ドライブ以外の記述チェック | ||
if(strpbrk(directory+3,"/,:;*<|>\""))return false; // ディレクトリ禁止文字のチェック | ||
if(strstr(directory,"\\\\"))return false; // 連続する'\'記号のチェック | ||
if(strstr(directory," \\"))return false; // スペースの後の'\'記号のチェック | ||
|
||
// ディレクトリ作成 | ||
if(_mkdir(directory)){ | ||
char current[0x400]; | ||
if(!GetDirectory(current,_countof(current),directory))return false; | ||
if(!DirectoryCreate(current))return false; | ||
if(_mkdir(directory))return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
//-------------------------------------------------- | ||
// メイン | ||
//-------------------------------------------------- | ||
int main(int argc,char *argv[]){ | ||
|
||
// コマンドライン解析 | ||
unsigned int count=0; | ||
char *filenameOut=NULL; | ||
unsigned int ciphKey1=0x207DFFFF; | ||
unsigned int ciphKey2=0x00B8F21B; | ||
for(int i=1;i<argc;i++){ | ||
if(argv[i][0]=='-'||argv[i][0]=='/'){ | ||
switch(argv[i][1]){ | ||
case 'o':if(i+1<argc){filenameOut=argv[++i];}break; | ||
case 'a':if(i+1<argc){ciphKey1=atoi16(argv[++i]);}break; | ||
case 'b':if(i+1<argc){ciphKey2=atoi16(argv[++i]);}break; | ||
} | ||
}else if(*argv[i]){ | ||
argv[count++]=argv[i]; | ||
} | ||
} | ||
|
||
// 入力チェック | ||
if(!count){ | ||
printf("Error: 入力ファイルを指定してください。\n"); | ||
return -1; | ||
} | ||
|
||
// 分離 | ||
for(unsigned int i=0;i<count;i++){ | ||
|
||
// 2つ目以降のファイルは、出力ファイル名オプションが無効 | ||
if(i)filenameOut=NULL; | ||
|
||
// デフォルト出力ファイル名 | ||
char path[0x400]; | ||
if(!(filenameOut&&filenameOut[0])){ | ||
strcpy_s(path,sizeof(path),argv[i]); | ||
char *d1=strrchr(path,'\\'); | ||
char *d2=strrchr(path,'/'); | ||
char *e=strrchr(path,'.'); | ||
if(e&&d1<e&&d2<e)*e='\0'; | ||
strcat_s(path,sizeof(path),".demux"); | ||
filenameOut=path; | ||
} | ||
|
||
printf("%s を分離中...\n",argv[i]); | ||
DirectoryCreate(filenameOut); | ||
clCRID crid(ciphKey1,ciphKey2); | ||
if(!crid.Demux(argv[i],filenameOut,true)){ | ||
printf("Error: 分離に失敗しました。\n"); | ||
} | ||
|
||
} | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
|
||
//-------------------------------------------------- | ||
// インクルード | ||
//-------------------------------------------------- | ||
#include "clADX.h" | ||
#include <stdio.h> | ||
#include <memory.h> | ||
|
||
//-------------------------------------------------- | ||
// インライン関数 | ||
//-------------------------------------------------- | ||
inline short bswap(short v){short r=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;return r;} | ||
inline unsigned short bswap(unsigned short v){unsigned short r=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;return r;} | ||
inline int bswap(int v){int r=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;return r;} | ||
inline unsigned int bswap(unsigned int v){unsigned int r=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;return r;} | ||
inline long long bswap(long long v){long long r=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;return r;} | ||
inline unsigned long long bswap(unsigned long long v){unsigned long long r=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;r<<=8;v>>=8;r|=v&0xFF;return r;} | ||
inline float bswap(float v){unsigned int i=bswap(*(unsigned int *)&v);return *(float *)&i;} | ||
|
||
//-------------------------------------------------- | ||
// コンストラクタ | ||
//-------------------------------------------------- | ||
clADX::clADX():_data(NULL){ | ||
memset(&_header,0,sizeof(_header)); | ||
} | ||
|
||
//-------------------------------------------------- | ||
// デストラクタ | ||
//-------------------------------------------------- | ||
clADX::~clADX(){ | ||
if(_data){ | ||
delete [] _data; | ||
_data=NULL; | ||
} | ||
} | ||
|
||
//-------------------------------------------------- | ||
// ADXチェック | ||
//-------------------------------------------------- | ||
bool clADX::CheckFile(void *data){ | ||
return (data&&*(unsigned short *)data==0x0080); | ||
} | ||
|
||
//-------------------------------------------------- | ||
// デコード | ||
//-------------------------------------------------- | ||
bool clADX::Decode(const char *filename,const char *filenameWAV){ | ||
|
||
// チェック | ||
if(!(filename&&filenameWAV))return false; | ||
|
||
// 開く | ||
FILE *fp,*fp2; | ||
if(fopen_s(&fp,filename,"rb"))return false; | ||
if(fopen_s(&fp2,filenameWAV,"wb")){fclose(fp);return false;} | ||
|
||
// | ||
fread(&_header,sizeof(_header),1,fp); | ||
if(!Decode(fp2,&_header,sizeof(_header),0)){fclose(fp2);fclose(fp);return false;} | ||
|
||
// | ||
unsigned int size=18*_header.channelCount; | ||
unsigned char *data=new unsigned char [size]; | ||
if(!data){fclose(fp2);fclose(fp);return false;} | ||
fseek(fp,_header.dataOffset,SEEK_SET); | ||
while(_header.sampleCount){ | ||
fread(data,size,1,fp); | ||
if(!Decode(fp2,data,size,_header.dataOffset)){ | ||
delete [] data; | ||
fclose(fp2); | ||
fclose(fp); | ||
return false; | ||
} | ||
} | ||
delete [] data; | ||
|
||
// 閉じる | ||
fclose(fp); | ||
fclose(fp2); | ||
|
||
return true; | ||
} | ||
|
||
//-------------------------------------------------- | ||
// デコード | ||
//-------------------------------------------------- | ||
bool clADX::Decode(FILE *fp,void *data,int size,unsigned int address){ | ||
|
||
// チェック | ||
if(!(fp&&data))return false; | ||
|
||
// ヘッダ | ||
if(address==0){ | ||
if(size<sizeof(_header))return false; | ||
|
||
// ヘッダを取得 | ||
memcpy(&_header,data,sizeof(_header)); | ||
if(!CheckFile(&_header))return false; | ||
//_header.signature=bswap(_header.signature); | ||
_header.dataOffset=bswap(_header.dataOffset)+4; | ||
_header.samplingRate=bswap(_header.samplingRate); | ||
_header.sampleCount=bswap(_header.sampleCount); | ||
|
||
// WAVEヘッダを書き込み | ||
struct stWAVEHeader{ | ||
char riff[4]; | ||
unsigned int riffSize; | ||
char wave[4]; | ||
char fmt[4]; | ||
unsigned int fmtSize; | ||
unsigned short fmtType; | ||
unsigned short fmtChannelCount; | ||
unsigned int fmtSamplingRate; | ||
unsigned int fmtSamplesPerSec; | ||
unsigned short fmtSamplingSize; | ||
unsigned short fmtBitCount; | ||
char data[4]; | ||
unsigned int dataSize; | ||
}wav={'R','I','F','F',0,'W','A','V','E','f','m','t',' ',0x10,1,0,0,0,0,16,'d','a','t','a',0}; | ||
wav.fmtChannelCount=_header.channelCount; | ||
wav.fmtSamplingRate=_header.samplingRate; | ||
wav.fmtSamplingSize=2*wav.fmtChannelCount; | ||
wav.fmtSamplesPerSec=wav.fmtSamplingRate*wav.fmtSamplingSize; | ||
wav.dataSize=_header.sampleCount*wav.fmtSamplingSize; | ||
wav.riffSize=wav.dataSize+0x24; | ||
fwrite(&wav,sizeof(wav),1,fp); | ||
|
||
// | ||
if(_data)delete [] _data; | ||
_data=new int [32*_header.channelCount]; | ||
if(!_data)return false; | ||
memset(_data,0,sizeof(int)*32*_header.channelCount); | ||
|
||
} | ||
|
||
// データ | ||
else if(address>=_header.dataOffset&&_data){ | ||
for(unsigned char *s=(unsigned char *)data,*e=s+size-18*_header.channelCount;s<=e;){ | ||
int *d=_data; | ||
for(unsigned int i=_header.channelCount;i>0;i--,d+=32,s+=18){ | ||
Decode(d,s); | ||
} | ||
d=_data; | ||
for(int i=32;i>0&&_header.sampleCount;i--,d++,_header.sampleCount--){ | ||
for(unsigned int j=0;j<_header.channelCount;j++){ | ||
int v=d[j*32]; | ||
if(v>0x7FFF)v=0x7FFF; | ||
else if(v<-0x8000)v=-0x8000; | ||
fwrite(&v,2,1,fp); | ||
} | ||
} | ||
} | ||
} | ||
|
||
else{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
//-------------------------------------------------- | ||
// デコード ※検証中 | ||
//-------------------------------------------------- | ||
void clADX::Decode(int *d,unsigned char *s){ | ||
int scale=bswap(*(unsigned short *)s);s+=2; | ||
int v,p=d[31],pp=d[30]; | ||
for(int i=16;i>0;i--,s++){ | ||
v=*s>>4;if(v&8)v-=16; | ||
v=(v*scale*0x4000+p*0x7298-pp*0x3350)>>14; | ||
pp=p;p=v;*(d++)=v; | ||
v=*s&0xF;if(v&8)v-=16; | ||
v=(v*scale*0x4000+p*0x7298-pp*0x3350)>>14; | ||
pp=p;p=v;*(d++)=v; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
|
||
//-------------------------------------------------- | ||
// インクルード | ||
//-------------------------------------------------- | ||
#include <stdio.h> | ||
|
||
//-------------------------------------------------- | ||
// ADXクラス | ||
//-------------------------------------------------- | ||
class clADX{ | ||
public: | ||
clADX(); | ||
~clADX(); | ||
|
||
// チェック | ||
static bool CheckFile(void *data); | ||
|
||
// デコード | ||
bool Decode(const char *filename,const char *filenameWAV); | ||
bool Decode(FILE *fp,void *data,int size,unsigned int address); | ||
|
||
private: | ||
struct stHeader{ | ||
unsigned short signature; // シグネチャ 0x8000 | ||
unsigned short dataOffset; // データオフセット(ヘッダサイズ)-4 | ||
unsigned char r04; // バージョン? 3 | ||
unsigned char r05; // ブロックサイズ? 18 | ||
unsigned char r06; // ? 4 | ||
unsigned char channelCount; // チャンネル数 | ||
unsigned int samplingRate; // サンプリングレート | ||
unsigned int sampleCount; // 合計サンプル数 | ||
unsigned char r10; | ||
unsigned char r11; | ||
unsigned char r12; | ||
unsigned char r13; | ||
unsigned int r14; | ||
unsigned short r18; | ||
unsigned short r1A; | ||
unsigned short r1C; | ||
unsigned short r1E; | ||
}; | ||
struct stInfo{//channelCountが3以上の時に(channelCount-2)回分存在 | ||
unsigned short r00; | ||
unsigned short r02; | ||
}; | ||
struct stAINF{ | ||
unsigned int ainf;// 'AINF' | ||
unsigned int r04; | ||
unsigned char r08[0x10]; | ||
unsigned short r18; | ||
unsigned short r1A; | ||
unsigned short r1C; | ||
unsigned short r1E; | ||
}; | ||
stHeader _header; | ||
int *_data; | ||
static void Decode(int *d,unsigned char *s); | ||
}; |
Oops, something went wrong.