Ejemplo n.º 1
0
int  RUCE_Roto_SetEntry(RUCE_Roto* This, RUCE_Roto_Entry* Sorc)
{
    cJSON* Entries = cJSON_GetObjectItem(This -> Ptr, "Entries");
    if(! Entries) return 0;
    
    char* Name = String_GetChars(& Sorc -> Name);
    cJSON* Entry = cJSON_GetObjectItem(Entries, Name);
    
    cJSON* NewEntry = cJSON_CreateObject();
    cJSON_AddNumberToObject(NewEntry, "VOT", Sorc -> VOT);
    cJSON_AddNumberToObject(NewEntry, "InvarLeft", Sorc -> InvarLeft);
    cJSON_AddNumberToObject(NewEntry, "InvarRight", Sorc -> InvarRight);
    cJSON_AddNumberToObject(NewEntry, "Overlap", Sorc -> Overlap);
    if(! Entry)
    {
        //Create new entry
        cJSON_AddItemToObject(Entries, Name, NewEntry);
    }else
    {
        //Modify existing entry
        cJSON_ReplaceItemInObject(Entries, Name, NewEntry);
    }
    
    return 1;
}
Ejemplo n.º 2
0
int  RUCE_Roto_CtorLoad(RUCE_Roto* This, String* Path)
{
    int Ret = 1;
    
    File RotoFile;
    String RotoContent;
    String_Ctor(& RotoContent);
    File_Ctor(& RotoFile);
    
    if(! File_Open(& RotoFile, Path, READONLY))
    {
        Ret = 0;
        goto End;
    }
    File_Read_String(& RotoFile, & RotoContent);
    This -> Ptr = cJSON_Parse(String_GetChars(& RotoContent));
    if(! This -> Ptr)
        Ret = 0;
    
    End:
    File_Close(& RotoFile);
    File_Dtor(& RotoFile);
    String_Dtor(& RotoContent);
    
    RInit(RUCE_Roto);
    return Ret;
}
Ejemplo n.º 3
0
int  RUCE_Roto_GetEntry(RUCE_Roto* This, RUCE_Roto_Entry* Dest, String* Name)
{
    cJSON* Entries = cJSON_GetObjectItem(This -> Ptr, "Entries");
    if(! Entries) return 0;
    
    cJSON* Entry = cJSON_GetObjectItem(Entries, String_GetChars(Name));
    if(! Entry) return -1;
    
    _GetEntry();
    
    return 1;
}
Ejemplo n.º 4
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;
}