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


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

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


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

示例1: DSoundUpdate

int DSoundUpdate(const void *buff, int blocking)
{
  DWORD play = 0;
  int pos;

  LoopBuffer->GetCurrentPosition(&play, NULL);
  pos = play;

  // 'LoopWrite' is the next seg in the loop that we want to write
  // First check that the sound 'play' pointer has moved out of it:
  if (blocking) {
    while (LoopWrite <= pos && pos < LoopWrite + LoopSeg) {
      WaitForSingleObject(seg_played_event, 5000);
      LoopBuffer->GetCurrentPosition(&play, NULL);
      pos = play;
    }
  }
  else {
    if (LoopWrite <= pos && pos < LoopWrite + LoopSeg)
      return 1;
  }

  WriteSeg(buff);

  // Advance LoopWrite to next seg:
  LoopWrite += LoopSeg;
  if (LoopWrite + LoopSeg > LoopLen)
    LoopWrite = 0;

  return 0;
}
开发者ID:alban-rochel,项目名称:pixbox-pcsx-rearmed,代码行数:31,代码来源:dsnd.cpp

示例2: GetMaxWriteSize

// GetMaxWriteSize
//
// Helper function to calculate max size of sound buffer write operation, i.e. how much
// free space there is in buffer.
DWORD AudioStream::GetMaxWriteSize (void)
{
	DWORD dwWriteCursor, dwPlayCursor, dwMaxSize;

	// Get current play position
	if (m_pdsb->GetCurrentPosition (&dwPlayCursor, &dwWriteCursor) == DS_OK) {
		if (m_cbBufOffset <= dwPlayCursor) {
			// Our write position trails play cursor
			dwMaxSize = dwPlayCursor - m_cbBufOffset;
		}

		else  {// (m_cbBufOffset > dw7Cursor)
			// Play cursor has wrapped
			dwMaxSize = m_cbBufSize - m_cbBufOffset + dwPlayCursor;
		}
	}
	else {
		// GetCurrentPosition call failed
		Int3();
		dwMaxSize = 0;
	}

//	nprintf(("Alan","Max write size: %d\n", dwMaxSize));
	return (dwMaxSize);
}
开发者ID:NonCreature0714,项目名称:freespace2,代码行数:29,代码来源:AudioStr.cpp

示例3: SNDDMA_GetDMAPos

/*
==============
SNDDMA_GetDMAPos

return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos(void)
{
	MMTIME	mmtime;
	int		s = 0;
	DWORD	dwWrite;

	if (dsound_init) 
	{
		mmtime.wType = TIME_SAMPLES;
		//if (!s_primary->value)
#ifdef QDSNDCOMPILERHACK
			pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &mmtime.u.sample, &dwWrite);
#else
			pDSBuf->GetCurrentPosition(&mmtime.u.sample, &dwWrite);
#endif
		//else
		//	pDSPBuf->lpVtbl->GetCurrentPosition(pDSPBuf, &mmtime.u.sample, &dwWrite);
		s = mmtime.u.sample - mmstarttime.u.sample;
	}
	else if (wav_init)
	{
		s = snd_sent * WAV_BUFFER_SIZE;
	}


	s >>= sample16;

	s &= (dma.samples-1);

	return s;
}
开发者ID:Jaegermeiste,项目名称:quake2_322,代码行数:40,代码来源:snd_win.c

示例4: VGetProgress

//  *******************************************************************************************************************
float cDirectSoundAudioBuffer::VGetProgress()
{
  LPDIRECTSOUNDBUFFER pDSBuffer = GetSoundBuffer();
  if (pDSBuffer == NULL)
  {
    return 0.0f;
  }
  unsigned long progress = 0;
  pDSBuffer->GetCurrentPosition(&progress, NULL);
  float length = static_cast<float>(m_pResource->VGetPCMBufferSize());
  return (progress / length);
}
开发者ID:AnkurSheel,项目名称:HHero,代码行数:13,代码来源:DirectSoundAudioBuffer.cpp

示例5: StreamPoll

/*------------------------------------------------------------------------
*
* PROTOTYPE  :  int StreamPoll(void)
*
* DESCRIPTION : Poller to the stream. If return -1, StreamLoad must be called.
*
*/
int StreamPoll(V3XA_STREAM handle)
{
    DS_stream *pHandle = g_pDSStreams + handle;
    DWORD lPlay=0;
	DWORD lWrite=0;
    int ret=-1;
    LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[pHandle->channel].pbuffer;
    if (!pDS)
		return ret;

    if ((pHandle->nState&1)==0)
		return -1;

    if (pHandle->m_nStreamState)
	{
		ret = 1;
	}
    else
    {
		// Polled streaming
		int32_t elapsed;
		ULONG lpStatus;

		if (pDS->GetStatus(&lpStatus)==DS_OK)
		{
			if ((lpStatus & DSBSTATUS_PLAYING)==0)
			{
				SYS_DXTRACE(pDS->Play(0, 0, DSBPLAY_LOOPING));
			}
		}

		SYS_DXTRACE(pDS->GetCurrentPosition(&lWrite, &lPlay));

		elapsed = (pHandle->m_nPreviousPosition<=(int32_t)lPlay)
				? lPlay - pHandle->m_nPreviousPosition
				: (lPlay + (int32_t)pHandle->sample.length) - pHandle->m_nPreviousPosition;

		pHandle->m_nWriteBytes+=elapsed;
		pHandle->m_nTotalBytes+=elapsed;
		pHandle->m_nPreviousPosition = lPlay;

		if ((pHandle->m_nWriteBytes+elapsed>=pHandle->m_nUploadedBytes)
			&&(pHandle->m_nUploadedBytes))
		{
			pHandle->m_nWriteBytes-=pHandle->m_nUploadedBytes;
			pHandle->m_nUploadedBytes = 0;
			ret = 1;
		}
    }
    return ret;
}
开发者ID:cbxbiker61,项目名称:nogravity,代码行数:58,代码来源:snd_ds6.cpp

示例6: SNDDXGetAudioSpace

u32 SNDDXGetAudioSpace()
{
	DWORD playcursor, writecursor;
	if(FAILED(lpDSB2->GetCurrentPosition(&playcursor, &writecursor)))
		return 0;

	u32 curToWrite = circularDist(soundoffset, writecursor, soundbufsize);
	u32 curToPlay = circularDist(soundoffset, playcursor, soundbufsize);

	if(curToWrite < curToPlay)
		return 0; // in-between the two cursors. we shouldn't write anything during this time.

	return curToPlay / (sizeof(s16) * 2);
}
开发者ID:BlueSplash,项目名称:svn-desmume,代码行数:14,代码来源:snddx.cpp

示例7: return

    // ////////////////////////////////////////////////////////////////////
    //
    // ////////////////////////////////////////////////////////////////////
    F32 DirectSound8AudioBuffer::VGetProgress()
    {
        LPDIRECTSOUNDBUFFER pDSB = static_cast<LPDIRECTSOUNDBUFFER>(VGet());
        if(!pDSB) {
            GF_LOG_TRACE_ERR("DirectSound8AudioBuffer::VGetProgress()", "Failed to cast the buffer to a DirectSound buffer");
            return (false);
        }
        DWORD progress = 0;

        pDSB->GetCurrentPosition(&progress, NULL);
        F32 length = static_cast<F32>(m_Resource->GetPCMBufferSize());

        return (static_cast<F32>(progress) / length);
    }
开发者ID:pjohalloran,项目名称:gameframework,代码行数:17,代码来源:DirectSoundAudio.cpp

示例8: SNDDMA_GetDMAPos

/*
==============
SNDDMA_GetDMAPos

return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos( void ) {
	DWORD	dwRead, dwWrite;

	if ( !dsound_init ) {
		return 0;
	}

	pDSBuf->GetCurrentPosition(&dwRead, &dwWrite);


	dwRead >>= sample16;

	dwRead &= (dma.samples-1);

	return dwRead;
}
开发者ID:deathsythe47,项目名称:jaMME,代码行数:25,代码来源:win_snd.cpp

示例9: SNDDMA_GetDMAPos

/*
==============
SNDDMA_GetDMAPos

return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos( void ) {
	MMTIME	mmtime;
	int		s;
	DWORD	dwWrite;

	mmtime.wType = TIME_SAMPLES;
	pDSBuf->GetCurrentPosition( &mmtime.u.sample, &dwWrite );

	s = mmtime.u.sample;

	s >>= sample16;

	s &= (dma.samples-1);

	return s;
}
开发者ID:ShaneIsley,项目名称:challengeq3,代码行数:25,代码来源:win_snd.cpp

示例10: WriteBuffer

void WriteBuffer(int * DestBuf, short * SrcBuf, int datalen)
{
    void * writePtr1;
    void * writePtr2;
    unsigned long length1;
    unsigned long length2;

    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) DestBuf;

    unsigned long WriteCur;

    dsBuffer->GetCurrentPosition(NULL, &WriteCur);

    dsBuffer->Lock(WriteCur, datalen, &writePtr1, &length1, &writePtr2, &length2, 0);
    memcpy(writePtr1, SrcBuf, length1);
    memcpy(writePtr2, SrcBuf + length1, length2);
    dsBuffer->Unlock(writePtr1, length1, writePtr2, length2);

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

示例11: soundmng_sync

void soundmng_sync(void) {

	DWORD	pos;
	DWORD	wpos;

	if (pDSData3 != NULL) {
		if (pDSData3->GetCurrentPosition(&pos, &wpos) == DS_OK) {
			if (pos >= dsstreambytes) {
				if (dsstreamevent != 0) {
					dsstreamevent = 0;
					streamwrite(0);
				}
			}
			else {
				if (dsstreamevent != 1) {
					dsstreamevent = 1;
					streamwrite(dsstreambytes);
				}
			}
		}
	}
}
开发者ID:josejl1987,项目名称:neko-tracer,代码行数:22,代码来源:soundmng.cpp

示例12: 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

示例13: DS_CreateBuffers


//.........这里部分代码省略.........
			Com_Printf( "ok\n" );
			Com_Printf( "Sound Buffer in Hardware\n" );
			}
		}

		dma.channels = format.nChannels;
		dma.samplebits = format.wBitsPerSample;
		dma.speed = format.nSamplesPerSec;

#ifdef QDSNDCOMPILERHACK
		if (DS_OK != pDSBuf->lpVtbl->GetCaps (pDSBuf, &dsbcaps))
#else
		if (DS_OK != pDSBuf->GetCaps (&dsbcaps))
#endif
		{
			Com_Printf ("*** GetCaps failed ***\n");
			FreeSound ();
			return 0;
		}

		Com_Printf ("...using secondary sound buffer\n");
	}
	else
	{
		Com_Printf( "...using primary buffer\n" );

		Com_Printf( "...setting WRITEPRIMARY coop level: " );
#ifdef QDSNDCOMPILERHACK
		if (DS_OK != pDS->lpVtbl->SetCooperativeLevel (pDS, cl_hwnd, DSSCL_WRITEPRIMARY))
#else
		if (DS_OK != pDS->SetCooperativeLevel (cl_hwnd, DSSCL_WRITEPRIMARY))
#endif
		{
			Com_Printf( "failed\n" );
			FreeSound ();
			return 0;
		}
		Com_Printf( "ok\n" );

#ifdef QDSNDCOMPILERHACK
		if (DS_OK != pDSPBuf->lpVtbl->GetCaps (pDSPBuf, &dsbcaps))
#else
		if (DS_OK != pDSPBuf->GetCaps (&dsbcaps))
#endif
		{
			Com_Printf ("*** GetCaps failed ***\n");
			return 0;
		}

		pDSBuf = pDSPBuf;
	}

	// Make sure mixer is active
	//if ( !s_primary->value)
#ifdef QDSNDCOMPILERHACK
		pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
#else
	pDSBuf->Play (0, 0, DSBPLAY_LOOPING);
#endif
	//else
	//	pDSPBuf->lpVtbl->Play(pDSPBuf, 0, 0, DSBPLAY_LOOPING);
	
	if (snd_firsttime)
		Com_Printf("   %d channel(s)\n"
		               "   %d bits/sample\n"
					   "   %d bytes/sec\n",
					   dma.channels, dma.samplebits, dma.speed);
	
	gSndBufSize = dsbcaps.dwBufferBytes;

	/* we don't want anyone to access the buffer directly w/o locking it first. */
	lpData = NULL; 

	//if ( !s_primary->value)
	//{
#ifdef QDSNDCOMPILERHACK
		pDSBuf->lpVtbl->Stop(pDSBuf);
		pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &mmstarttime.u.sample, &dwWrite);
		pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
#else
		pDSBuf->Stop();
		pDSBuf->GetCurrentPosition(&mmstarttime.u.sample, &dwWrite);
		pDSBuf->Play(0, 0, DSBPLAY_LOOPING);
#endif
	//}
	//else
	//{
	//	pDSPBuf->lpVtbl->Stop(pDSPBuf);
	//	pDSPBuf->lpVtbl->GetCurrentPosition(pDSPBuf, &mmstarttime.u.sample, &dwWrite);
	//	pDSPBuf->lpVtbl->Play(pDSPBuf, 0, 0, DSBPLAY_LOOPING);
	//}
	
	dma.samples = gSndBufSize/(dma.samplebits/8);
	dma.samplepos = 0;
	dma.submission_chunk = 1;
	dma.buffer = (unsigned char *) lpData;
	sample16 = (dma.samplebits/8) - 1;

	return 1;
}
开发者ID:Jaegermeiste,项目名称:quake2_322,代码行数:101,代码来源:snd_win.c

示例14: 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

示例15: write

void DirectSound::write()
{
  int len = soundBufferLen;
  LPVOID  lpvPtr1; 
  DWORD   dwBytes1; 
  LPVOID  lpvPtr2; 
  DWORD   dwBytes2; 

  if(!pDirectSound)
    return;

  if(theApp.soundRecording) {
    if(dsbSecondary) {
      if(theApp.soundRecorder == NULL) {
        theApp.soundRecorder = new WavWriter;
        WAVEFORMATEX format;
        dsbSecondary->GetFormat(&format, sizeof(format), NULL);
        if(theApp.soundRecorder->Open(theApp.soundRecordName))
          theApp.soundRecorder->SetFormat(&format);
      }
    }
      
    if(theApp.soundRecorder) {
      theApp.soundRecorder->AddSound((u8 *)soundFinalWave, len);
    }
  }

  if(theApp.aviRecording) {
    if(theApp.aviRecorder) {
      if(dsbSecondary) {
        if(!theApp.aviRecorder->IsSoundAdded()) {
          WAVEFORMATEX format;
          dsbSecondary->GetFormat(&format, sizeof(format), NULL);
          theApp.aviRecorder->SetSoundFormat(&format);
        }
      }
      
      theApp.aviRecorder->AddSound((const char *)soundFinalWave, len);
    }
  }
  
  HRESULT hr;

  if(!speedup && synchronize && !theApp.throttle) {
    DWORD status=0;
    hr = dsbSecondary->GetStatus(&status);
    if(status && DSBSTATUS_PLAYING) {
      if(!soundPaused) {      
        DWORD play;
        while(true) {
          dsbSecondary->GetCurrentPosition(&play, NULL);

          if(play < soundNextPosition ||
             play > soundNextPosition+soundBufferLen) {
            break;
          }

          if(dsbEvent) {
            WaitForSingleObject(dsbEvent, 50);
          }
        }
      }
    } else {
      soundPaused = 1;
    }
  }
  // Obtain memory address of write block. This will be in two parts
  // if the block wraps around.
  hr = dsbSecondary->Lock(soundNextPosition, soundBufferLen, &lpvPtr1, 
                          &dwBytes1, &lpvPtr2, &dwBytes2,
                          0);
  
  // If DSERR_BUFFERLOST is returned, restore and retry lock. 
  if (DSERR_BUFFERLOST == hr) { 
    dsbSecondary->Restore(); 
    hr = dsbSecondary->Lock(soundNextPosition, soundBufferLen,&lpvPtr1,
                            &dwBytes1, &lpvPtr2, &dwBytes2,
                            0);
  } 

  soundNextPosition += soundBufferLen;
  soundNextPosition = soundNextPosition % soundBufferTotalLen;
  
  if SUCCEEDED(hr) { 
    // Write to pointers. 
    CopyMemory(lpvPtr1, soundFinalWave, dwBytes1); 
    if (NULL != lpvPtr2) { 
      CopyMemory(lpvPtr2, soundFinalWave+dwBytes1, dwBytes2); 
    } 
    // Release the data back to DirectSound. 
    hr = dsbSecondary->Unlock(lpvPtr1, dwBytes1, lpvPtr2, 
                              dwBytes2);
  }
}
开发者ID:BackupTheBerlios,项目名称:vbastep-svn,代码行数:94,代码来源:DirectSound.cpp


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