当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECTSOUNDBUFFER::Play方法代码示例

本文整理汇总了C++中LPDIRECTSOUNDBUFFER::Play方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUNDBUFFER::Play方法的具体用法?C++ LPDIRECTSOUNDBUFFER::Play怎么用?C++ LPDIRECTSOUNDBUFFER::Play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECTSOUNDBUFFER的用法示例。


在下文中一共展示了LPDIRECTSOUNDBUFFER::Play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SNDDMA_InitDS

static qbool SNDDMA_InitDS()
{
	HRESULT			hresult;
	DSBUFFERDESC	dsbuf;
	DSBCAPS			dsbcaps;
	WAVEFORMATEX	format;

	Com_Printf( "Initializing DirectSound\n" );

	if (SUCCEEDED( hresult = CoCreateInstance( CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound8, (void **)&pDS))) {
		Com_DPrintf( "Using DS8\n" );
	}
	else if (SUCCEEDED( hresult = CoCreateInstance( CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound, (void **)&pDS))) {
		Com_DPrintf( "Using legacy DS\n" );
	}
	else {
		Com_Printf("failed\n");
		SNDDMA_Shutdown();
		return qfalse;
	}

	hresult = pDS->Initialize( NULL );

	Com_DPrintf("...setting DSSCL_PRIORITY coop level: " );

	if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) ) {
		Com_Printf ("failed\n");
		SNDDMA_Shutdown();
		return qfalse;
	}
	Com_DPrintf("ok\n" );


	// create the secondary buffer we'll actually work with
	dma.channels = 2;
	dma.samplebits = 16;
	dma.speed = 22050;

	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
	format.nChannels = dma.channels;
	format.wBitsPerSample = dma.samplebits;
	format.nSamplesPerSec = dma.speed;
	format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
	format.cbSize = 0;
	format.nAvgBytesPerSec = format.nSamplesPerSec*format.nBlockAlign;

	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);

	dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
	dsbuf.lpwfxFormat = &format;

	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);

	Com_DPrintf( "...creating secondary buffer: " );
	dsbuf.dwFlags = DSBCAPS_LOCHARDWARE | DSBCAPS_GETCURRENTPOSITION2;
	if (DS_OK == pDS->CreateSoundBuffer( &dsbuf, &pDSBuf, NULL )) {
		Com_Printf( "locked hardware.  ok\n" );
	}
	else {
		// Couldn't get hardware, fallback to software.
		dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2;
		if (DS_OK != pDS->CreateSoundBuffer( &dsbuf, &pDSBuf, NULL )) {
			Com_Printf( "failed\n" );
			SNDDMA_Shutdown();
			return qfalse;
		}
		Com_DPrintf( "forced to software.  ok\n" );
	}

	// Make sure mixer is active
	if ( DS_OK != pDSBuf->Play( 0, 0, DSBPLAY_LOOPING ) ) {
		Com_Printf ("*** Looped sound play failed ***\n");
		SNDDMA_Shutdown ();
		return qfalse;
	}

	// get the returned buffer size
	if ( DS_OK != pDSBuf->GetCaps(&dsbcaps) ) {
		Com_Printf ("*** GetCaps failed ***\n");
		SNDDMA_Shutdown ();
		return qfalse;
	}

	gSndBufSize = dsbcaps.dwBufferBytes;

	dma.channels = format.nChannels;
	dma.samplebits = format.wBitsPerSample;
	dma.speed = format.nSamplesPerSec;
	dma.samples = gSndBufSize/(dma.samplebits/8);
	dma.submission_chunk = 1;
	dma.buffer = NULL;			// must be locked first

	sample16 = (dma.samplebits/8) - 1;

	SNDDMA_BeginPainting();
	if (dma.buffer)
		memset(dma.buffer, 0, dma.samples * dma.samplebits/8);
//.........这里部分代码省略.........
开发者ID:ShaneIsley,项目名称:challengeq3,代码行数:101,代码来源:win_snd.cpp

示例2: main

int main()
{
    using namespace flamenco;
    
    LPDIRECTSOUND8 directSound;
    
    // Создаем интерфейс DirectSound.
    check_directx(DirectSoundCreate8(&GUID_NULL, &directSound, NULL));
    check_directx(directSound->SetCooperativeLevel(GetForegroundWindow(), DSSCL_PRIORITY));
    
    // Получаем первичный буфер.
    LPDIRECTSOUNDBUFFER primaryBuffer = NULL;
    DSBUFFERDESC descr;
    ZeroMemory(&descr, sizeof(DSBUFFERDESC));
    descr.dwSize = sizeof(DSBUFFERDESC);
    descr.dwFlags = DSBCAPS_PRIMARYBUFFER;
    descr.lpwfxFormat = NULL;
    check_directx(directSound->CreateSoundBuffer(&descr, &primaryBuffer, NULL));
    
    // Изменяем формат первичного буфера.
    WAVEFORMATEX wfx;
    ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
    wfx.cbSize          = sizeof(WAVEFORMATEX);
    wfx.wFormatTag      = WAVE_FORMAT_PCM;
    wfx.nChannels       = 2;
    wfx.nSamplesPerSec  = FREQUENCY;
    wfx.wBitsPerSample  = 16;
    wfx.nBlockAlign     = wfx.wBitsPerSample / 8 * wfx.nChannels;
    wfx.nAvgBytesPerSec = (u32)wfx.nSamplesPerSec * wfx.nBlockAlign;
    check_directx(primaryBuffer->SetFormat(&wfx));
    primaryBuffer->Release();
    
    
    // Формат буфера микшера.
    const u32 MIXER_BUFFER_SIZE_IN_BYTES = MIXER_BUFFER_SIZE_IN_SAMPLES * sizeof(s16);
    // Размер звукового буфера должен быть больше 100 ms, иначе GetCurrentPosition()
    // будет выдавать неправильные данные.
    const u32 SOUND_BUFFER_SIZE_IN_BYTES = 10 * MIXER_BUFFER_SIZE_IN_BYTES;
    DSBUFFERDESC desc;
    ZeroMemory(&desc, sizeof(DSBUFFERDESC));
    desc.dwSize          = sizeof(DSBUFFERDESC);
    desc.dwFlags         = DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
    desc.dwBufferBytes   = SOUND_BUFFER_SIZE_IN_BYTES;
    desc.guid3DAlgorithm = DS3DALG_DEFAULT;
    desc.lpwfxFormat     = &wfx;
    
    // Создаем буфер.
    LPDIRECTSOUNDBUFFER soundBuffer = NULL;
    check_directx(directSound->CreateSoundBuffer(&desc, &soundBuffer, NULL));
    
    //reference<stream<ogg_decoder> > sound = stream<ogg_decoder>::create(std::auto_ptr<source>(new file_source("input.ogg")));
    
    // Инициализация flamenco.
    mixer & mixer = mixer::singleton();
    
    reference<sound_stream_base> sound = stream<wavpack_decoder>::create(std::auto_ptr<source>(new file_source("input.wv")));
    //assert(!src.get());
    mixer.attach(sound);
    /*
    
    reference<pin> sine = sine::create(400);
    reference<ogg> wave = ogg::create("input.ogg");
    reference<pin> noise = noise::create();
    
    reference<volume_pan> vp = volume_pan::create(sound, 1.0f, 0.0f);
    
    //mixer.attach(sine);
    mixer.attach(vp);
    //mixer.attach(noise);
    */
    
    // Заполнение звукового буфера.
    s16 * bufferPtr;
    u32 bufferSize;
    check_directx(soundBuffer->Lock(0, 0, reinterpret_cast<void **>(&bufferPtr), &bufferSize,
                                    NULL, NULL, DSBLOCK_ENTIREBUFFER));
    // Заполняем обе половинки буфера.
    mixer.mix(bufferPtr);
    mixer.mix(bufferPtr + MIXER_BUFFER_SIZE_IN_SAMPLES);
    check_directx(soundBuffer->Unlock(bufferPtr, bufferSize, NULL, 0));
    
    // Проигрываем звук и дописываем данные по ходу.
    soundBuffer->Play(0, 0, DSBPLAY_LOOPING);
    u32 writeOffset = MIXER_BUFFER_SIZE_IN_BYTES * 2;
    while (true)
    {
        u32 cursorPos;
        soundBuffer->GetCurrentPosition(&cursorPos, NULL);
        
        // Определяем, нужно ли дописать очередную порцию данных.
        u32 offset = (SOUND_BUFFER_SIZE_IN_BYTES + writeOffset - cursorPos) % SOUND_BUFFER_SIZE_IN_BYTES;
        if (offset > MIXER_BUFFER_SIZE_IN_BYTES)
        {
            check_directx(soundBuffer->Lock(writeOffset, MIXER_BUFFER_SIZE_IN_BYTES,
                              reinterpret_cast<void **>(&bufferPtr), &bufferSize,
                              NULL, NULL, 0));
            mixer.mix(bufferPtr);
            check_directx(soundBuffer->Unlock(bufferPtr, bufferSize, NULL, 0));
            writeOffset = (writeOffset + MIXER_BUFFER_SIZE_IN_BYTES) % SOUND_BUFFER_SIZE_IN_BYTES;
        }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:flamenco,代码行数:101,代码来源:test.cpp

示例3: run

void DXAudioOutput::run() {
	HRESULT hr;
	DSBUFFERDESC        dsbdesc;
	WAVEFORMATEXTENSIBLE wfx;
	WAVEFORMATEXTENSIBLE wfxSet;
	int ns = 0;
	unsigned int chanmasks[32];

	LPDIRECTSOUND8             pDS = NULL;
	LPDIRECTSOUNDBUFFER       pDSBPrimary = NULL;
	LPDIRECTSOUNDBUFFER       pDSBOutput = NULL;
	LPDIRECTSOUNDNOTIFY8       pDSNotify = NULL;

	DWORD	dwBufferSize;
	DWORD	dwLastWritePos;
	DWORD	dwLastPlayPos;
	DWORD	dwTotalPlayPos;
	int iLastwriteblock;
	LPVOID aptr1, aptr2;
	DWORD nbytes1, nbytes2;

	int playblock;
	int nowriteblock;
	DWORD dwPlayPosition, dwWritePosition;

	unsigned int iByteSize;

	bool bOk;
	DWORD dwSpeakerConfig;

	bool failed = false;

	bOk = false;
	DWORD dwMask = 0;
	bool bHead = false;

	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
	dsbdesc.dwSize  = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;

	if (! g.s.qbaDXOutput.isEmpty()) {
		LPGUID lpguid = reinterpret_cast<LPGUID>(g.s.qbaDXOutput.data());
		if (FAILED(hr = DirectSoundCreate8(lpguid, &pDS, NULL))) {
			failed = true;
		}
	}

	if (! pDS && FAILED(hr = DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback, &pDS, NULL))) {
		qWarning("DXAudioOutput: DirectSoundCreate failed: hr=0x%08lx", hr);
		goto cleanup;
	} else if (FAILED(hr = pDS->SetCooperativeLevel(g.mw->winId(), DSSCL_PRIORITY))) {
		qWarning("DXAudioOutput: SetCooperativeLevel failed: hr=0x%08lx", hr);
		goto cleanup;
	} else if (FAILED(hr = pDS->CreateSoundBuffer(&dsbdesc, &pDSBPrimary, NULL))) {
		qWarning("DXAudioOutput: CreateSoundBuffer (Primary) failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	pDS->GetSpeakerConfig(&dwSpeakerConfig);


	switch (DSSPEAKER_CONFIG(dwSpeakerConfig)) {
		case DSSPEAKER_HEADPHONE:
			dwMask = KSAUDIO_SPEAKER_STEREO;
			bHead = true;
			break;
		case DSSPEAKER_MONO:
			dwMask = KSAUDIO_SPEAKER_MONO;
			break;
		case DSSPEAKER_QUAD:
			dwMask = KSAUDIO_SPEAKER_QUAD;
			break;
		case DSSPEAKER_STEREO:
			dwMask = KSAUDIO_SPEAKER_STEREO;
			break;
		case DSSPEAKER_SURROUND:
			dwMask = KSAUDIO_SPEAKER_SURROUND;
			break;
		case DSSPEAKER_5POINT1:
			dwMask = KSAUDIO_SPEAKER_5POINT1;
			break;
		case DSSPEAKER_7POINT1:
			dwMask = KSAUDIO_SPEAKER_7POINT1;
			break;
		case DSSPEAKER_7POINT1_SURROUND:
			dwMask = KSAUDIO_SPEAKER_7POINT1_SURROUND;
			break;
		case DSSPEAKER_5POINT1_SURROUND:
			dwMask = KSAUDIO_SPEAKER_5POINT1_SURROUND;
			break;
		default:
			dwMask = 0;
			break;
	}

	if (! g.s.doPositionalAudio())
		dwMask = KSAUDIO_SPEAKER_STEREO;

	for (int i=0;i<32;i++) {
		if (dwMask & (1 << i)) {
//.........这里部分代码省略.........
开发者ID:EarlOfWenc,项目名称:mumble,代码行数:101,代码来源:DirectSound.cpp

示例4: resume

void DirectSound::resume()
{
  if(dsbSecondary != NULL) {
    dsbSecondary->Play(0,0,DSBPLAY_LOOPING);
  }  
}
开发者ID:BackupTheBerlios,项目名称:vbastep-svn,代码行数:6,代码来源:DirectSound.cpp

示例5: DS_Init

//===========================================================================
// DS_Init
//===========================================================================
int DS_Init(void)
{
	HWND				hWnd;
	DSBUFFERDESC		desc;
	LPDIRECTSOUNDBUFFER	bufTemp;

	if(initOk) return true;

	// Are we in verbose mode?	
	if((verbose = ArgExists("-verbose")))
		Con_Message("DS_Init(Compat): Initializing sound driver...\n");

	// Get Doomsday's window handle.
	hWnd = (HWND) DD_GetInteger(DD_WINDOW_HANDLE);

	hr = DS_OK;
	if(ArgExists("-noeax") 
		|| FAILED(hr = EAXDirectSoundCreate(NULL, &dsound, NULL)))
	{
		// EAX can't be initialized. Use normal DS, then.
		if(FAILED(hr)) Error("DS_Init", "EAX 2 couldn't be initialized.");
		if(FAILED(hr = DirectSoundCreate(NULL, &dsound, NULL)))
		{
			Error("DS_Init", "Failed to create dsound interface.");
			return false;
		}
	}
	// Set the cooperative level.
	if(FAILED(hr = dsound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY)))
	{
		Error("DS_Init", "Couldn't set dSound coop level.");
		return false;
	}
	// Get the primary buffer and the listener.
	primary = NULL;
	memset(&desc, 0, sizeof(desc));
	desc.dwSize = sizeof(desc);
	desc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER;
	dsListener = NULL;
	if(SUCCEEDED(dsound->CreateSoundBuffer(&desc, &primary, NULL)))
	{
		// Query the listener interface.
		primary->QueryInterface(IID_IDirectSound3DListener, 
			(void**) &dsListener);
	}
	else
	{
		// Failure; get a 2D primary buffer, then.
		desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
		dsound->CreateSoundBuffer(&desc, &primary, NULL);
	}
	// Start playing the primary buffer.
	if(primary) 
	{
		if(FAILED(hr = primary->Play(0, 0, DSBPLAY_LOOPING)))
			Error("DS_Init", "Can't play primary buffer.");
	}
	
	// Try to get the EAX listener property set. 
	// Create a temporary secondary buffer for it.
	eaxListener = NULL;
	if(SUCCEEDED(CreateDSBuffer(DSBCAPS_STATIC | DSBCAPS_CTRL3D, 
		DSBSIZE_MIN, 22050, 8, 1, &bufTemp)))
	{
		// Now try to get the property set.
		if(SUCCEEDED(hr = bufTemp->QueryInterface(IID_IKsPropertySet, 
			(void**) &eaxListener)))
		{
			DWORD support = 0, revsize = 0;
			// Check for support.
			if(FAILED(hr = eaxListener->QuerySupport(
				DSPROPSETID_EAX_ListenerProperties,
				DSPROPERTY_EAXLISTENER_ENVIRONMENT,
				&support)) 
				|| ((support & NEEDED_SUPPORT) != NEEDED_SUPPORT))
			{
				Error("DS_Init", "Sufficient EAX2 support not present.");
				eaxListener->Release();
				eaxListener = NULL;
			}
			else
			{
				// EAX is supported!
				if(verbose) Con_Message("DS_Init(Compat): EAX2 is available.\n");
			}
		}
		// Release the temporary buffer interface.
		bufTemp->Release();
	}
		
	// Get the caps.
	dsCaps.dwSize = sizeof(dsCaps);
	dsound->GetCaps(&dsCaps);
	if(verbose) Con_Message("DS_Init(Compat): Number of hardware 3D "
		"buffers: %i\n", dsCaps.dwMaxHw3DAllBuffers);

	// Configure the DS3D listener.
//.........这里部分代码省略.........
开发者ID:amitahire,项目名称:development,代码行数:101,代码来源:driver_sndcmp.cpp

示例6: Write

int audioStreamer_ds::Write(char *buf, int len) // returns 0 on success
{ 
  if (len<1) return 0;
  if (!m_outbuf) return -1;

  if (!m_has_started)
  {
    m_outbuf->Play(0,0,DSBPLAY_LOOPING);
    m_has_started=1;
  }


  int thispos=0,ppos=0;
  m_outbuf->GetCurrentPosition((DWORD*)&ppos,(DWORD*)&thispos);

//  thispos=ppos; // let's use the write cursor, not the play position

  if (thispos < m_last_pos) 
  {
    m_i_dw++;
  }
  m_last_pos = thispos;

  if (m_i_lw < m_i_dw || (m_i_lw == m_i_dw && m_bufpos < thispos )) // detect if we fall too far behind
  {
//    audiostream_onunder();
    m_i_lw=m_i_dw;
    m_bufpos=0;
    while (m_bufpos <= thispos+m_bufsize) m_bufpos+=m_bufsize;
    if (m_bufpos >= m_totalbufsize)
    {
      m_bufpos -= m_totalbufsize;
      m_i_lw++;
    }
  }

  if (m_bufpos + len >= ppos && m_i_lw > m_i_dw)
  {
    return 0;
  }

//    printf("%d,%d,%d\n",m_totalbufsize, tp2, m_bufpos+len);

  if (1)//tp2 >= m_bufpos + len)
  {
    void *v1=0, *v2=0;
    DWORD lv1=0, lv2=0;
    if (m_outbuf->Lock(m_bufpos,len,&v1,&lv1,&v2,&lv2,0) == DS_OK)
    {
      memcpy(v1,buf,min((int)lv1,len));
      if ((int)lv1 < len && v2 && lv2) memcpy(v2,buf+lv1,min((int)lv2,(int)(len-lv1)));

      m_outbuf->Unlock(v1,lv1,v2,lv2);

      m_bufpos += len;
      if (m_bufpos >= m_totalbufsize) 
      {
        m_bufpos -= m_totalbufsize;
        m_i_lw++;
      }
    }
    else 
    {
      return -1;
    }


  }
  else
  {
//  	audiostream_onunder(); // g_sound_in_overruns?
  }

  return 0;
}
开发者ID:libninjam,项目名称:libninjam-win,代码行数:75,代码来源:audiostream_win32.cpp

示例7: init


//.........这里部分代码省略.........

  DSBUFFERDESC dsbdesc;
  ZeroMemory(&dsbdesc,sizeof(DSBUFFERDESC));
  dsbdesc.dwSize=sizeof(DSBUFFERDESC);
  dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
  
  if((hr=pDirectSound->CreateSoundBuffer(&dsbdesc,
                                         &dsbPrimary,
                                         NULL) != DS_OK)) {
    //    errorMessage(myLoadString(IDS_ERROR_SOUND_BUFFER),hr);
    systemMessage(IDS_CANNOT_CREATESOUNDBUFFER,
                  "Cannot CreateSoundBuffer %08x", hr);
    return false;
  }
  
  // Set primary buffer format

  memset(&wfx, 0, sizeof(WAVEFORMATEX)); 
  wfx.wFormatTag = WAVE_FORMAT_PCM; 
  wfx.nChannels = 2;
  switch(soundQuality) {
  case 2:
    wfx.nSamplesPerSec = 22050;
    soundBufferLen = 736*2;
    soundBufferTotalLen = 7360*2;
    break;
  case 4:
    wfx.nSamplesPerSec = 11025;
    soundBufferLen = 368*2;
    soundBufferTotalLen = 3680*2;
    break;
  default:
    soundQuality = 1;
    wfx.nSamplesPerSec = 44100;
    soundBufferLen = 1470*2;
    soundBufferTotalLen = 14700*2;
  }
  wfx.wBitsPerSample = 16; 
  wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
  wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

  if((hr = dsbPrimary->SetFormat(&wfx)) != DS_OK) {
    //    errorMessage(myLoadString(IDS_ERROR_SOUND_PRIMARY),hr);
    systemMessage(IDS_CANNOT_SETFORMAT_PRIMARY,
                  "Cannot SetFormat for primary %08x", hr);
    return false;
  }
  
  ZeroMemory(&dsbdesc,sizeof(DSBUFFERDESC));  
  dsbdesc.dwSize = sizeof(DSBUFFERDESC);
  dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLPOSITIONNOTIFY;
  dsbdesc.dwBufferBytes = soundBufferTotalLen;
  dsbdesc.lpwfxFormat = &wfx;

  if((hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbSecondary, NULL))
     != DS_OK) {
    dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
    if((hr = pDirectSound->CreateSoundBuffer(&dsbdesc, &dsbSecondary, NULL))
       != DS_OK) {
      systemMessage(IDS_CANNOT_CREATESOUNDBUFFER_SEC,
                    "Cannot CreateSoundBuffer secondary %08x", hr);
      return false;
    }
  }

  dsbSecondary->SetCurrentPosition(0);

  if(!theApp.useOldSync) {
    hr = dsbSecondary->QueryInterface(IID_IDirectSoundNotify,
                                      (void **)&dsbNotify);
    if(!FAILED(hr)) {
      dsbEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
      
      DSBPOSITIONNOTIFY notify[10];
      
      for(int i = 0; i < 10; i++) {
        notify[i].dwOffset = i*soundBufferLen;
        notify[i].hEventNotify = dsbEvent;
      }
      if(FAILED(dsbNotify->SetNotificationPositions(10, notify))) {
        dsbNotify->Release();
        dsbNotify = NULL;
        CloseHandle(dsbEvent);
        dsbEvent = NULL;
      }
    }
  }
  
  hr = dsbPrimary->Play(0,0,DSBPLAY_LOOPING);

  if(hr != DS_OK) {
    //    errorMessage(myLoadString(IDS_ERROR_SOUND_PLAYPRIM), hr);
    systemMessage(IDS_CANNOT_PLAY_PRIMARY, "Cannot Play primary %08x", hr);
    return false;
  }

  systemSoundOn = true;
  
  return true;
}
开发者ID:BackupTheBerlios,项目名称:vbastep-svn,代码行数:101,代码来源:DirectSound.cpp

示例8: sizeof

// playing thread
static DWORD __stdcall dsound_play_thread(void *param) {
  // primary buffer caps
  DSBCAPS caps;
  caps.dwSize = sizeof(caps);
  primary_buffer->GetCaps(&caps);

  // primary buffer format
  WAVEFORMATEX format;
  primary_buffer->GetFormat(&format, sizeof(format), NULL);

  // timer resolustion
  timeBeginPeriod(1);

  // temp buffer for vsti process
  float output_buffer[2][4096];

  // data write posision
  int write_position = 0;

  // start playing primary buffer
  primary_buffer->Play(0, 0, DSBPLAY_LOOPING);

  while (dsound_thread) {
    DWORD play_pos, write_pos;

    // get current position
    primary_buffer->GetCurrentPosition(&play_pos, &write_pos);

    // size left in buffer to write.
    int data_buffer_size = (caps.dwBufferBytes + write_position - write_pos) % caps.dwBufferBytes;

    // write buffer size
    int write_buffer_size = buffer_size * format.nBlockAlign;

    // size left in buffer
    int write_size = write_buffer_size - data_buffer_size;

    // maybe data buffer is underflowed.
    if (write_size < 0) {
      write_size = (caps.dwBufferBytes + write_pos + write_buffer_size - write_position) % caps.dwBufferBytes;
    }

    // write data at least 32 samles
    if (write_size >= 32 * format.nBlockAlign) {
      //printf("%8d, %8d, %8d, %8d, %8d\n", timeGetTime(),  (caps.dwBufferBytes + write_position + write_size - write_pos) % caps.dwBufferBytes, write_pos, write_size, write_buffer_size);

      // samples
      uint samples = write_size / format.nBlockAlign;

      if (export_rendering()) {
        memset(output_buffer[0], 0, samples * sizeof(float));
        memset(output_buffer[1], 0, samples * sizeof(float));
      } else   {
        // update
        song_update(1000.0 * (double)samples / (double)format.nSamplesPerSec);

        // call vsti process func
        vsti_update_config((float)format.nSamplesPerSec, 4096);
        vsti_process(output_buffer[0], output_buffer[1], samples);
      }

      // lock primary buffer
      void  *ptr1, *ptr2;
      DWORD size1, size2;
      HRESULT hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);

      // device lost, restore and try again
      if (DSERR_BUFFERLOST == hr) {
        primary_buffer->Restore();
        hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);
      }

      // lock succeeded
      if (SUCCEEDED(hr)) {
        float *left = output_buffer[0];
        float *right = output_buffer[1];

        uint samples1 = size1 / format.nBlockAlign;
        uint samples2 = size2 / format.nBlockAlign;

        if (ptr1) write_buffer((short *)ptr1, left, right, samples1);
        if (ptr2) write_buffer((short *)ptr2, left + samples1, right + samples1, samples2);

        hr = primary_buffer->Unlock(ptr1, size1, ptr2, size2);

        write_position = (write_position + write_size) % caps.dwBufferBytes;
      }

    } else   {
      Sleep(1);
    }
  }

  // stop sound buffer
  primary_buffer->Stop();

  // timer resolustion
  timeEndPeriod(10);

//.........这里部分代码省略.........
开发者ID:YueLinHo,项目名称:freepiano,代码行数:101,代码来源:output_dsound.cpp

示例9: SNDDMA_InitDS

int SNDDMA_InitDS ()
{
	HRESULT			hresult;
	DSBUFFERDESC	dsbuf;
	DSBCAPS			dsbcaps;
	WAVEFORMATEX	format;

	Com_Printf( "Initializing DirectSound\n");

    // Create IDirectSound using the primary sound device
    if( FAILED( hresult = DirectSoundCreate8(NULL, &pDS, NULL) ) ) {
		Com_Printf ("failed\n");
		SNDDMA_Shutdown ();
		return false;
	}

	hresult = pDS->Initialize(NULL);

	Com_DPrintf( "ok\n" );

	Com_DPrintf("...setting DSSCL_PRIORITY coop level: " );

	if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) )	{
		Com_Printf ("failed\n");
		SNDDMA_Shutdown ();
		return false;
	}
	Com_DPrintf("ok\n" );


	// create the secondary buffer we'll actually work with
	dma.channels = 2;
	dma.samplebits = 16;

//	if (s_khz->integer == 44)
//		dma.speed = 44100;
//	else if (s_khz->integer == 22)
//		dma.speed = 22050;
//	else
//		dma.speed = 11025;

	dma.speed = 22050;
	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
    format.nChannels = dma.channels;
    format.wBitsPerSample = dma.samplebits;
    format.nSamplesPerSec = dma.speed;
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
    format.cbSize = 0;
    format.nAvgBytesPerSec = format.nSamplesPerSec*format.nBlockAlign; 

	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);

	// Micah: take advantage of 2D hardware.if available.
	dsbuf.dwFlags = DSBCAPS_LOCHARDWARE;
	dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2;
	dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
	dsbuf.lpwfxFormat = &format;
	
	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);
	
	Com_DPrintf( "...creating secondary buffer: " );
	if (DS_OK == pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL)) {
		Com_Printf( "locked hardware.  ok\n" );
	}
	else {
		// Couldn't get hardware, fallback to software.
		dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE;
		dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2;
		if (DS_OK != pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL)) {
			Com_Printf( "failed\n" );
			SNDDMA_Shutdown ();
			return false;
		}
		Com_DPrintf( "forced to software.  ok\n" );
	}
		
	// Make sure mixer is active
	if ( DS_OK != pDSBuf->Play(0, 0, DSBPLAY_LOOPING) ) {
		Com_Printf ("*** Looped sound play failed ***\n");
		SNDDMA_Shutdown ();
		return false;
	}

	// get the returned buffer size
	if ( DS_OK != pDSBuf->GetCaps (&dsbcaps) ) {
		Com_Printf ("*** GetCaps failed ***\n");
		SNDDMA_Shutdown ();
		return false;
	}
	
	gSndBufSize = dsbcaps.dwBufferBytes;

	dma.channels = format.nChannels;
	dma.samplebits = format.wBitsPerSample;
	dma.speed = format.nSamplesPerSec;
	dma.samples = gSndBufSize/(dma.samplebits/8);
	dma.submission_chunk = 1;
//.........这里部分代码省略.........
开发者ID:MilitaryForces,项目名称:MilitaryForces,代码行数:101,代码来源:win_snd.c

示例10: SNDDMA_InitDS


//.........这里部分代码省略.........
			return 0;
		}

		if ( pauseTried ) {
			Com_Printf ("failed, hardware already in use\n" );
			return 0;
		}
		// first try just waiting five seconds and trying again
		// this will handle the case of a sysyem beep playing when the
		// game starts
		Com_DPrintf ("retrying...\n");
		Sleep( 3000 );
		pauseTried = qtrue;
	}
	Com_DPrintf( "ok\n" );

	Com_DPrintf("...setting DSSCL_PRIORITY coop level: " );

	if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) )	{
		Com_Printf ("failed\n");
		SNDDMA_Shutdown ();
		return qfalse;
	}
	Com_DPrintf("ok\n" );


	// create the secondary buffer we'll actually work with
	dma.channels = 2;
	dma.samplebits = 16;

	if (s_khz->integer == 44)
		dma.speed = 44100;
	else if (s_khz->integer == 22)
		dma.speed = 22050;
	else
		dma.speed = 11025;

	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
    format.nChannels = dma.channels;
    format.wBitsPerSample = dma.samplebits;
    format.nSamplesPerSec = dma.speed;
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
    format.cbSize = 0;
    format.nAvgBytesPerSec = format.nSamplesPerSec*format.nBlockAlign; 

	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);

#define idDSBCAPS_GETCURRENTPOSITION2 0x00010000

	dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCHARDWARE | idDSBCAPS_GETCURRENTPOSITION2;
	dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
	dsbuf.lpwfxFormat = &format;
	
	Com_DPrintf( "...creating secondary buffer: " );
	if (DS_OK != pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL)) {
		dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY;
		hresult = pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL);
		if (hresult != DS_OK) {			
			Com_Printf( "failed to create secondary buffer - %s\n", DSoundError( hresult ) );
			SNDDMA_Shutdown ();
			return qfalse;
		}
	}
	Com_Printf( "locked hardware.  ok\n" );
		
	// Make sure mixer is active
	if ( DS_OK != pDSBuf->Play(0, 0, DSBPLAY_LOOPING) ) {
		Com_Printf ("*** Looped sound play failed ***\n");
		SNDDMA_Shutdown ();
		return qfalse;
	}

	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);
	// get the returned buffer size
	if ( DS_OK != pDSBuf->GetCaps (&dsbcaps) ) {
		Com_Printf ("*** GetCaps failed ***\n");
		SNDDMA_Shutdown ();
		return qfalse;
	}
	
	gSndBufSize = dsbcaps.dwBufferBytes;

	dma.channels = format.nChannels;
	dma.samplebits = format.wBitsPerSample;
	dma.speed = format.nSamplesPerSec;
	dma.samples = gSndBufSize/(dma.samplebits/8);
	dma.submission_chunk = 1;
	dma.buffer = NULL;			// must be locked first

	sample16 = (dma.samplebits/8) - 1;

	SNDDMA_BeginPainting ();
	if (dma.buffer)
		memset(dma.buffer, 0, dma.samples * dma.samplebits/8);
	SNDDMA_Submit ();
	return 1;
}
开发者ID:ctoliver,项目名称:JediKnight2,代码行数:101,代码来源:win_snd.cpp

示例11: DSoundInit

int DSoundInit(HWND wnd_coop, int rate, int stereo, int seg_samples)
{
  DSBUFFERDESC dsbd;
  WAVEFORMATEX wfx;
  DSBPOSITIONNOTIFY notifies[NSEGS];
  int i;

  memset(&dsbd,0,sizeof(dsbd));
  memset(&wfx,0,sizeof(wfx));

  // Make wave format:
  wfx.wFormatTag=WAVE_FORMAT_PCM;
  wfx.nChannels=stereo ? 2 : 1;
  wfx.nSamplesPerSec=rate;
  wfx.wBitsPerSample=16;

  wfx.nBlockAlign=(WORD)((wfx.nChannels*wfx.wBitsPerSample)>>3);
  wfx.nAvgBytesPerSec=wfx.nBlockAlign*wfx.nSamplesPerSec;

  // Create the DirectSound interface:
  DirectSoundCreate(NULL,&DSound,NULL);
  if (DSound==NULL) return 1;

  LoopSeg = seg_samples * 2;
  if (stereo)
    LoopSeg *= 2;

  LoopLen = LoopSeg * NSEGS;

  DSound->SetCooperativeLevel(wnd_coop, DSSCL_PRIORITY);
  dsbd.dwFlags=DSBCAPS_GLOBALFOCUS;  // Play in background
  dsbd.dwFlags|=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLPOSITIONNOTIFY;

  // Create the looping buffer:
  dsbd.dwSize=sizeof(dsbd);
  dsbd.dwBufferBytes=LoopLen;
  dsbd.lpwfxFormat=&wfx;

  DSound->CreateSoundBuffer(&dsbd,&LoopBuffer,NULL);
  if (LoopBuffer==NULL) return 1;

  LoopBuffer->QueryInterface(IID_IDirectSoundNotify, (LPVOID*)&DSoundNotify);
  if (DSoundNotify == NULL) {
    lprintf("QueryInterface(IID_IDirectSoundNotify) failed\n");
    goto out;
  }

  seg_played_event = CreateEvent(NULL, 0, 0, NULL);
  if (seg_played_event == NULL)
    goto out;

  for (i = 0; i < NSEGS; i++) {
    notifies[i].dwOffset = i * LoopSeg;
    notifies[i].hEventNotify = seg_played_event;
  }
  i = DSoundNotify->SetNotificationPositions(NSEGS, notifies);
  if (i != DS_OK) {
    lprintf("SetNotificationPositions failed\n");
    goto out;
  }

out:
  LoopBlank();
  LoopBuffer->Play(0, 0, DSBPLAY_LOOPING);
  return 0;
}
开发者ID:CatalystG,项目名称:libpicofe,代码行数:66,代码来源:dsnd.cpp

示例12: SelectSong

void SelectSong(void)
{
	DWORD count,i;
	static DWORD current;
	static DWORD SelectCurrent;
	static int Selected, zoom,toggle,speed;

	RECT	lRect;
	int ModeTemp1p, ModeTemp2p;
	
	static	time_t t;
	
	static	int a,b,c;

	static	int iMove;

	RECT DiscSize,Screen;

	char s[50];

	if(First==0)
	{
		startTimer=timeGetTime();
		if(Start1p==FALSE)
		{
			HighSpeed1p=1;
			bModeMirror1p=FALSE;
			bModeNonstep1p=FALSE;
			bModeSynchro=FALSE;
			bModeUnion1p=FALSE;
			bModeRandom1p=FALSE;
			b4dMix1p=FALSE;
				HighSpeed1p_1=1;
				HighSpeed1p_3=1;
				HighSpeed1p_5=1;
				HighSpeed1p_7=1;
				HighSpeed1p_9=1;
			bModeVanish1p=FALSE;
			bModeSuddenR1p=FALSE;
			bModeRandomS1p=FALSE;

		}
		if(Start2p==FALSE)
		{
			HighSpeed2p=1;
			bModeMirror2p=FALSE;
			bModeNonstep2p=FALSE;
			bModeUnion2p=FALSE;
			bModeRandom2p=FALSE;
			b4dMix2p=FALSE;
				HighSpeed2p_1=1;
				HighSpeed2p_3=1;
				HighSpeed2p_5=1;
				HighSpeed2p_7=1;
				HighSpeed2p_9=1;
			bModeVanish2p=FALSE;
			bModeSuddenR1p=FALSE;
			bModeRandomS1p=FALSE;
		}
		DDFillSurface(g_pDDSPrimary,0);
		DDFillSurface(g_pDDSBack,0);
		
		//FadeToSurface(SelectBack);
		g_pDDSBack->BltFast(0,0, SelectBack, NULL, DDBLTFAST_NOCOLORKEY);
		
		a=Start1p;b=Start2p;
		First++;

		if(g_dsSelectSong)g_dsSelectSong->Play(0,0,DSBPLAY_LOOPING);
	}

	DiscSize.top=0;
	DiscSize.left=0;
	DiscSize.right=300;
	DiscSize.bottom=200;

	for(count=0;;count++)
	{
		if(count!=0)CSONG[count].Prev=count-1;
		
		CSONG[count].Next=count+1;
		
		if(CSONG[count].bpm==0)
		{
			CSONG[count].Prev=0;
			count--;
			CSONG[count].Next=0;
			CSONG[0].Prev=count;
			break;
		}
	}

	if(speed==1) //일단은 변수를 이용합니다. 곧 타이머 형식으로 바꾸도록 합시다. 
	{
		speed=0;
		if(toggle==0)
		{
			if(zoom==10)toggle=1;
			else zoom++;
		}
//.........这里部分代码省略.........
开发者ID:Flameshadowxeroshin,项目名称:kick-it-up-source,代码行数:101,代码来源:Select.cpp

示例13: PlayBuffer

void PlayBuffer(int * Buffer)
{
    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) Buffer;

    dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
}
开发者ID:process,项目名称:Project-8,代码行数:6,代码来源:sound.cpp

示例14: SNDDMA_Init

bool SNDDMA_Init() {
	HRESULT hresult;
	DSBUFFERDESC dsbuf;
	DSBCAPS dsbcaps;
	WAVEFORMATEX format;
	bool use8;

	Com_Memset( ( void* )&dma, 0, sizeof ( dma ) );
	dsound_init = false;

	CoInitialize( NULL );

	common->Printf( "Initializing DirectSound\n" );

	use8 = 1;
	// Create IDirectSound using the primary sound device
	if ( FAILED( hresult = CoCreateInstance( CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound8, ( void** )&pDS ) ) ) {
		use8 = 0;
		if ( FAILED( hresult = CoCreateInstance( CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound, ( void** )&pDS ) ) ) {
			common->Printf( "failed\n" );
			SNDDMA_Shutdown();
			return false;
		}
	}

	hresult = pDS->Initialize( NULL );

	common->DPrintf( "ok\n" );

	common->DPrintf( "...setting DSSCL_PRIORITY coop level: " );

	if ( DS_OK != pDS->SetCooperativeLevel( GMainWindow, DSSCL_PRIORITY ) ) {
		common->Printf( "failed\n" );
		SNDDMA_Shutdown();
		return false;
	}
	common->DPrintf( "ok\n" );

	// create the secondary buffer we'll actually work with
	dma.channels = s_channels_cv->integer;
	dma.samplebits = s_bits->integer;

	if ( s_khz->integer == 44 ) {
		dma.speed = 44100;
	} else if ( s_khz->integer == 22 ) {
		dma.speed = 22050;
	} else {
		dma.speed = 11025;
	}

	Com_Memset( &format, 0, sizeof ( format ) );
	format.wFormatTag = WAVE_FORMAT_PCM;
	format.nChannels = dma.channels;
	format.wBitsPerSample = dma.samplebits;
	format.nSamplesPerSec = dma.speed;
	format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
	format.cbSize = 0;
	format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;

	Com_Memset( &dsbuf, 0, sizeof ( dsbuf ) );
	dsbuf.dwSize = sizeof ( DSBUFFERDESC );

	// Micah: take advantage of 2D hardware.if available.
	dsbuf.dwFlags = DSBCAPS_LOCHARDWARE;
	if ( use8 ) {
		dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2;
	}
	dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
	dsbuf.lpwfxFormat = &format;

	Com_Memset( &dsbcaps, 0, sizeof ( dsbcaps ) );
	dsbcaps.dwSize = sizeof ( dsbcaps );

	common->DPrintf( "...creating secondary buffer: " );
	if ( DS_OK == pDS->CreateSoundBuffer( &dsbuf, &pDSBuf, NULL ) ) {
		common->Printf( "locked hardware.  ok\n" );
	} else {
		// Couldn't get hardware, fallback to software.
		dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE;
		if ( use8 ) {
			dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2;
		}
		if ( DS_OK != pDS->CreateSoundBuffer( &dsbuf, &pDSBuf, NULL ) ) {
			common->Printf( "failed\n" );
			SNDDMA_Shutdown();
			return false;
		}
		common->DPrintf( "forced to software.  ok\n" );
	}

	// Make sure mixer is active
	if ( DS_OK != pDSBuf->Play( 0, 0, DSBPLAY_LOOPING ) ) {
		common->Printf( "*** Looped sound play failed ***\n" );
		SNDDMA_Shutdown();
		return false;
	}

	// get the returned buffer size
	if ( DS_OK != pDSBuf->GetCaps( &dsbcaps ) ) {
		common->Printf( "*** GetCaps failed ***\n" );
//.........这里部分代码省略.........
开发者ID:janisl,项目名称:jlquake,代码行数:101,代码来源:driver_directsound.cpp

示例15: SNDDXInit

int SNDDXInit(int buffersize)
{
	DSBUFFERDESC dsbdesc;
	WAVEFORMATEX wfx;
	HRESULT ret;
	char tempstr[512];

	if (FAILED(ret = DirectSoundCreate8(NULL, &lpDS8, NULL)))
	{
		sprintf(tempstr, "DirectSound8Create error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	if (FAILED(ret = lpDS8->SetCooperativeLevel(MainWindow->getHWnd(), DSSCL_PRIORITY)))
	{
		sprintf(tempstr, "IDirectSound8_SetCooperativeLevel error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	memset(&dsbdesc, 0, sizeof(dsbdesc));
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	dsbdesc.dwBufferBytes = 0;
	dsbdesc.lpwfxFormat = NULL;

	if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB, NULL)))
	{
		sprintf(tempstr, "Error when creating primary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	soundbufsize = buffersize * 2; // caller already multiplies buffersize by 2
	soundoffset = 0;

	memset(&wfx, 0, sizeof(wfx));
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = DESMUME_SAMPLE_RATE;
	wfx.wBitsPerSample = 16;
	wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

	if (FAILED(ret = lpDSB->SetFormat(&wfx)))
	{
		sprintf(tempstr, "IDirectSoundBuffer8_SetFormat error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	memset(&dsbdesc, 0, sizeof(dsbdesc));
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS |
		DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
		DSBCAPS_LOCHARDWARE;
	dsbdesc.dwBufferBytes = soundbufsize;
	dsbdesc.lpwfxFormat = &wfx;

	if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)))
	{
		if (ret == DSERR_CONTROLUNAVAIL ||
			ret == DSERR_INVALIDCALL ||
			ret == E_FAIL || 
			ret == E_NOTIMPL)
		{
			// Try using a software buffer instead
			dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS |
				DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
				DSBCAPS_LOCSOFTWARE;

			if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)))
			{
				sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
				MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
				return -1;
			}
		}
		else
		{
			sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
			MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
			return -1;
		}
	}

	lpDSB2->Play(0, 0, DSBPLAY_LOOPING);

	if ((stereodata16 = new s16[soundbufsize / sizeof(s16)]) == NULL)
		return -1;

	memset(stereodata16, 0, soundbufsize);

	soundvolume = DSBVOLUME_MAX;
	issoundmuted = 0;

	doterminate = false;
	terminated = false;
	CreateThread(0,0,SNDDXThread,0,0,0);
//.........这里部分代码省略.........
开发者ID:BlueSplash,项目名称:svn-desmume,代码行数:101,代码来源:snddx.cpp


注:本文中的LPDIRECTSOUNDBUFFER::Play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。