void as_Sound::Play() { HRESULT hr; hr = g_pPerformance->PlaySegmentEx( pSegment, // Segment to play. NULL, // Used for songs; not implemented. NULL, // For transitions. DMUS_SEGF_REFTIME | DMUS_SEGF_SECONDARY, // Flags. 0, // Start time; 0 is immediate. &(this->pState), // Pointer that receives segment state. NULL, // Object to stop. pAudioPath // Audiopath. ); if (FAILED(hr)) { char msg[MSG_LEN]; sprintf(msg, "Could not play segment, error 0x%08lX", hr); AddLogMsg(msg); return; } AddLogMsg("Play"); hr = pSegment->AddNotificationType(GUID_NOTIFICATION_SEGMENT); this->playing = true; this->status = STATUS_PLAYING; }
void as_Sound::Stop() { HRESULT hr; hr = g_pPerformance->Stop(pSegment, NULL, 0, 0); if (FAILED(hr)) { char msg[MSG_LEN]; sprintf(msg, "Could not stop segment, error 0x%08lX", hr); AddLogMsg(msg); return; } AddLogMsg("Stop"); this->status = STATUS_STOPPED; this->playing = false; }
void as_Sound::SetDirectionRelative(float x, float y, float z) { this->Position[0] = x; this->Position[1] = y; this->Position[2] = z; this->pDS3DBuffer->SetPosition(x, y, z, DS3D_IMMEDIATE); #ifdef DEBUG char msg[MSG_LEN]; sprintf(msg, "SetDirectionRelative x=%3.2f, y=%3.2f, z=%3.2f", x, y, z); AddLogMsg(msg); #endif }
LRESULT CMy601DemoClientView::OnMsgLogMsg(WPARAM wp,LPARAM lp) { std::string *pstrMsg = (std::string*)(lp); if (lp == NULL) return S_FALSE; if (pstrMsg->empty()) return S_OK; AddLogMsg(pstrMsg->c_str()); delete pstrMsg; return S_OK; }
void as_Sound::SetLooping(bool enable) { this->looping = enable; this->pSegment->SetLoopPoints(0, 0); if (true == enable) this->pSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE); else this->pSegment->SetRepeats(0); #ifdef DEBUG char msg[MSG_LEN]; sprintf(msg, "SetLooping %d", enable); AddLogMsg(msg); #endif }
void CMy601DemoClientView::OnConnectionSet() { // TODO: 在此添加命令处理程序代码 CConnectionSetDlg dlg; dlg.m_strLocalPort = theApp.m_strLocalServicePort; dlg.m_strServerPort = theApp.m_strServerPort; dlg.m_strServerIp = theApp.m_strServerIp; dlg.m_strServerDomain = theApp.m_strServerDomain; dlg.m_iUseIp = theApp.m_bUseIp? 0 : -1; if (dlg.DoModal()!=IDOK) return; if (theApp.m_strLocalServicePort!= dlg.m_strLocalPort) { theApp.m_strLocalServicePort = dlg.m_strLocalPort; if (m_pIceServiceClient) { AddLogMsg("本地服务端口已改变,正在重启本地服务..."); m_pIceServiceClient->OnStop(); delete m_pIceServiceClient; m_pIceServiceClient = NULL; PostMessage(WM_START_LOCAL_SERVICE,0,NULL); } } theApp.m_bUseIp = dlg.m_iUseIp==0 ? TRUE:FALSE; theApp.m_strServerPort = dlg.m_strServerPort; if (theApp.m_bUseIp) theApp.m_strServerIp = dlg.m_strServerIp; else theApp.m_strServerDomain = dlg.m_strServerDomain; CString strServerLocation; if (theApp.m_bUseIp) strServerLocation = theApp.m_strServerIp; else strServerLocation = theApp.m_strServerDomain; m_ServerObj.SetServerIP(strServerLocation); m_ServerObj.SetServerPort(theApp.m_strServerPort); m_ServerObj.SetLocalPort(theApp.m_strLocalServicePort); theApp.WriteSettingToIni(); // 写配置信息 CString strMsg; strMsg.Format("通讯设置:服务器地址:%s,服务器端口号:%s,本机服务端口号%s",strServerLocation,theApp.m_strServerPort,theApp.m_strLocalServicePort); theApp.TraceRunLog(strMsg); MessageBox("设置成功!","提示",MB_OK|MB_ICONINFORMATION); }
void as_Sound::SetDirectionRelative(float x, float y, float z, long color) { this->Position[0] = x; this->Position[1] = y; this->Position[2] = z; this->pDS3DBuffer->SetPosition(x, y, z, DS3D_IMMEDIATE); #ifdef DEBUG char msg[MSG_LEN]; sprintf(msg, "SetDirectionRelative x=%3.2f, y=%3.2f, z=%3.2f, color=%08lXh", x, y, z, color); AddLogMsg(msg); #endif this->updateGridColored(); }
void as_Sound::SetGain(float gain) { // set volume in hundredth of Decibel from 0 (full volume) to -9600 (silence) long volume; HRESULT hr; if (gain > 1.0f) gain = 1.0f; // volume = (long)(-(1.0f-gain)*9600.0f); // wrong calculation // 1.0 -> -0 db // 0.5 -> -1 db // 0.25 -> -2 db // 0.125 -> -3 db if (0.0f == gain) volume = -9600; else volume = (long)(1000 * log(gain) / log(2.0)); #ifdef DEBUG char msg[MSG_LEN]; sprintf(msg, "Volume = %ld (%5.2f)", volume, gain); AddLogMsg(msg); #endif hr = this->pAudioPath->SetVolume(volume, 0); if (FAILED(hr)) { char msg[MSG_LEN]; sprintf(msg, "Could not set AudioPath volume, error 0x%08lX", hr); AddLogMsg(msg); return; } }
void as_Sound::SetPitch(float pitch) { // set volume in hundredth of Decibel from 0 (full volume) to -9600 (silence) long volume; HRESULT hr; // Get the 3D buffer in the audio path. IDirectSoundBuffer *myBuffer = NULL; hr = this->pAudioPath->GetObjectInPath( 0, DMUS_PATH_BUFFER, 0, GUID_NULL, 0, IID_IDirectSoundBuffer, (LPVOID *)&myBuffer); if (FAILED(hr)) { AddLogMsg("Error: GetObjectInPath"); return; } //this->pDS3DBuffer->QueryInterface(IID_IDirectSoundBuffer,(LPVOID *)&myBuffer); if (myBuffer) { myBuffer->SetFrequency(pitch); } /* if (true == looping) { MUSIC_TIME mtLength; hr = pSegment->GetLength(&mtLength); hr = pSegment->SetLoopPoints(0, mtLength/44000*22000); if (S_OK != hr) { char msg[128]; sprintf(msg, "SetLoopPoints error 0x%08lX", hr); AddLogMsg(msg); } this->pSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE); } else this->pSegment->SetRepeats(0);*/ }
void as_Sound::SetDirectionRelative(float angle) { float x, y, z; // x = (float)sin(pi*angle/180); // z = (float)cos(pi*angle/180); x = (float)sin(angle); y = 0.0; z = (float)cos(angle); this->Position[0] = x; this->Position[1] = y; this->Position[2] = z; this->pDS3DBuffer->SetPosition(x, y, z, DS3D_IMMEDIATE); #ifdef DEBUG char msg[MSG_LEN]; sprintf(msg, "SetDirectionRelative angle = %f (x=%3.2f, y=%3.2f, z=%3.2f)", angle, x, y, z); AddLogMsg(msg); #endif }
void as_Sound::Play(float starttime, float stoptime) { HRESULT hr; MUSIC_TIME mtLength; MUSIC_TIME mtStart = TimeToMusicTime(starttime); MUSIC_TIME mtStop = TimeToMusicTime(stoptime); REFERENCE_TIME rtTime; hr = pSegment->GetLength(&mtLength); hr = g_pPerformance->MusicToReferenceTime( mtStop, &rtTime); if (S_OK != hr) { char msg[128]; sprintf(msg, "MusicToReferenceTime error 0x%08lX", hr); AddLogMsg(msg); } hr = pSegment->AddNotificationType(GUID_NOTIFICATION_SEGMENT); if (true == looping) { hr = pSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE); } else { hr = pSegment->SetRepeats(0); } if (S_OK != hr) { char msg[128]; sprintf(msg, "SetRepeats error 0x%08lX", hr); AddLogMsg(msg); } hr = pSegment->SetStartPoint(mtStart); if (S_OK != hr) { char msg[128]; sprintf(msg, "SetStartPoint error 0x%08lX", hr); AddLogMsg(msg); hr = S_OK; } /* hr = pSegment->SetLoopPoints(mtStart, mtStop); if (S_OK != hr) { char msg[128]; sprintf(msg, "SetLoopPoints error 0x%08lX", hr); AddLogMsg(msg); } */ // Start the segment. // if (SUCCEEDED(hr)) { char msg[MSG_LEN]; /* hr = g_pPerformance->PlaySegment(pSegment, 0, 0, &pState); if (S_OK != hr) { char msg[128]; sprintf(msg, "PlaySegment error 0x%08lX", hr); AddLogMsg(msg); } */ hr = g_pPerformance->PlaySegmentEx( pSegment, // Segment to play. NULL, // Used for songs; not implemented. NULL, // For transitions. DMUS_SEGF_REFTIME | DMUS_SEGF_SECONDARY, // Flags. 0, // Start time; 0 is immediate. &(this->pState), // Pointer that receives segment state. NULL, // Object to stop. pAudioPath // Audiopath. ); if (FAILED(hr)) { char msg[MSG_LEN]; sprintf(msg, "Could not play segment, error 0x%08lX", hr); AddLogMsg(msg); return; } // Stop the segment. // /* hr = g_pPerformance->Stop(pSegment, 0, mtStop, DMUS_SEGF_REFTIME); if (S_OK != hr) { char msg[128]; sprintf(msg, "Stop error 0x%08lX", hr); AddLogMsg(msg); } */ hr = g_pPerformance->StopEx(this->pSegment, rtTime, DMUS_SEGF_REFTIME); if (S_OK != hr) { char msg[128]; sprintf(msg, "Stop error 0x%08lX", hr); AddLogMsg(msg); } this->playing = true; this->status = STATUS_PLAYING; sprintf(msg, "Play(starttime = %5.2f, stoptime = %5.2f)", starttime, stoptime); AddLogMsg(msg); } }
as_Sound::as_Sound(char *fileName) { long rc = 0; long len = 0; HRESULT hr; WCHAR wChar[MAX_PATH]; if (NULL == fileName) return; pSegment = NULL; pState = NULL; pDS3DBuffer = NULL; pAudioPath = NULL; memset(&dmod, 0, sizeof(DMUS_OBJECTDESC)); gain = 1.0f; Direction[0] = 0.0f; Direction[1] = 0.0f; Direction[2] = 0.0f; Position[0] = 0.0f; Position[1] = 0.0f; Position[2] = 0.0f; // Create a 3D audiopath with a 3d buffer. // We can then play all segments into this buffer and directly control its 3D parameters. hr = g_pPerformance->CreateStandardAudioPath( DMUS_APATH_DYNAMIC_3D, 1, TRUE, &(this->pAudioPath)); if (FAILED(hr)) { char msg[MSG_LEN]; sprintf(msg, "Could not create standard audio path, error 0x%08lX", hr); AddLogMsg(msg); return; } // Get the 3D buffer in the audio path. hr = this->pAudioPath->GetObjectInPath( 0, DMUS_PATH_BUFFER, 0, GUID_NULL, 0, IID_IDirectSound3DBuffer, (LPVOID *)&this->pDS3DBuffer); if (FAILED(hr)) { AddLogMsg("Error: GetObjectInPath"); return; } this->pAudioPath->SetVolume(0, 0); dmod.dwSize = sizeof(DMUS_OBJECTDESC); dmod.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH; dmod.guidClass = CLSID_DirectMusicSegment; len = strlen(fileName); rc = mbstowcs(wChar, fileName, len + 1); wcscpy(dmod.wszFileName, wChar); hr = g_Loader->GetObject(&dmod, IID_IDirectMusicSegment8, (void **)&pSegment); if (FAILED(hr)) { AddLogMsg("Could not get object: IID_IDirectMusicSegment8"); return; } hr = pSegment->Download(g_pPerformance); if (FAILED(hr)) { AddLogMsg("Could not download segment"); return; } this->status = STATUS_INITIAL; }