⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sounddb.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    /* store the version number */
    hSDB->tSounddb.version_number[0] = pTmpBuf[4];
    hSDB->tSounddb.version_number[1] = pTmpBuf[5];
    hSDB->tSounddb.version_number[2] = pTmpBuf[6];
    hSDB->tSounddb.version_number[3] = pTmpBuf[7];

    /* Check that version number is valid */
    if (GET_INT_FROM_ASCII4(hSDB->tSounddb.version_number) < BDROM_SPEC_VERSION)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Version Number Invalid!\n", __FUNCTION__));
        tStatus = SOUNDDB_INVALID_FORMAT;
        goto errout_2;
    }

    /* Read the SoundData Start Address */
    hSDB->tSounddb.SoundData_start_address = MAKE_DWORD(&pTmpBuf[8]);

    /* Read the ExtensionData Start Address */
    hSDB->tSounddb.ExtensionData_start_address = MAKE_DWORD(&pTmpBuf[12]);


    /*
     * LOAD SOUNDINDEX
     */
    if (LoaderFileSeek(hSDB->hLoader, sound_file, LOADER_SEEK_CURRENT, 24) != LOADER_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u:  Failed to seek in file!\n", __FILE__, __LINE__));
        tStatus = SOUNDDB_FILE_ERROR;
        goto errout_2;
    }

    /* read the length */
    if (LoaderFileRead(hSDB->hLoader, sound_file, (PVOID)pTmpBuf, 4, NULL) != LOADER_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Failed to read length!\n", __FUNCTION__));
        tStatus = SOUNDDB_FILE_ERROR;
        goto errout_2;
    }
    hSDB->tSounddb.SoundIndex.length = MAKE_DWORD(&pTmpBuf[0]);

    /* if length is zero, there are no sounds (but it's not an error) */
    if (hSDB->tSounddb.SoundIndex.length == 0)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u:  length is zero!\n", __FILE__, __LINE__));
        tStatus = SOUNDDB_SUCCESS;
        goto errout_2;
    }

    /* read the number of sound entries */
    if (LoaderFileRead(hSDB->hLoader, sound_file, (PVOID)pTmpBuf, 2, NULL) != LOADER_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u: Failed to read!\n", __FILE__, __LINE__));
        tStatus = SOUNDDB_FILE_ERROR;
        goto errout_2;
    }
    hSDB->tSounddb.SoundIndex.number_of_sound_entries = pTmpBuf[1];
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("number of sound entries: %u\n", hSDB->tSounddb.SoundIndex.number_of_sound_entries));

    /* allocate the sound Index tables */
    hSDB->tSounddb.SoundIndex.sound_attributes = (SOUND_ATTRIBUTES*)OS_MemAlloc(hSDB->tSounddb.SoundIndex.number_of_sound_entries * sizeof(SOUND_ATTRIBUTES));
    hSDB->tSounddb.SoundIndex.sound_location   = (SOUND_LOCATION*)OS_MemAlloc(hSDB->tSounddb.SoundIndex.number_of_sound_entries * sizeof(SOUND_LOCATION));
    if ( (hSDB->tSounddb.SoundIndex.sound_attributes == NULL) || (hSDB->tSounddb.SoundIndex.sound_location == NULL) )
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u: OS_MemAlloc Failure!\n", __FILE__, __LINE__));
        tStatus = SOUNDDB_FAILURE;
        goto errout_2;
    }

    /* fill the sound index tables */
    for (i=0; i<hSDB->tSounddb.SoundIndex.number_of_sound_entries; i++)
    {
        if (LoaderFileRead(hSDB->hLoader, sound_file, (PVOID)pTmpBuf, 10, NULL) != LOADER_SUCCESS)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u: Failed to read!\n", __FILE__, __LINE__));
            tStatus = SOUNDDB_FILE_ERROR;
            goto errout_2;
        }

        hSDB->tSounddb.SoundIndex.sound_attributes[i].channel_configuration  = pTmpBuf[0] >> 4;
        hSDB->tSounddb.SoundIndex.sound_attributes[i].sampling_frequency     = pTmpBuf[0] & 0x0f;
        hSDB->tSounddb.SoundIndex.sound_attributes[i].bits_per_sample        = pTmpBuf[1] >> 6;

        /* some error checking */
        DbgAssert(hSDB->tSounddb.SoundIndex.sound_attributes[i].channel_configuration == 1 || hSDB->tSounddb.SoundIndex.sound_attributes[i].channel_configuration == 3);
        DbgAssert(hSDB->tSounddb.SoundIndex.sound_attributes[i].sampling_frequency == 1);
        DbgAssert(hSDB->tSounddb.SoundIndex.sound_attributes[i].bits_per_sample == 1);

        hSDB->tSounddb.SoundIndex.sound_location[i].sound_data_start_address = MAKE_DWORD(&pTmpBuf[2]);
        hSDB->tSounddb.SoundIndex.sound_location[i].sound_data_length        = MAKE_DWORD(&pTmpBuf[6]);
    }


    /*
     * LOAD SOUNDDATA
     */
    if (LoaderFileSeek(hSDB->hLoader, sound_file, LOADER_SEEK_SET, hSDB->tSounddb.SoundData_start_address) != LOADER_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u:  Failed to seek in file!\n", __FILE__, __LINE__));
        tStatus = SOUNDDB_FILE_ERROR;
        goto errout_2;
    }

    /* find the size of the sound data */
    sounddatalength =   (hSDB->tSounddb.SoundIndex.sound_location[hSDB->tSounddb.SoundIndex.number_of_sound_entries-1].sound_data_start_address)   /* last start location */
                      + (hSDB->tSounddb.SoundIndex.sound_location[hSDB->tSounddb.SoundIndex.number_of_sound_entries-1].sound_data_length       );  /* + length of last    */

    DBGPRINT(DBG_ON(DBG_VERBOSE), ("sounddatalength: %u\n", sounddatalength));

    /* allocate a buffer to hold all of the sound data */
    hSDB->tSounddb.SoundData  = (BYTE*)OS_MemAlloc(sounddatalength * sizeof(BYTE));
    if (hSDB->tSounddb.SoundData == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u: OS_MemAlloc Failure!\n", __FILE__, __LINE__));
        tStatus = SOUNDDB_FAILURE;
        goto errout_2;
    }

    /* read the sound data into the buffer */
    if (LoaderFileRead(hSDB->hLoader, sound_file, (PVOID)hSDB->tSounddb.SoundData, sounddatalength, NULL) != LOADER_SUCCESS)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Failed to LOAD SOUNDDATA!\n", __FUNCTION__));
        tStatus = SOUNDDB_FILE_ERROR;
        goto errout_2;
    }

#if SOUNDDB_ENDIAN_FIX
    BYTE temp_byte;

    for (i = 0; i < sounddatalength; i+=2)
    {
        temp_byte = hSDB->tSounddb.SoundData[i];
        hSDB->tSounddb.SoundData[i] = hSDB->tSounddb.SoundData[i+1];
        hSDB->tSounddb.SoundData[i+1] = temp_byte;
    }
#endif

#if 0
   /* Seek To the ExtensionData() */
   if (LoaderFileSeek(hSDB->hLoader, sound_file, LOADER_SEEK_SET, hSDB->tSounddb.ExtensionData_start_address) != LOADER_SUCCESS)
   {
       DBGPRINT(DBG_ON(DBG_ERROR), ("%s: %u:  Failed to seek in file!\n", __FILE__, __LINE__));
       tStatus = SOUNDDB_FILE_ERROR;
       goto errout_2;
   }
   /* read in extension data */
        /* none exists */
#endif


errout_2:
    /* close the movie play list file */
    LoaderFileClose(hSDB->hLoader, sound_file);

errout_1:
    return (tStatus);
}




/**
 * SOUNDDBGetSoundInfo -- Get a pointer to the sound attributes for the current sound file, at the specified index.
 *
 * @param
 *      sound_id         -- index into the sound index database
 *      sound_attributes -- pointer that gets the sound attributes of the sound at the specified index.
 *
 * @retval
 *      SOUNDDB_STATUS
 */
SOUNDDB_STATUS SOUNDDBGetSoundInfo(BYTE sound_id, SOUND_ATTRIBUTES *sound_attributes)
{
    if (hSDB == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Database not created!\n", __FUNCTION__));
        return (SOUNDDB_FAILURE);
    }
    if (sound_attributes == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: NULL pointer!\n", __FUNCTION__));
        return (SOUNDDB_NULL_PTR);
    }
    if (sound_id >= hSDB->tSounddb.SoundIndex.number_of_sound_entries)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Index too large!\n", __FUNCTION__));
        return (SOUNDDB_FAILURE);
    }

    /* return the sound_attributes */
    *sound_attributes = hSDB->tSounddb.SoundIndex.sound_attributes[sound_id];

    return (SOUNDDB_SUCCESS);
}



/**
 * SOUNDDBGetSoundData -- Get a pointer to the sound data for the current sound file, at the specified index.
 *
 * @param
 *      sound_id        -- index into the sound data database
 *      buffer          -- pointer that gets the sound data of the sound at the specified index.
 *      buffer_length   -- length of the sound data of the sound at the specified index.
 *
 * @retval
 *      SOUNDDB_STATUS
 */
SOUNDDB_STATUS SOUNDDBGetSoundData(BYTE sound_id, BYTE **buffer, ULONG *buffer_length)
{
    if (hSDB == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Database not created!\n", __FUNCTION__));
        return (SOUNDDB_FAILURE);
    }
    if (buffer == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: NULL pointer!\n", __FUNCTION__));
        return (SOUNDDB_NULL_PTR);
    }
    if (sound_id >= hSDB->tSounddb.SoundIndex.number_of_sound_entries)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("%s: Index too large!\n", __FUNCTION__));
        return (SOUNDDB_FAILURE);
    }

    /* return a pointer to the sound data */
    *buffer         = &(hSDB->tSounddb.SoundData[hSDB->tSounddb.SoundIndex.sound_location[sound_id].sound_data_start_address]);
    *buffer_length  =   hSDB->tSounddb.SoundIndex.sound_location[sound_id].sound_data_length;

    return (SOUNDDB_SUCCESS);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -