qmcConvert.cpp

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<io.h>
#include<string>
#include<iostream>  
#include<algorithm>

using namespace std;  

int x,y,dx,index;
int seedMap[8][7]  = {
            {0x4a, 0xd6, 0xca, 0x90, 0x67, 0xf7, 0x52},
            {0x5e, 0x95, 0x23, 0x9f, 0x13, 0x11, 0x7e},
            {0x47, 0x74, 0x3d, 0x90, 0xaa, 0x3f, 0x51},
            {0xc6, 0x09, 0xd5, 0x9f, 0xfa, 0x66, 0xf9},
            {0xf3, 0xd6, 0xa1, 0x90, 0xa0, 0xf7, 0xf0},
            {0x1d, 0x95, 0xde, 0x9f, 0x84, 0x11, 0xf4},
            {0x0e, 0x74, 0xbb, 0x90, 0xbc, 0x3f, 0x92},
            {0x00, 0x09, 0x5b, 0x9f, 0x62, 0x66, 0xa1}
        };

void init()
{
    x=-1;
    y=8;
    dx=1;
    index=-1;
}

int next_mask()
{
    index+=1;
    int ret = 0;
    if(x<0)
    {
        dx=1;
        y= ((8 - y) % 8);
        ret = 0xc3;
    }
    else if(x>6)
    {
        dx=-1;
        y=7-y;
        ret = 0xd8;
    }
    else
    {
        ret = seedMap[y][x];
    }
    x+=dx;
    if(index == 0x8000 || (index > 0x8000 && (index + 1) % 0x8000 == 0))
    {
        return next_mask();
    }
    return ret;
}

void conversion(string path,string outpath)
{  
    init();
    FILE *fp = fopen(path.c_str(), "rb");
    FILE *fout=fopen(outpath.c_str(),"wb");
    fseek (fp, 0, SEEK_END);
    int buf_len=ftell(fp);   
    fseek (fp, 0, 0);  
    int t=0;
    for(int i=0;i<buf_len;i++)
    {
         t=fgetc(fp);
         t = next_mask() ^ t;
         fputc(t,fout);
    }
    fclose(fp);
    fclose(fout);
    printf("Output %s success!\n",outpath.c_str());
}

int main(int argc, char *argv[] )
{
    if(argc==1)
    {
        string arg = argv[0];
        string path = arg.substr(0,arg.find_last_of("\\"));
        string dir=path+"\\flac";  
        if (access(dir.c_str(), 0) == -1)  
        {
            int flag=mkdir(dir.c_str());
        }
        string inPath = path+ "\\*.qmcflac";
        long handle;
        struct _finddata_t fileinfo;
        handle = _findfirst(inPath.c_str(),&fileinfo);
        
        if(handle == -1)
        {
            printf("No qmcflac file found!\n");
            system("pause");
            return -1;
        }   
        do
        {   
            string name = fileinfo.name;
            name = name.substr(0,name.find_last_of('.'));
            string outname = path+"\\flac\\"+name+".flac";
            string inname=path+"\\"""+fileinfo.name;
            conversion(inname,outname);
        } while (!_findnext(handle,&fileinfo));
        _findclose(handle);  
        system("pause");
        return 0;
    }
    string filename = argv[1];  
    int index = filename.find_last_of('.');
    string filetype = filename.substr(index,filename.length()-index);
    
    
    transform(filetype.begin(), filetype.end(), filetype.begin(), ::tolower);
    if(filetype.compare(".qmcflac"))
    {
        printf("Please input qmcflac file!\n");
        system("pause");
        return 0;
    }
    string outfile = filename.substr(0,index)+".flac";
    init();
    conversion(filename,outfile);  
    system("pause");
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值