示例#1
0
void WaveFile_FinishWrite(WaveFile* This)
{
    int FileSize = File_GetPosition(WStream);

    File_SetPosition(WStream, 4); //Size
    File_Write_Int32(WStream, FileSize - 8);
    int DataSize = 
        This -> WriteCounter * Header.Channel * Header.BitPerSample / 8;

    File_SetPosition(WStream, This -> WritePosition - 4); //dataSize
    File_Write_Int32(WStream, DataSize);
    File_Flush(WStream);

    File_Close(WStream);
}
示例#2
0
int main(int ArgN, char** Arg)
{
    int RegenFlag = 0;
    
    char* CWaveFile = NULL;
    char* CLabelFile = NULL;
    char* CRecFile = NULL;
    char* CRegenFile = "RegeneratedTrack.txt";
    
    int c;
    
    while((c = getopt(ArgN, Arg, "r")) != -1)
    {
        switch(c)
        {
            case 'r':
                RegenFlag = 1;
            break;
            case '?':
                printf("Usage: rsegment [-r] "
                           "[-h] wavfile labelfile recfile\n");
                return 1;
            default:
                abort();
        }
    }
    
    int i;
    for(i = optind; i < ArgN; i ++)
    {
        switch(i - optind)
        {
            case 0:
                CWaveFile = Arg[i];
            break;
            case 1:
                CLabelFile = Arg[i];
            break;
            case 2:
                CRecFile = Arg[i];
            break;
            default:
                fprintf(stderr, "Warning: redundant argument '%s'.\n", Arg[i]);
        }
    }
    
    if(! CWaveFile)
    {
        fprintf(stderr, "Missing argument 'wavfile'.\n");
        return 1;
    }
    if(! CLabelFile)
    {
        fprintf(stderr, "Missing argument 'labelfile'.\n");
        return 1;
    }
    if(! CRecFile)
    {
        fprintf(stderr, "Missing argument 'recfile'.\n");
        return 1;
    }
    
    Wave SorcWave;
    File LabelFile;
    File RecFile;
    File RegenFile;
    String WavePath, LabelPath, RecPath, RegenPath;
    
    RNew(String, & WavePath, & LabelPath, & RecPath, & RegenPath);
    RNew(File, & LabelFile, & RecFile, & RegenFile);
    RCall(Wave, Ctor)(& SorcWave);
    
    String_SetChars(& WavePath, CWaveFile);
    String_SetChars(& LabelPath, CLabelFile);
    String_SetChars(& RecPath, CRecFile);
    String_SetChars(& RegenPath, CRegenFile);

    if(! RCall(Wave, FromFile)(& SorcWave, & WavePath))
    {
        fprintf(stderr, "Cannot load wave file.\n");
        return 1;
    }
    if(! File_Open(& LabelFile, & LabelPath, READONLY))
    {
        fprintf(stderr, "Cannot load label file.\n");
        return 1;
    }
    if(! File_Open(& RecFile, & RecPath, READONLY))
    {
        fprintf(stderr, "Cannot load word table.\n");
        return 1;
    }
    if(RegenFlag)
    {
        if(! File_Open(& RegenFile, & RegenPath, CREATE))
        {
            fprintf(stderr, "Cannot create '%s'.\n", CRegenFile);
            return 1;
        }
    }
    
    Array_Ctor(String, RecList);
    Array_Ctor(int, SegList);
    
    ParseRecFile(& RecFile);
    ParseLabelFile(& LabelFile, SorcWave.SampleRate);
    
    Wave SegWave;
    RCall(Wave, Ctor)(& SegWave);
    SegWave.SampleRate = SorcWave.SampleRate;
    
    String SegName, LineBuf, TempBuf;
    RNew(String, & SegName, & LineBuf, & TempBuf);
    for(i = 0; i <= SegList_Index; i ++)
    {
        int Start = SegList[i];
        int End;
        if(i == SegList_Index)
            End = SorcWave.Size;
        else
            End = SegList[i + 1];
        
        if(i > RecList_Index)
        {
            fprintf(stderr, "Insufficient records in word table.\n");
            fprintf(stderr, "Segmentation aborted at %fs.\n",
                (float)Start / SorcWave.SampleRate);
            return 1;
        }
        
        String* Name = & RecList[i];
        String_Copy(& SegName, Name);
        String_JoinChars(& SegName, ".wav");
        
        if(! RegenFlag)
        {
            int Size = End - Start;
            Real* Data = RCall(RAlloc, Real)(Size);
            RCall(Wave, Read)(& SorcWave, Data, Start, Size);
            
            RCall(Wave, Resize)(& SegWave, Size);
            RCall(Wave, Write)(& SegWave, Data, 0, Size);
            if(! RCall(Wave, ToFile)(& SegWave, & SegName))
                fprintf(stderr, "Exporting '%s' failed. Skipped.\n",
                    String_GetChars(& SegName));
            RFree(Data);
        }
        
        if(RegenFlag)
        {
            CStrFloat(& LineBuf, (float)SegList[i] / SorcWave.SampleRate);
            String_Copy(& TempBuf, & LineBuf);
            String_JoinChars(& LineBuf, "\t");
            String_Join(& LineBuf, & TempBuf);
            String_JoinChars(& LineBuf, "\t");
            String_Join(& LineBuf, Name);
            File_WriteLine(& RegenFile, & LineBuf);
        }
    }
    if(i <= RecList_Index)
        fprintf(stderr, "Warning: redundant records in word table starting from"
            " '%s'.\n", String_GetChars(& RecList[i]));
    
    if(RegenFlag)
        File_Flush(& RegenFile);
    File_Close(& RecFile);
    File_Close(& LabelFile);
    File_Close(& RegenFile);

    Array_ObjDtor(String, RecList);
    Array_Dtor(String, RecList);
    Array_Dtor(int, SegList);
    RDelete(& WavePath, & LabelPath, & RecPath, & RegenPath, & SegName,
        & LineBuf, & TempBuf);
    RDelete(& SorcWave, & LabelFile, & RecFile, & SegWave, & RegenFile);
    return 0;
}
示例#3
0
文件: Fwl_osFS.c 项目: uli42/BTPhone
T_BOOL Fwl_FileFlush(T_hFILE hFile)
{
    File_Flush(hFile);
    return AK_TRUE;
}