Äúµ±Ç°µÄλÖãºÊ×Ò³ > IT±à³Ì > C++
| CÓïÑÔ | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | ѧÊõÓë´úÂë | cnn¾í»ýÉñ¾­ÍøÂç | gnn | ͼÏñÐÞ¸´ | Keras | Êý¾Ý¼¯ | Neo4j | ×ÔÈ»ÓïÑÔ´¦Àí | Éî¶Èѧϰ | ҽѧCAD | ҽѧӰÏñ | ³¬²ÎÊý | pointnet | pytorch | Òì³£¼ì²â | Transformers | Çé¸Ð·ÖÀà | ֪ʶͼÆ× |

×Ôѧ½Ì³Ì£ºC++ IDirectSoundBuffer_Playº¯Êý´úÂëʾÀý

51×ÔÑ§Íø 2021-06-01 21:28:10
  C++
ÕâÆª½Ì³ÌC++ IDirectSoundBuffer_Playº¯Êý´úÂëʾÀýдµÃºÜʵÓã¬Ï£ÍûÄܰﵽÄú¡£

±¾ÎÄÕûÀí»ã×ÜÁËC++ÖÐIDirectSoundBuffer_Playº¯ÊýµÄµäÐÍÓ÷¨´úÂëʾÀý¡£Èç¹ûÄúÕý¿àÓÚÒÔÏÂÎÊÌ⣺C++ IDirectSoundBuffer_Playº¯ÊýµÄ¾ßÌåÓ÷¨£¿C++ IDirectSoundBuffer_PlayÔõôÓã¿C++ IDirectSoundBuffer_PlayʹÓõÄÀý×Ó£¿ÄÇô¹§Ï²Äú, ÕâÀᆱѡµÄº¯Êý´úÂëʾÀý»òÐí¿ÉÒÔΪÄúÌṩ°ïÖú¡£

ÔÚÏÂÎÄÖÐÒ»¹²Õ¹Ê¾ÁËIDirectSoundBuffer_Playº¯ÊýµÄ30¸ö´úÂëʾÀý£¬ÕâЩÀý×ÓĬÈϸù¾ÝÊÜ»¶Ó­³Ì¶ÈÅÅÐò¡£Äú¿ÉÒÔΪϲ»¶»òÕ߸оõÓÐÓõĴúÂëµãÔÞ£¬ÄúµÄÆÀ¼Û½«ÓÐÖúÓÚÎÒÃǵÄÏµÍ³ÍÆ¼ö³ö¸ü°ôµÄC++´úÂëʾÀý¡£

ʾÀý1: Play

static HRESULT Play( vlc_object_t *obj, aout_stream_sys_t *sys,                     block_t *p_buffer ){    HRESULT dsresult;    dsresult = FillBuffer( obj, sys, p_buffer );    if( dsresult != DS_OK )        return dsresult;    /* start playing the buffer */    dsresult = IDirectSoundBuffer_Play( sys->p_dsbuffer, 0, 0,                                        DSBPLAY_LOOPING );    if( dsresult == DSERR_BUFFERLOST )    {        IDirectSoundBuffer_Restore( sys->p_dsbuffer );        dsresult = IDirectSoundBuffer_Play( sys->p_dsbuffer,                                            0, 0, DSBPLAY_LOOPING );    }    if( dsresult != DS_OK )        msg_Err( obj, "cannot start playing buffer: (hr=0x%0lx)", dsresult );    else    {        vlc_mutex_lock( &sys->lock );        sys->b_playing = true;        vlc_cond_signal(&sys->cond);        vlc_mutex_unlock( &sys->lock );    }    return dsresult;}
¿ª·¢ÕßID:videolan£¬ÏîÄ¿Ãû³Æ:vlc£¬´úÂëÐÐÊý:29£¬


ʾÀý2: DX6_WaitAudio_EventWait

static void DX6_WaitAudio_EventWait(_THIS){	DWORD status;	HRESULT result;	/* Try to restore a lost sound buffer */	IDirectSoundBuffer_GetStatus(mixbuf, &status);	if ( (status&DSBSTATUS_BUFFERLOST) ) {		IDirectSoundBuffer_Restore(mixbuf);		IDirectSoundBuffer_GetStatus(mixbuf, &status);		if ( (status&DSBSTATUS_BUFFERLOST) ) {			return;		}	}	if ( ! (status&DSBSTATUS_PLAYING) ) {		result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);		if ( result != DS_OK ) {#ifdef DEBUG_SOUND			SetDSerror("DirectSound Play", result);#endif			return;		}	}	WaitForSingleObject(audio_event, INFINITE);}
¿ª·¢ÕßID:bohwaz£¬ÏîÄ¿Ãû³Æ:ozex£¬´úÂëÐÐÊý:25£¬


ʾÀý3: I_UpdateSoundParams

void I_UpdateSoundParams(int channel, int vol, int sep, int pitch){// proff 07/04/98: Added for CYGWIN32 compatibility#ifdef HAVE_LIBDSOUND  int DSB_Status;  if (noDSound == true)    return;// proff 07/26/98: Added volume check  if (vol==0)    {      IDirectSoundBuffer_Stop(lpSecondaryDSB[channel]);      return;    }  IDirectSoundBuffer_SetVolume(lpSecondaryDSB[channel],VOL(vol));  IDirectSoundBuffer_SetPan(lpSecondaryDSB[channel],SEP(sep));  IDirectSoundBuffer_SetFrequency    (lpSecondaryDSB[channel], ChannelInfo[channel].samplerate+PITCH(pitch));  if (ChannelInfo[channel].playing == true)    {      IDirectSoundBuffer_GetStatus(lpSecondaryDSB[channel], &DSB_Status);      if ((DSB_Status & DSBSTATUS_PLAYING) == 0)	IDirectSoundBuffer_Play(lpSecondaryDSB[channel], 0, 0, 0);    }#endif // HAVE_LIBDSOUND}
¿ª·¢ÕßID:dorienh£¬ÏîÄ¿Ãû³Æ:smmu£¬´úÂëÐÐÊý:27£¬


ʾÀý4: CreatePrimaryBuffer

static HRESULT CreatePrimaryBuffer(void){  DSBUFFERDESC dsbdesc;// proff 07/23/98: Added WAVEFORMATEX and HRESULT  WAVEFORMATEX wf;  HRESULT result;  memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));  dsbdesc.dwSize = sizeof(DSBUFFERDESC);  dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;   memset(&wf, 0, sizeof(WAVEFORMATEX));  if (snd_bits!=16)    snd_bits=8;// proff 07/23/98: Added wf  wf.wFormatTag = WAVE_FORMAT_PCM;  if (snd_stereo!=0)    wf.nChannels = 2;  else    wf.nChannels = 1;  wf.wBitsPerSample = snd_bits;  wf.nSamplesPerSec = snd_freq;  wf.nBlockAlign = wf.nChannels*wf.wBitsPerSample/8;  wf.nAvgBytesPerSec = wf.nSamplesPerSec*wf.nBlockAlign;      result=IDirectSound_CreateSoundBuffer(lpDS, &dsbdesc, &lpPrimaryDSB, NULL);// proff 07/23/98: Added wf and result  if (result == DS_OK)    result=IDirectSoundBuffer_SetFormat(lpPrimaryDSB,&wf);  if (result == DS_OK)    result=IDirectSoundBuffer_Play(lpPrimaryDSB,0,0,DSBPLAY_LOOPING);  return result;}
¿ª·¢ÕßID:dorienh£¬ÏîÄ¿Ãû³Æ:smmu£¬´úÂëÐÐÊý:33£¬


ʾÀý5: DS_Update

static void DS_Update(void){	LPVOID block;	DWORD bBytes;	/* Do first update in DS_Update() to be consistent with other	   non threaded drivers. */	if (do_update && pSoundBuffer) {		do_update = 0;		if (IDirectSoundBuffer_Lock(pSoundBuffer, 0, fragsize, &block, &bBytes, NULL, NULL, 0)											== DSERR_BUFFERLOST) {			IDirectSoundBuffer_Restore (pSoundBuffer);			IDirectSoundBuffer_Lock (pSoundBuffer, 0, fragsize, &block, &bBytes, NULL, NULL, 0);		}		if (Player_Paused_internal()) {			VC_SilenceBytes ((SBYTE *)block, (ULONG)bBytes);		} else {			VC_WriteBytes ((SBYTE *)block, (ULONG)bBytes);		}		IDirectSoundBuffer_Unlock (pSoundBuffer, block, bBytes, NULL, 0);		IDirectSoundBuffer_SetCurrentPosition(pSoundBuffer, 0);		IDirectSoundBuffer_Play(pSoundBuffer, 0, 0, DSBPLAY_LOOPING);		threadInUse=1;		ResumeThread (updateBufferHandle);	}}
¿ª·¢ÕßID:OS2World£¬ÏîÄ¿Ãû³Æ:LIB-SDL-2014£¬´úÂëÐÐÊý:31£¬


ʾÀý6: SB_Init

static BOOL SB_Init(void){    HRESULT result;    if (!lpdsound) {        result = DirectSoundCreate(NULL,&lpdsound,NULL);        if (result != DS_OK) {            ERR("Unable to initialize Sound Subsystem err = %x !/n",result);            return FALSE;        }        /* FIXME: To uncomment when :           - SetCooperative level is correctly implemented           - an always valid and non changing handle to a windows  (vga_hwnd) is available             (this surely needs some work in vga.c)        result = IDirectSound_SetCooperativeLevel(lpdsound,vga_hwnd,DSSCL_EXCLUSIVE|DSSCL_PRIORITY);        if (result != DS_OK) {            ERR("Can't set cooperative level !/n");            return FALSE;        }        */        /* Default format */        wav_fmt.wFormatTag = WAVE_FORMAT_PCM;        wav_fmt.nChannels = 1;        wav_fmt.nSamplesPerSec = 22050;        wav_fmt.nAvgBytesPerSec = 22050;        wav_fmt.nBlockAlign = 1;        wav_fmt.wBitsPerSample = 8;        wav_fmt.cbSize = 0;        memset(&buf_desc,0,sizeof(DSBUFFERDESC));        buf_desc.dwSize = sizeof(DSBUFFERDESC);        buf_desc.dwBufferBytes = DSBUFLEN;        buf_desc.lpwfxFormat = &wav_fmt;        result = IDirectSound_CreateSoundBuffer(lpdsound,&buf_desc,&lpdsbuf,NULL);        if (result != DS_OK) {            ERR("Can't create sound buffer !/n");            return FALSE;        }        result = IDirectSoundBuffer_Play(lpdsbuf,0, 0, DSBPLAY_LOOPING);        if (result != DS_OK) {            ERR("Can't start playing !/n");            return FALSE;        }        buf_off = 0;        end_sound_loop = 0;        SB_Thread = CreateThread(NULL, 0, SB_Poll, NULL, 0, NULL);        TRACE("thread/n");        if (!SB_Thread) {            ERR("Can't create thread !/n");            return FALSE;        }    }    return TRUE;}
¿ª·¢ÕßID:Dimillian£¬ÏîÄ¿Ãû³Æ:wine£¬´úÂëÐÐÊý:58£¬


ʾÀý7: tdav_consumer_dsound_start

int tdav_consumer_dsound_start(tmedia_consumer_t* self){	tdav_consumer_dsound_t* dsound = (tdav_consumer_dsound_t*)self;	tsk_size_t i;	HRESULT hr;	LPDIRECTSOUNDNOTIFY lpDSBNotify;	DSBPOSITIONNOTIFY pPosNotify[TDAV_DSOUNS_CONSUMER_NOTIF_POS_COUNT] = {0};	if(!dsound){		TSK_DEBUG_ERROR("Invalid parameter");		return -1;	}	if(!dsound->device || !dsound->primaryBuffer || !dsound->secondaryBuffer){		TSK_DEBUG_ERROR("Consumer not prepared");		return -2;	}	if(dsound->started){		TSK_DEBUG_WARN("Consumer already started");		return 0;	}	if((hr = IDirectSoundBuffer_QueryInterface(dsound->secondaryBuffer, &IID_IDirectSoundNotify, (LPVOID*)&lpDSBNotify)) != DS_OK){		tdav_win32_print_error("IDirectSoundBuffer_QueryInterface", hr);		return -3;	}	/* Events associated to notification points */	for(i = 0; i<sizeof(dsound->notifEvents)/sizeof(HANDLE); i++){		dsound->notifEvents[i] = CreateEvent(NULL, FALSE, FALSE, NULL);		pPosNotify[i].dwOffset = ((dsound->bytes_per_notif * i) + dsound->bytes_per_notif) - 1;		pPosNotify[i].hEventNotify = dsound->notifEvents[i];	}	if((hr = IDirectSoundNotify_SetNotificationPositions(lpDSBNotify, TDAV_DSOUNS_CONSUMER_NOTIF_POS_COUNT, pPosNotify)) != DS_OK){		IDirectSoundNotify_Release(lpDSBNotify);		tdav_win32_print_error("IDirectSoundBuffer_QueryInterface", hr);		return -4;	}		if((hr = IDirectSoundNotify_Release(lpDSBNotify))){		tdav_win32_print_error("IDirectSoundNotify_Release", hr);	}		/* start the reader thread */	tsk_thread_create(&dsound->tid[0], __playback_thread, dsound);	/* Start the buffer */	if((hr = IDirectSoundBuffer_Play(dsound->secondaryBuffer,0, 0, DSBPLAY_LOOPING)) != DS_OK){		tdav_win32_print_error("IDirectSoundNotify_Release", hr);		return -5;	}	dsound->started = tsk_true;	return 0;}
¿ª·¢ÕßID:NewComerBH£¬ÏîÄ¿Ãû³Æ:doubango£¬´úÂëÐÐÊý:58£¬


ʾÀý8: m1sdr_PlayStart

void m1sdr_PlayStart(void){	waveLogStart();	IDirectSound_SetCooperativeLevel(lpDS, GetForegroundWindow(), DSSCL_PRIORITY);		IDirectSoundBuffer_SetCurrentPosition(lpSecB, 0);	IDirectSoundBuffer_Play(lpSecB, 0, 0, DSBPLAY_LOOPING);}
¿ª·¢ÕßID:dreiss£¬ÏîÄ¿Ãû³Æ:M1-Android£¬´úÂëÐÐÊý:9£¬


ʾÀý9: DSoundRender_GetPos

static inline HRESULT DSoundRender_GetPos(DSoundRenderImpl *This, DWORD *pPlayPos, REFERENCE_TIME *pRefTime){    HRESULT hr;    EnterCriticalSection(&This->filter.csFilter);    {        DWORD state;        DWORD write_pos;        hr = IDirectSoundBuffer_GetStatus(This->dsbuffer, &state);        if (SUCCEEDED(hr) && !(state & DSBSTATUS_PLAYING) && This->filter.state == State_Running)        {            TRACE("Not playing, kickstarting the engine/n");            hr = IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);            if (FAILED(hr))                ERR("Can't play sound buffer (%x)/n", hr);        }        if (SUCCEEDED(hr))            hr = IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, pPlayPos, &write_pos);        if (hr == S_OK)        {            DWORD play_pos = *pPlayPos;            if (play_pos < This->last_play_pos)                This->play_loops++;            This->last_play_pos = play_pos;            /* If we really fell behind, start at the next possible position             * Also happens when just starting playback for the first time,             * or when flushing             */            if ((This->play_loops*This->buf_size)+play_pos >=                (This->write_loops*This->buf_size)+This->write_pos)                This->write_pos = write_pos;            if (pRefTime)            {                REFERENCE_TIME play_time;                play_time = ((REFERENCE_TIME)This->play_loops*10000000) +                            ((REFERENCE_TIME)play_pos*10000000/This->buf_size);                /* Don't let time run backwards */                if(play_time-This->play_time > 0)                    This->play_time = play_time;                else                    hr = S_FALSE;                *pRefTime = This->play_time;            }        }    }    LeaveCriticalSection(&This->filter.csFilter);    return hr;}
¿ª·¢ÕßID:r6144£¬ÏîÄ¿Ãû³Æ:wine£¬´úÂëÐÐÊý:57£¬


ʾÀý10: DSOUND_WaitDevice

static voidDSOUND_WaitDevice(_THIS){    DWORD status = 0;    DWORD cursor = 0;    DWORD junk = 0;    HRESULT result = DS_OK;    /* Semi-busy wait, since we have no way of getting play notification       on a primary mixing buffer located in hardware (DirectX 5.0)     */    result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,                                                   &junk, &cursor);    if (result != DS_OK) {        if (result == DSERR_BUFFERLOST) {            IDirectSoundBuffer_Restore(this->hidden->mixbuf);        }#ifdef DEBUG_SOUND        SetDSerror("DirectSound GetCurrentPosition", result);#endif        return;    }    while ((cursor / this->hidden->mixlen) == this->hidden->lastchunk) {        /* FIXME: find out how much time is left and sleep that long */        SDL_Delay(1);        /* Try to restore a lost sound buffer */        IDirectSoundBuffer_GetStatus(this->hidden->mixbuf, &status);        if ((status & DSBSTATUS_BUFFERLOST)) {            IDirectSoundBuffer_Restore(this->hidden->mixbuf);            IDirectSoundBuffer_GetStatus(this->hidden->mixbuf, &status);            if ((status & DSBSTATUS_BUFFERLOST)) {                break;            }        }        if (!(status & DSBSTATUS_PLAYING)) {            result = IDirectSoundBuffer_Play(this->hidden->mixbuf, 0, 0,                                             DSBPLAY_LOOPING);            if (result == DS_OK) {                continue;            }#ifdef DEBUG_SOUND            SetDSerror("DirectSound Play", result);#endif            return;        }        /* Find out where we are playing */        result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,                                                       &junk, &cursor);        if (result != DS_OK) {            SetDSerror("DirectSound GetCurrentPosition", result);            return;        }    }}
¿ª·¢ÕßID:BoonsNaibot£¬ÏîÄ¿Ãû³Æ:kivy-ios£¬´úÂëÐÐÊý:57£¬


ʾÀý11: SOUND_play

//---------------------------------------------------------------------------////---------------------------------------------------------------------------void SOUND_play(int sound,int mode){	int m;	if(mode == PLAY_LOOP)		m = DSBPLAY_LOOPING;	else 		m = 0;	IDirectSoundBuffer_Play(sample_buffers[sound],0,0,m);}
¿ª·¢ÕßID:javisantana£¬ÏîÄ¿Ãû³Æ:cubyshot£¬´úÂëÐÐÊý:12£¬


ʾÀý12: write_buffer

/**/brief fill sound buffer/param data pointer to the sound data to copy/param len length of the data to copy in bytes/return number of copyed bytes*/static int write_buffer(struct ao *ao, unsigned char *data, int len){    struct priv *p = ao->priv;    HRESULT res;    LPVOID lpvPtr1;    DWORD dwBytes1;    LPVOID lpvPtr2;    DWORD dwBytes2;    p->underrun_check = 0;    // Lock the buffer    res = IDirectSoundBuffer_Lock(p->hdsbuf, p->write_offset, len, &lpvPtr1,                                  &dwBytes1, &lpvPtr2, &dwBytes2, 0);    // If the buffer was lost, restore and retry lock.    if (DSERR_BUFFERLOST == res) {        IDirectSoundBuffer_Restore(p->hdsbuf);        res = IDirectSoundBuffer_Lock(p->hdsbuf, p->write_offset, len, &lpvPtr1,                                      &dwBytes1, &lpvPtr2, &dwBytes2, 0);    }    if (SUCCEEDED(res)) {        if (!AF_FORMAT_IS_AC3(ao->format)) {            memcpy(lpvPtr1, data, dwBytes1);            if (lpvPtr2 != NULL)                memcpy(lpvPtr2, (char *)data + dwBytes1, dwBytes2);            p->write_offset += dwBytes1 + dwBytes2;            if (p->write_offset >= p->buffer_size)                p->write_offset = dwBytes2;        } else {            // Write to pointers without reordering.            memcpy(lpvPtr1, data, dwBytes1);            if (NULL != lpvPtr2)                memcpy(lpvPtr2, data + dwBytes1, dwBytes2);            p->write_offset += dwBytes1 + dwBytes2;            if (p->write_offset >= p->buffer_size)                p->write_offset = dwBytes2;        }        // Release the data back to DirectSound.        res = IDirectSoundBuffer_Unlock(p->hdsbuf, lpvPtr1, dwBytes1, lpvPtr2,                                        dwBytes2);        if (SUCCEEDED(res)) {            // Success.            DWORD status;            IDirectSoundBuffer_GetStatus(p->hdsbuf, &status);            if (!(status & DSBSTATUS_PLAYING))                res = IDirectSoundBuffer_Play(p->hdsbuf, 0, 0, DSBPLAY_LOOPING);            return dwBytes1 + dwBytes2;        }    }    // Lock, Unlock, or Restore failed.    return 0;}
¿ª·¢ÕßID:CrimsonVoid£¬ÏîÄ¿Ãû³Æ:mpv£¬´úÂëÐÐÊý:62£¬


ʾÀý13: DSSoundFeedVoiceData

void DSSoundFeedVoiceData(unsigned char* pSound,long lBytes){	LPVOID lpvPtr1, lpvPtr2;	unsigned long dwBytes1,dwBytes2;	unsigned long *lpSS, *lpSD;	unsigned long dw,cplay,cwrite;	HRESULT hr;	unsigned long status;	IDirectSoundBuffer_GetStatus(lpDSBSECONDARY1,&status);	if (status & DSBSTATUS_BUFFERLOST)	{		if (IDirectSoundBuffer_Restore(lpDSBSECONDARY1) != DS_OK) return;		IDirectSoundBuffer_Play(lpDSBSECONDARY1,0,0,DSBPLAY_LOOPING);	}	IDirectSoundBuffer_GetCurrentPosition(lpDSBSECONDARY1,&cplay,&cwrite);	if(LastWrite == 0xffffffff) LastWrite=cwrite;	hr = IDirectSoundBuffer_Lock(lpDSBSECONDARY1,LastWrite,lBytes,        &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);	if (hr != DS_OK)	{		LastWrite=0xffffffff;		return;	}	lpSS = (unsigned long *)pSound;	lpSD = (unsigned long *)lpvPtr1;	dw = dwBytes1 >> 2;	while(dw)	{		*lpSD++=*lpSS++;		dw--;	}	if (lpvPtr2)	{		lpSD = (unsigned long *)lpvPtr2;		dw = dwBytes2 >> 2;		while(dw)		{			*lpSD++ = *lpSS++;			dw--;		}	}	IDirectSoundBuffer_Unlock(lpDSBSECONDARY1,lpvPtr1,dwBytes1,lpvPtr2,dwBytes2);	LastWrite += lBytes;	if(LastWrite >= SOUNDSIZE) LastWrite -= SOUNDSIZE;	LastPlay = cplay;}
¿ª·¢ÕßID:madnessw£¬ÏîÄ¿Ãû³Æ:thesnow£¬´úÂëÐÐÊý:56£¬


ʾÀý14: dsound_start

static bool dsound_start(void *data){   dsound_t *ds = (dsound_t*)data;   dsound_clear_buffer(ds);   if (!dsound_start_thread(ds))      return false;   return IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) == DS_OK;}
¿ª·¢ÕßID:jonakino£¬ÏîÄ¿Ãû³Æ:RetroArch£¬´úÂëÐÐÊý:10£¬


ʾÀý15: I_Update3DSound

void I_Update3DSound(int handle, sound3d_t *desc){    sndsource_t *buf = GetSource(handle);    if(!initOk || !buf) return;    if(buf->source == NULL) return;    if(buf->source3D == NULL) return;    if(!I2_IsSourcePlaying(buf)) IDirectSoundBuffer_Play(buf->source, 0, 0, 0);    I2_UpdateSource(buf, desc);}
¿ª·¢ÕßID:cmbruns£¬ÏîÄ¿Ãû³Æ:Doomsday-Engine£¬´úÂëÐÐÊý:10£¬


ʾÀý16: DX5_WaitAudio_BusyWait

static void DX5_WaitAudio_BusyWait(_THIS){	DWORD status;	DWORD cursor, junk;	HRESULT result;	/* Semi-busy wait, since we have no way of getting play notification	   on a primary mixing buffer located in hardware (DirectX 5.0)	*/	result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);	if ( result != DS_OK ) {		if ( result == DSERR_BUFFERLOST ) {			IDirectSoundBuffer_Restore(mixbuf);		}#ifdef DEBUG_SOUND		SetDSerror("DirectSound GetCurrentPosition", result);#endif		return;	}	cursor /= mixlen;	while ( cursor == playing ) {		/* FIXME: find out how much time is left and sleep that long */		SDL_Delay(10);		/* Try to restore a lost sound buffer */		IDirectSoundBuffer_GetStatus(mixbuf, &status);		if ( (status&DSBSTATUS_BUFFERLOST) ) {			IDirectSoundBuffer_Restore(mixbuf);			IDirectSoundBuffer_GetStatus(mixbuf, &status);			if ( (status&DSBSTATUS_BUFFERLOST) ) {				break;			}		}		if ( ! (status&DSBSTATUS_PLAYING) ) {			result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);			if ( result == DS_OK ) {				continue;			}#ifdef DEBUG_SOUND			SetDSerror("DirectSound Play", result);#endif			return;		}		/* Find out where we are playing */		result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,								&cursor, &junk);		if ( result != DS_OK ) {			SetDSerror("DirectSound GetCurrentPosition", result);			return;		}		cursor /= mixlen;	}}
¿ª·¢ÕßID:bohwaz£¬ÏîÄ¿Ãû³Æ:ozex£¬´úÂëÐÐÊý:55£¬


ʾÀý17: I_Update2DSound

void I_Update2DSound(int handle, int volume, int pan, int pitch){    sndsource_t *buf = GetSource(handle);    if(!initOk || !buf) return;    if(buf->source == NULL) return;    if(buf->source3D) return;    if(!I2_IsSourcePlaying(buf)) IDirectSoundBuffer_Play(buf->source, 0, 0, 0);    I2_SetVolume(buf, volume/1000.0f);    I2_SetPan(buf, pan/1000.0f);    I2_SetPitch(buf, pitch/1000.0f);}
¿ª·¢ÕßID:cmbruns£¬ÏîÄ¿Ãû³Æ:Doomsday-Engine£¬´úÂëÐÐÊý:12£¬


ʾÀý18: dsound_ctl_out

static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...){    HRESULT hr;    DWORD status;    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;    LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;    dsound *s = ds->s;    if (!dsb) {        dolog ("Attempt to control voice without a buffer/n");        return 0;    }    switch (cmd) {    case VOICE_ENABLE:        if (dsound_get_status_out (dsb, &status, s)) {            return -1;        }        if (status & DSBSTATUS_PLAYING) {            dolog ("warning: Voice is already playing/n");            return 0;        }        dsound_clear_sample (hw, dsb, s);        hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING);        if (FAILED (hr)) {            dsound_logerr (hr, "Could not start playing buffer/n");            return -1;        }        break;    case VOICE_DISABLE:        if (dsound_get_status_out (dsb, &status, s)) {            return -1;        }        if (status & DSBSTATUS_PLAYING) {            hr = IDirectSoundBuffer_Stop (dsb);            if (FAILED (hr)) {                dsound_logerr (hr, "Could not stop playing buffer/n");                return -1;            }        }        else {            dolog ("warning: Voice is not playing/n");        }        break;    }    return 0;}
¿ª·¢ÕßID:01org£¬ÏîÄ¿Ãû³Æ:qemu-lite£¬´úÂëÐÐÊý:52£¬


ʾÀý19: dsound_start

static bool dsound_start(void *data, bool is_shutdown){   dsound_t *ds = (dsound_t*)data;   dsound_clear_buffer(ds);   if (!dsound_start_thread(ds))      return false;   ds->is_paused = (IDirectSoundBuffer_Play(            ds->dsb, 0, 0, DSBPLAY_LOOPING) == DS_OK) ? false : true;   return (ds->is_paused) ? false : true;}
¿ª·¢ÕßID:Alcaro£¬ÏîÄ¿Ãû³Æ:RetroArch£¬´úÂëÐÐÊý:13£¬


ʾÀý20: SndSys_LockRenderBuffer

/*====================SndSys_LockRenderBufferGet the exclusive lock on "snd_renderbuffer"====================*/qboolean SndSys_LockRenderBuffer (void){#ifdef SUPPORTDIRECTX	int reps;	HRESULT hresult;	DWORD	dwStatus;	if (pDSBuf)	{		// if the buffer was lost or stopped, restore it and/or restart it		if (IDirectSoundBuffer_GetStatus (pDSBuf, &dwStatus) != DS_OK)			Con_Print("Couldn't get sound buffer status/n");		if (dwStatus & DSBSTATUS_BUFFERLOST)		{			Con_Print("DSound buffer is lost!!/n");			IDirectSoundBuffer_Restore (pDSBuf);		}		if (!(dwStatus & DSBSTATUS_PLAYING))			IDirectSoundBuffer_Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);		reps = 0;		while ((hresult = IDirectSoundBuffer_Lock(pDSBuf, 0, gSndBufSize, (LPVOID*)&dsound_pbuf, &dsound_dwSize, (LPVOID*)&dsound_pbuf2, &dsound_dwSize2, 0)) != DS_OK)		{			if (hresult != DSERR_BUFFERLOST)			{				Con_Print("S_LockBuffer: DS: Lock Sound Buffer Failed/n");				S_Shutdown ();				S_Startup ();				return false;			}			if (++reps > 10000)			{				Con_Print("S_LockBuffer: DS: couldn't restore buffer/n");				S_Shutdown ();				S_Startup ();				return false;			}		}		if ((void*)dsound_pbuf != snd_renderbuffer->ring)			Sys_Error("SndSys_LockRenderBuffer: the ring address has changed!!!/n");		return true;	}#endif	return wav_init;}
¿ª·¢ÕßID:kasymovga£¬ÏîÄ¿Ãû³Æ:DarkPlacesRM£¬´úÂëÐÐÊý:58£¬


ʾÀý21: SSInit

BOOL SSInit(HWND hWnd, int channels, unsigned flags){	LPDIRECTSOUNDBUFFER lpPrimaryBuffer;	LPDIRECTSOUND lpDS;	DSBUFFERDESC dsbd;	if (SSMixer.lpds) return TRUE;//	Perform Direct Sound Initialization	if (DirectSoundCreate(NULL, &lpDS, NULL) != DS_OK) 		return FALSE;	SSMixer.lpds = lpDS;	if (IDirectSound_SetCooperativeLevel(lpDS, hWnd, DSSCL_NORMAL) != DS_OK) {		SSDestroy();		return FALSE;	}//	Start Mixer	memset(&dsbd, 0, sizeof(DSBUFFERDESC));	dsbd.dwSize = sizeof(DSBUFFERDESC);	dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;	if (IDirectSound_CreateSoundBuffer(SSMixer.lpds, &dsbd, &lpPrimaryBuffer, NULL) == DS_OK) {		if (IDirectSoundBuffer_Play(lpPrimaryBuffer, 0, 0, DSBPLAY_LOOPING) != DS_OK) {			IDirectSoundBuffer_Release(lpPrimaryBuffer);			SSDestroy();			return FALSE;		}		IDirectSoundBuffer_Release(lpPrimaryBuffer);	}	else {		SSDestroy();		return FALSE;	}//	Finish initializing SSMixer.	SSMixer.ch_cur = 0;	SSMixer.ch_list = (SSoundBuffer *)malloc(sizeof(SSoundBuffer)*channels);	if (!SSMixer.ch_list) return FALSE;		memset(SSMixer.ch_list, 0, sizeof(SSoundBuffer)*channels);		SSMixer.ch_num = channels;//	Determine Sound technology and volume caps	waveOutGetVolume((HWAVEOUT)WAVE_MAPPER, (LPDWORD)&SSMixer.old_master_vol);//	waveOutSetVolume((HWAVEOUT)WAVE_MAPPER, 0x40004000);	return TRUE;}
¿ª·¢ÕßID:btb£¬ÏîÄ¿Ãû³Æ:d2x£¬´úÂëÐÐÊý:51£¬


ʾÀý22: SndObjPlay

BOOL SndObjPlay(SNDOBJ *pSO, DWORD dwPlayFlags){    BOOL result = FALSE;    if (pSO == NULL)        return FALSE;    if ((!(dwPlayFlags & DSBPLAY_LOOPING) || (pSO->iAlloc == 1)))    {        IDirectSoundBuffer *pDSB = SndObjGetFreeBuffer(pSO);        if (pDSB != NULL) {            result = SUCCEEDED(IDirectSoundBuffer_Play(pDSB, 0, 0, dwPlayFlags));        }    }    return result;}
¿ª·¢ÕßID:bowlofstew£¬ÏîÄ¿Ãû³Æ:ja2£¬´úÂëÐÐÊý:17£¬


ʾÀý23: DSoundRender_OnStartStreaming

static VOID WINAPI DSoundRender_OnStartStreaming(BaseRenderer * iface){    DSoundRenderImpl *This = impl_from_BaseRenderer(iface);    TRACE("(%p)/n", This);    if (This->renderer.pInputPin->pin.pConnectedTo)    {        if (This->renderer.filter.state == State_Paused)        {            /* Unblock our thread, state changing from paused to running doesn't need a reset for state change */            SetEvent(This->blocked);        }        IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);        ResetEvent(This->blocked);    }}
¿ª·¢ÕßID:reactos£¬ÏîÄ¿Ãû³Æ:reactos£¬´úÂëÐÐÊý:17£¬


ʾÀý24: CheckDStatus

void CheckDStatus(void){  DWORD status;  status=0;  IDirectSoundBuffer_GetStatus(ppbufw, &status);  if(status&DSBSTATUS_BUFFERLOST)  {   IDirectSoundBuffer_Restore(ppbufw);  }  if(!(status&DSBSTATUS_PLAYING))  {   ToWritePos=0;   IDirectSoundBuffer_SetFormat(ppbufw,&wf);   IDirectSoundBuffer_Play(ppbufw,0,0,DSBPLAY_LOOPING);  }}
¿ª·¢ÕßID:ficoos£¬ÏîÄ¿Ãû³Æ:fceu-next£¬´úÂëÐÐÊý:18£¬


ʾÀý25: DSOUND_Restore

void DSOUND_Restore(void){// if the buffer was lost or stopped, restore it and/or restart it        DWORD       dwStatus;        if (!pDSBuf) return;	if (IDirectSoundBuffer_GetStatus (pDSBuf, &dwStatus) != DD_OK)        	Con_Printf ("Couldn't get sound buffer status/n");	if (dwStatus & DSBSTATUS_BUFFERLOST)		IDirectSoundBuffer_Restore (pDSBuf);	if (!(dwStatus & DSBSTATUS_PLAYING))		IDirectSoundBuffer_Play (pDSBuf, 0, 0, DSBPLAY_LOOPING);        return;}
¿ª·¢ÕßID:luaman£¬ÏîÄ¿Ãû³Æ:qforge-newtree£¬´úÂëÐÐÊý:18£¬


ʾÀý26: Pause

static HRESULT Pause( aout_stream_sys_t *sys, bool pause ){    HRESULT hr;    if( pause )        hr = IDirectSoundBuffer_Stop( sys->p_dsbuffer );    else        hr = IDirectSoundBuffer_Play( sys->p_dsbuffer, 0, 0, DSBPLAY_LOOPING );    if( hr == DS_OK )    {        vlc_mutex_lock( &sys->lock );        sys->b_playing = !pause;        if( sys->b_playing )            vlc_cond_signal( &sys->cond );        vlc_mutex_unlock( &sys->lock );    }    return hr;}
¿ª·¢ÕßID:videolan£¬ÏîÄ¿Ãû³Æ:vlc£¬´úÂëÐÐÊý:18£¬


ʾÀý27: PlaySoundBuffer

/* * ¥Ð¥Ã¥Õ¥¡¤òÔÙÉú¤¹¤ë */static BOOL PlaySoundBuffer(int nBuffer, struct wave *pStr){	HRESULT hRet;	int i;	assert(pDSBuffer[nBuffer] != NULL);	assert(pStream[nBuffer] == NULL);	assert(nBuffer >= 0 && nBuffer < MIXER_STREAMS);	/* ¥Ð¥Ã¥Õ¥¡¤¬¥í¥¹¥È¤·¤Æ¤¤¤ì¤ÐÐÞ
C++ IDirectSoundBuffer_Restoreº¯Êý´úÂëʾÀý
C++ IDirectSoundBuffer_Lockº¯Êý´úÂëʾÀý
ÍòÊÂOK×ÔÑ§Íø£º51×ÔÑ§Íø_Èí¼þ×ÔÑ§Íø_CAD×ÔÑ§Íø×Ôѧexcel¡¢×ÔѧPS¡¢×ÔѧCAD¡¢×ÔѧCÓïÑÔ¡¢×Ôѧcss3ʵÀý£¬ÊÇÒ»¸öͨ¹ýÍøÂç×ÔÖ÷ѧϰ¹¤×÷¼¼ÄܵÄ×Ôѧƽ̨£¬ÍøÓÑϲ»¶µÄÈí¼þ×ÔÑ§ÍøÕ¾¡£