Exemple #1
0
bool CDxSound::AddSound(char *fileName)
{
	if(false==IncreaseList())
		return false;

	//声明一个Wave声音对象
	CSoundWave sWave;
	if(false==sWave.Open(fileName))
		return false;

	//添加音频信息
	DSBUFFERDESC dsbDesc;
	ZeroMemory(&dsbDesc,sizeof(dsbDesc));
	dsbDesc.dwSize=sizeof(DSBUFFERDESC);
	dsbDesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_GLOBALFOCUS|DSBCAPS_CTRLPOSITIONNOTIFY|
		DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN|DSBCAPS_CTRLFREQUENCY;
	dsbDesc.dwBufferBytes=sWave.GetDataChunkSize();
	dsbDesc.lpwfxFormat=sWave.GetWaveFormat();
	if(DS_OK!=m_dsound->CreateSoundBuffer(&dsbDesc,&m_soundList[m_iListLength-1].dsBuffer,NULL))
		return false;
	m_soundList[m_iListLength-1].dsBuffer->GetVolume(&m_soundList[m_iListLength-1].volume);
	m_soundList[m_iListLength-1].dsBuffer->GetPan(&m_soundList[m_iListLength-1].pen);
	m_soundList[m_iListLength-1].dsBuffer->GetFrequency(&m_soundList[m_iListLength-1].frequency);

	//添加音频数据
	void *pointer1,*pointer2;
	DWORD bytes1,bytes2;
	if(DS_OK!=m_soundList[m_iListLength-1].dsBuffer->Lock(0,
		sWave.GetDataChunkSize(),&pointer1,&bytes1,&pointer2,&bytes2,0))
		return false;
	DWORD nread;
	sWave.Read(bytes1,pointer1,&nread);
	if(bytes2)
		sWave.Read(bytes2,pointer2,&nread);
	if(DS_OK!=m_soundList[m_iListLength-1].dsBuffer->Unlock(pointer1,bytes1,pointer2,bytes2))
		return false;

	return true;
}
TRI_fulltext_list_t* TRI_InsertListFulltextIndex(
    TRI_fulltext_list_t* list, const TRI_fulltext_list_entry_t entry) {
  TRI_fulltext_list_entry_t* listEntries;
  uint32_t numAllocated;
  uint32_t numEntries;
  bool unsort;

  numAllocated = GetNumAllocated(list);
  numEntries = GetNumEntries(list);
  listEntries = GetStart(list);
  unsort = false;

  if (numEntries > 0) {
    TRI_fulltext_list_entry_t lastEntry;

    // check whether the entry is already contained in the list
    lastEntry = listEntries[numEntries - 1];
    if (entry == lastEntry) {
      // entry is already contained. no need to insert the same value again
      return list;
    }

    if (entry < lastEntry) {
      // we're adding at the end. we must update the sorted property if
      // the list is not sorted anymore
      unsort = true;
    }
  }

  if (numEntries + 1 >= numAllocated) {
    // must allocate more memory
    TRI_fulltext_list_t* clone;
    uint32_t newSize;

    newSize = (uint32_t)(numEntries * GROWTH_FACTOR);

    if (newSize == numEntries) {
      // 0 * something might not be enough...
      newSize = numEntries + 1;
    }

    // increase the existing list
    clone = IncreaseList(list, newSize);
    if (clone == nullptr) {
      return nullptr;
    }

    // switch over
    if (list != clone) {
      list = clone;
      listEntries = GetStart(list);
    }
  }

  if (unsort) {
    SetIsSorted(list, false);
  }

  // insert at the end
  listEntries[numEntries] = entry;
  SetNumEntries(list, numEntries + 1);

  return list;
}