Ejemplo n.º 1
0
XGM* XGC_create(XGM* xgm)
{
    XGM* result = XGM_create();
    LList* s;
    LList* d;

    if (!silent)
        printf("Converting to XGC...\n");

    // copy pal/ntsc information
    result->pal = xgm->pal;

    // simple copy for sample
    s = xgm->samples;
    d = result->samples;
    while(s != NULL)
    {
        XGMSample* sample = s->element;
        d = insertAfterLList(d, sample);
        s = s->next;
    }
    result->samples = getHeadLList(d);

    // and extract music data
    XGC_extractMusic(result, xgm);

    // shift all samples to 2 frames for PAL and 3 frames ahead for NTSC (because of PCM buffer length)
    if (result->pal)
        XGC_shiftSamples(result, 2);
    else
        XGC_shiftSamples(result, 3);

    // display play PCM command
//    if (verbose)
//    {
//        LList* curCom = result->commands;
//        while(curCom != NULL)
//        {
//            XGMCommand* command = curCom->element;
//
//            if (XGCCommand_isPCM(command))
//                printf("play sample %2X at frame %d\n", XGCCommand_getPCMId(command), XGC_getTimeInFrame(result, command));
//
//            curCom = curCom->next;
//        }
//    }

    if (verbose)
    {
        printf("Sample size: %d\n", XGM_getSampleDataSize(result));
        printf("Music data size: %d\n", XGM_getMusicDataSize(result));
        printf("Number of sample: %d\n", getSizeLList(result->samples));
    }
    if (!silent)
        printf("XGC duration: %d frames (%d seconds)\n", XGC_computeLenInFrame(result), XGC_computeLenInSecond(result));

    return result;
}
Ejemplo n.º 2
0
Archivo: xgm.c Proyecto: clbr/SGDK
XGM* XGM_createFromVGM(VGM* vgm)
{
    XGM* result = XGM_create();

    if (!silent)
        printf("Converting VGM to XGM...\n");

    if (vgm->rate == 60)
        result->pal = 0;
    else if (vgm->rate == 50)
        result->pal = 1;
    else
        result->pal = -1;

    result->gd3 = vgm->gd3;

    // extract samples from VGM
    XGM_extractSamples(result, vgm);
    // and extract music data
    XGM_extractMusic(result, vgm);

    // display play PCM command
//    if (verbose)
//    {
//        LList* curCom = result->commands;
//        while(curCom != NULL)
//        {
//            XGMCommand* command = curCom->element;
//
//            if (XGMCommand_isPCM(command))
//                printf("play sample %2X at frame %d\n", XGMCommand_getPCMId(command), XGM_getTimeInFrame(result, command));
//
//            curCom = curCom->next;
//        }
//    }

    if (verbose)
    {
        printf("XGM sample number: %d\n", getSizeLList(result->samples));
        printf("Sample size: %d\n", XGM_getSampleDataSize(result));
        printf("Music data size: %d\n", XGM_getMusicDataSize(result));
    }
    if (!silent)
        printf("XGM duration: %d frames (%d seconds)\n", XGM_computeLenInFrame(result), XGM_computeLenInSecond(result));

    return result;
}
Ejemplo n.º 3
0
Archivo: xgm.c Proyecto: clbr/SGDK
unsigned char* XGM_asByteArray(XGM* xgm, int *outSize)
{
    int i;
    int offset;
    unsigned char byte;
    FILE* f = fopen("tmp.bin", "wb+");
    LList* l;

    if (f == NULL)
    {
        printf("Error: cannot open file tmp.bin\n");
        return NULL;
    }

    // 0000: XGM (should be ignored in ROM resource)
    fwrite("XGM ", 1, 4, f);

    // 0004-0100: sample id table
    // fixed size : 252 bytes, limit music to 63 samples max
    offset = 0;
    i = 0;
    l = xgm->samples;
    while(l != NULL)
    {
        XGMSample* sample = l->element;
        const int len = sample->dataSize;

        byte = offset >> 8;
        fwrite(&byte, 1, 1, f);
        byte = offset >> 16;
        fwrite(&byte, 1, 1, f);
        byte = len >> 8;
        fwrite(&byte, 1, 1, f);
        byte = len >> 16;
        fwrite(&byte, 1, 1, f);
        offset += len;

        i++;
        l = l->next;
    }
    for (; i < 0x3F; i++)
    {
        // special mark for silent sample
        byte = 0xFF;
        fwrite(&byte, 1, 1, f);
        fwrite(&byte, 1, 1, f);
        byte = 0x00;
        fwrite(&byte, 1, 1, f);
        fwrite(&byte, 1, 1, f);
    }

    // 0100-0101: sample block size *256 (2 bytes)
    byte = offset >> 8;
    fwrite(&byte, 1, 1, f);
    byte = offset >> 16;
    fwrite(&byte, 1, 1, f);

    // init PAL flag if needed (default is NTSC)
    if (xgm->pal == -1)
        xgm->pal = 0;

    // 0102: XGM version
    byte = 0x01;
    fwrite(&byte, 1, 1, f);
    // 0103
    byte = 0x00;
    // b0=NTSC/PAL
    byte |= xgm->pal?1:0;
    // b1=GD3 tags
    byte |= (xgm->gd3 != NULL)?2:0;
    // b2=multi track, others=reserved
    fwrite(&byte, 1, 1, f);

    // 0104-XXXX: sample data
    l = xgm->samples;
    while(l != NULL)
    {
        XGMSample* sample = l->element;
        fwrite(sample->data, 1, sample->dataSize, f);
        l = l->next;
    }

    // compute XGM music data size in byte
    const int len = XGM_getMusicDataSize(xgm);

    // XXXX+0000: music data size (in byte)
    byte = len >> 0;
    fwrite(&byte, 1, 1, f);
    byte = len >> 8;
    fwrite(&byte, 1, 1, f);
    byte = len >> 16;
    fwrite(&byte, 1, 1, f);
    byte = len >> 24;
    fwrite(&byte, 1, 1, f);

    // XXXX+0004: music data
    l = xgm->commands;
    while(l != NULL)
    {
        XGMCommand* command = l->element;
        fwrite(command->data, 1, command->size, f);
        l = l->next;
    }

    // XXXX+0004+MLEN: GD3 tags if present
    if (xgm->gd3)
    {
        unsigned char* data = GD3_asByteArray(xgm->gd3, &i);
        fwrite(data, 1, i, f);
    }

    unsigned char* result = inEx(f, 0, getFileSizeEx(f), outSize);

    fclose(f);

    return result;
}