int SoundDataManager::loadFromFile(const char* pFilePath) { int nSoundID = 0; do { BREAK_IF(! FileUtils::isFileExisted(pFilePath)); int nID = BKDRHash(pFilePath); // if we have loaded the file before,break tEffectElement *pElement = NULL; HASH_FIND_INT(m_pEffects, &nID, pElement); if (pElement) { nSoundID = nID; break; } // calculate the buffer size we needed SoundPlayer TempPlayer; int nBufferSize = TempPlayer.GetFileBufferSize(pFilePath); // can not calculate the size,load failed BREAK_IF(nBufferSize < 0); // load the file data unsigned char* buffer = NULL; buffer = new unsigned char[nBufferSize]; BREAK_IF(!buffer); int nSize = TempPlayer.DecodeFile(buffer, nBufferSize, pFilePath); BREAK_IF(nSize < 0); // record the id nSoundID = nID; // add the data to hash map pElement = (tEffectElement*)calloc(sizeof(*pElement), 1); pElement->nSoundID = nSoundID; pElement->pDataBuffer = buffer; pElement->nDataSize = nBufferSize; pElement->FileName = ""; pElement->nPlayerSoundID = -1; HASH_ADD_INT(m_pEffects, nSoundID, pElement); } while (0); return nSoundID; }