Ejemplo n.º 1
0
void COggDlg::Closeds()
{
//	fade1=1;
	if(m_dsb){
		m_dsb->Stop();
		if(m_dsb3d != NULL){m_dsb3d->Release();m_dsb3d =NULL;}
		if(m_dsb != NULL){m_dsb->Release();m_dsb =NULL;}
	}
}
Ejemplo n.º 2
0
int GlobalSoundManager::getAvailableBufferIndex(SoundPriority priority) {
  int available_buffer = -1; // index of a buffer that could be overwritten if no
                             // empty one is found
  for (int buffer = 0; buffer < NUMBER_OF_SOUND_BUFFERS; ++buffer) {
    if (sound_buffers_[buffer] == NULL) return buffer;
    if (sound_buffer_priority_[buffer] <= priority) {
      available_buffer = buffer;
    }
  }

  if (available_buffer < 0) return -1;

  LPDIRECTSOUNDBUFFER8 buffer = sound_buffers_[available_buffer];
  buffer->Stop();
  buffer->Release();
  sound_buffers_[available_buffer] = NULL;
  sound_buffer_priority_[available_buffer] = SOUNDPRIORITY_AMBIENT;
  return available_buffer;
}
Ejemplo n.º 3
0
UINT HandleNotifications(LPVOID)
{
	DWORD hr = DS_OK;
	DWORD hRet = 0;
	thn=FALSE;
	thn1=FALSE;
	char* pdsb1;
	char* pdsb2;
	syukai=0;
//	char bufwav2[OUTPUT_BUFFER_SIZE];
	HANDLE ev[] = {(HANDLE)og->timer};
//	ULONG PlayCursor,WriteCursor=OUTPUT_BUFFER_SIZE*4,oldw=OUTPUT_BUFFER_SIZE*4;
	ULONG PlayCursor,WriteCursor=0,oldw=OUTPUT_BUFFER_SIZE*2,oldw2;
	m_dsb->SetCurrentPosition(0);
	if(mode==-10){
		oldw=OUTPUT_BUFFER_SIZE*2;
		og->timer.SetEvent();
	}
	fade1=0;
	for(;;){
		DWORD  dwDataLen = WAVDALen/10;
		if(syukai==2) {thn=TRUE;AfxEndThread(0);}
		if(syukai==1) {syukai2=1;continue;}
//		int ik;
//		for(ik=0;ik<60;ik++){
//		if(syukai)
			::WaitForMultipleObjects(1, ev, FALSE, 40);
//		else
			//Sleep(1);
			if (sek == 1) {
				if (m_dsb)m_dsb->Stop();
				oldw = 0;
				if ((mode >= 10 && mode <= 20) || mode < -10) {
					playwavadpcm(bufwav3, oldw, OUTPUT_BUFFER_SIZE / 12 * wavch * 2, 0);//データ獲得
				}
				else if (mode == -10) {
					playwavmp3(bufwav3, oldw, OUTPUT_BUFFER_SIZE / 12 * wavch * 2, 0);//データ獲得
				}
				else if (mode == -3) {
					playwavkpi(bufwav3, oldw, OUTPUT_BUFFER_SIZE / 12 * wavch * 2, 0);//データ獲得
				}
				else if (mode == -8) {
					playwavflac(bufwav3, oldw, OUTPUT_BUFFER_SIZE / 12 * wavch * 2, 0);//データ獲得
				}
				else if (mode == -9) {
					playwavm4a(bufwav3, oldw, OUTPUT_BUFFER_SIZE / 12 * wavch * 2, 0);//データ獲得
				}
				else {
					playwavds2(bufwav3, oldw, OUTPUT_BUFFER_SIZE / 12 * wavch * 2, 0);//データ獲得
				}
				oldw = OUTPUT_BUFFER_SIZE / 12 * wavch * 2; WriteCursor = OUTPUT_BUFFER_SIZE / 12 * wavch * 2;
				if(m_dsb)m_dsb->SetCurrentPosition(0);
				if(m_dsb)m_dsb->Play(0,0,DSBPLAY_LOOPING);
				sek=FALSE;
				//break;
			}
			if(thn1) {thn=TRUE;AfxEndThread(0);}
//		}
		if(ps==1) continue;
		if(m_dsb)m_dsb->GetCurrentPosition(&PlayCursor, &WriteCursor);//再生位置取得
		int len1=0,len2=0,len3,len4;
//		oldw = ((oldw / (wavch * 2)) * (wavch * 2));
		len1=(int)WriteCursor-(int)oldw;//書き込み範囲取得10
		len2=0;
		if (len1 == 0 && len2 == 0) continue;
		if(len1<0){
			len1=OUTPUT_BUFFER_SIZE*OUTPUT_BUFFER_NUM-oldw; len2= WriteCursor;}
		if(len2<0)
			len2=0;
		//len1 = (len1 / (wavsam / 8)) * (wavsam / 8);
		//len2 = (len2 / (wavsam / 8)) * (wavsam / 8);
		len4=len1+len2;
		if((mode>=10 && mode<=20) || mode<-10)
			playwavadpcm(bufwav3,oldw,len1,len2);//データ獲得
		else if(mode==-10)
			len4=playwavmp3(bufwav3,oldw,len1,len2);//データ獲得
		else if(mode==-3)
			len4=playwavkpi(bufwav3,oldw,len1,len2);//データ獲得
		else if (mode == -8)
			playwavflac(bufwav3, oldw, len1, len2);//データ獲得
		else if (mode == -9)
			playwavm4a(bufwav3, oldw, len1, len2);//データ獲得
		else
			playwavds2(bufwav3,oldw,len1,len2);//データ獲得

		if(m_dsb){
			m_dsb->Lock(oldw,len4,(LPVOID *)&pdsb1,(DWORD*)&len3,(LPVOID *)&pdsb2,(DWORD*)&len4,0);
			thn=FALSE;
			Sleep(20);
			thn=FALSE;
			memcpy(pdsb1,bufwav3+oldw,len3);
			if(len4!=0)memcpy(pdsb2,bufwav3,len4);
			if(m_dsb)m_dsb->Unlock(pdsb1,len3,pdsb2,len4);
			oldw2=oldw+len3;
			if(len4!=0)oldw2=len4;
			oldw=WriteCursor;
//			oldw+=(len3+len4);
//			oldw%=OUTPUT_BUFFER_SIZE*OUTPUT_BUFFER_NUM;
		}
		if(fade1){
//			if(m_dsb){
//				m_dsb->Lock(0,OUTPUT_BUFFER_SIZE*OUTPUT_BUFFER_NUM,(LPVOID *)&pdsb1,(DWORD*)&len3,(LPVOID *)&pdsb2,(DWORD*)&len4,0);
//				ZeroMemory(pdsb1,len3);
//				if(len4!=0)ZeroMemory(pdsb2,len4);
//				m_dsb->Unlock(pdsb1,len3,pdsb2,len4);
//			}
//			Sleep(750);
			oldw=oldw2-(wavbit);
			if(((int)oldw)<=0)oldw=wavbit;
			int flgn=0;
			playf = 1;
			thn = FALSE;
			if(m_dsb && thn==FALSE){
				m_dsb->GetCurrentPosition(&PlayCursor, &WriteCursor);
				if(oldw<=PlayCursor) flgn=1;
//				DWORD time=timeGetTime()+3000;
				for(;;){
//					if(time<timeGetTime()) break;
					DoEvent();
					if(m_dsb)m_dsb->GetCurrentPosition(&PlayCursor, &WriteCursor);
					if(oldw>PlayCursor){flgn=0; continue;}
					if(oldw<=PlayCursor && flgn==0) break;
				}
			}
//			m_dsb->SetVolume(DSBVOLUME_MIN);
//			m_dsb->Stop();
			og->OnPause();
			playf=0;
			thn=TRUE;

			AfxEndThread(0);
//			for(int y=0;y<11;y++){
//				CloseHandle(hNotifyEvent[y]);hNotifyEvent[y] = (HANDLE)NULL;
//			}
			return 0;
		}
	}

} //handlenotifications()