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


C++ IDirectSoundBuffer::Unlock方法代码示例

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


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

示例1: WriteDataToBuffer

bool DSoundAudioBackend::WriteDataToBuffer(DWORD offset, // Our own write cursor.
																		char* soundData, // Start of our data.
																		DWORD soundBytes) { // Size of block to copy.
	void *ptr1, *ptr2;
	DWORD numBytes1, numBytes2;
	// Obtain memory address of write block. This will be in two parts if the block wraps around.
	HRESULT hr = dsBuffer_->Lock(offset, soundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);

	// If the buffer was lost, restore and retry lock.
	/*
	if (DSERR_BUFFERLOST == hr) {
	dsBuffer->Restore();
	hr=dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);
	} */
	if (SUCCEEDED(hr)) { 
		memcpy(ptr1, soundData, numBytes1);
		if (ptr2)
			memcpy(ptr2, soundData+numBytes1, numBytes2);

		// Release the data back to DirectSound.
		dsBuffer_->Unlock(ptr1, numBytes1, ptr2, numBytes2);
		return true;
	}/* 
		else
		{
		char temp[8];
		sprintf(temp,"%i\n",hr);
		OutputDebugStringUTF8(temp);
		}*/
	return false;
}
开发者ID:chinhodado,项目名称:ppsspp,代码行数:31,代码来源:DSoundStream.cpp

示例2: sizeof

int		DSoundBuffer::CreateFragmentBuffer(void* pBuffer, int nLength)
{
	WAVEFORMATEX	WaveFormat;
	HRESULT hResult = m_pDirectSoundBuffer->GetFormat(&WaveFormat, sizeof(WAVEFORMATEX), NULL);
	if(FAILED(hResult)){ return 0; }

	DSBUFFERDESC	BufferDesc;
	ZeroMemory(&BufferDesc, sizeof(DSBUFFERDESC));
	BufferDesc.dwSize			= sizeof(DSBUFFERDESC);
	BufferDesc.dwFlags			= DSBCAPS_GLOBALFOCUS| DSBCAPS_CTRLVOLUME| DSBCAPS_CTRLFREQUENCY;
	BufferDesc.dwBufferBytes	= nLength;
	BufferDesc.dwReserved		= 0;
	BufferDesc.lpwfxFormat		= &WaveFormat;
	BufferDesc.guid3DAlgorithm	= GUID_NULL;

	IDirectSoundBuffer* pTempDirectSoundBuffer = NULL;
	hResult = m_pDevice->GetDirectSound()->CreateSoundBuffer(&BufferDesc, &pTempDirectSoundBuffer, NULL);
	if(FAILED(hResult)){ return 0; }

	void*	pTempBuffer = NULL;
	DWORD	nTempLength	= 0;
	hResult = pTempDirectSoundBuffer->Lock(0, nLength, &pTempBuffer, &nTempLength, NULL, NULL, 0);
	if(SUCCEEDED(hResult))
	{
		memcpy(pTempBuffer, pBuffer, nLength);
		pTempDirectSoundBuffer->Unlock(pTempBuffer, nTempLength, NULL, 0);
	}

	//
	m_FragmentBuffers[++m_nFragmentIndex] = pTempDirectSoundBuffer;
	return m_nFragmentIndex;
}
开发者ID:thewayup,项目名称:MusicPlayer,代码行数:32,代码来源:DSoundDevice.cpp

示例3: RunThread

int DSoundAudioBackend::RunThread() {
	if (FAILED(DirectSoundCreate8(0, &ds_, 0))) {
		ds_ = NULL;
		threadData_ = 2;
		return 1;
	}

	ds_->SetCooperativeLevel(window_, DSSCL_PRIORITY);
	if (!CreateBuffer()) {
		ds_->Release();
		ds_ = NULL;
		threadData_ = 2;
		return 1;
	}

	soundSyncEvent_ = CreateEvent(0, false, false, 0);
	InitializeCriticalSection(&soundCriticalSection);

	DWORD num1;
	short *p1;

	dsBuffer_->Lock(0, bufferSize_, (void **)&p1, &num1, 0, 0, 0);

	memset(p1, 0, num1);
	dsBuffer_->Unlock(p1, num1, 0, 0);
	totalRenderedBytes_ = -bufferSize_;

	setCurrentThreadName("DSound");
	currentPos_ = 0;
	lastPos_ = 0;

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

	while (!threadData_) {
		EnterCriticalSection(&soundCriticalSection);

		dsBuffer_->GetCurrentPosition((DWORD *)&currentPos_, 0);
		int numBytesToRender = RoundDown128(ModBufferSize(currentPos_ - lastPos_)); 

		if (numBytesToRender >= 256) {
			int numBytesRendered = 4 * (*callback_)(realtimeBuffer_, numBytesToRender >> 2, 16, 44100, 2);
			//We need to copy the full buffer, regardless of what the mixer claims to have filled
			//If we don't do this then the sound will loop if the sound stops and the mixer writes only zeroes
			numBytesRendered = numBytesToRender;
			WriteDataToBuffer(lastPos_, (char *) realtimeBuffer_, numBytesRendered);

			currentPos_ = ModBufferSize(lastPos_ + numBytesRendered);
			totalRenderedBytes_ += numBytesRendered;

			lastPos_ = currentPos_;
		}

		LeaveCriticalSection(&soundCriticalSection);
		WaitForSingleObject(soundSyncEvent_, MAXWAIT);
	}
开发者ID:njh08d,项目名称:ppsspp,代码行数:55,代码来源:DSoundStream.cpp

示例4: Stream

void DirectSoundStreamer::Stream( void const *pSamples )
{
    // Verify buffer availability
    DWORD play, write;
    if( FAILED( m_pDirectSoundBuffer->GetCurrentPosition( &play, &write ) ) )
        return;
    if( write < play )
        write += DWORD( m_physical );
    std::size_t begin( m_begin );
    if( begin < play )
        begin += m_physical;
    if( begin < write )
        begin = std::size_t( write );
    std::size_t end( begin + m_stream );
    if( play + m_virtual < end )
        return;
    begin %= m_physical;

    // Copy samples to buffer
    void *ps[ 2 ];
    DWORD sizes[ 2 ];
    HRESULT hResult( m_pDirectSoundBuffer->Lock( DWORD( begin ), DWORD( m_stream ), &ps[ 0 ], &sizes[ 0 ], &ps[ 1 ], &sizes[ 1 ], 0 ) );
    if( FAILED( hResult ) )
    {
        if( hResult != DSERR_BUFFERLOST )
            return;
        m_pDirectSoundBuffer->Restore();
        if( FAILED( m_pDirectSoundBuffer->Lock( DWORD( begin ), DWORD( m_stream ), &ps[ 0 ], &sizes[ 0 ], &ps[ 1 ], &sizes[ 1 ], 0 ) ) )
            return;
    }
    using std::memcpy;
    memcpy( ps[ 0 ], pSamples, std::size_t( sizes[ 0 ] ) );
    if( ps[ 1 ] )
        memcpy( ps[ 1 ], static_cast< char const * >( pSamples ) + sizes[ 0 ], std::size_t( sizes[ 1 ] ) );
    m_pDirectSoundBuffer->Unlock( ps[ 0 ], sizes[ 0 ], ps[ 1 ], sizes[ 1 ] );

    // Select next buffer
    m_begin = end % m_physical;
}
开发者ID:fesh0r,项目名称:beebem,代码行数:39,代码来源:beebsound.cpp

示例5: GetSampleSize

  OutputStream*
  DSAudioDevice::openBuffer(
    void* samples, int frame_count,
    int channel_count, int sample_rate, SampleFormat sample_format)
  {
    ADR_GUARD("DSAudioDevice::openBuffer");

    const int frame_size = channel_count * GetSampleSize(sample_format);

    WAVEFORMATEX wfx;
    memset(&wfx, 0, sizeof(wfx));
    wfx.wFormatTag      = WAVE_FORMAT_PCM;
    wfx.nChannels       = channel_count;
    wfx.nSamplesPerSec  = sample_rate;
    wfx.nAvgBytesPerSec = sample_rate * frame_size;
    wfx.nBlockAlign     = frame_size;
    wfx.wBitsPerSample  = GetSampleSize(sample_format) * 8;
    wfx.cbSize          = sizeof(wfx);

    DSBUFFERDESC dsbd;
    memset(&dsbd, 0, sizeof(dsbd));
    dsbd.dwSize  = sizeof(dsbd);
    dsbd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPAN |
                   DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY |
                   DSBCAPS_STATIC | DSBCAPS_CTRLPOSITIONNOTIFY;
    if (m_global_focus) {
      dsbd.dwFlags |= DSBCAPS_GLOBALFOCUS;
    }

    const int buffer_frame_count = std::max(m_min_buffer_length, frame_count);
    const int buffer_size = buffer_frame_count * frame_size;
    dsbd.dwBufferBytes = buffer_size;
    dsbd.lpwfxFormat   = &wfx;

    // create the DS buffer
    IDirectSoundBuffer* buffer;
    HRESULT result = m_direct_sound->CreateSoundBuffer(
      &dsbd, &buffer, NULL);
    if (FAILED(result) || !buffer) {
      return 0;
    }

    ADR_IF_DEBUG {
      DSBCAPS caps;
      caps.dwSize = sizeof(caps);
      result = buffer->GetCaps(&caps);
      if (FAILED(result)) {
        buffer->Release();
        return 0;
      } else {
        std::ostringstream ss;
        ss << "actual buffer size: " << caps.dwBufferBytes << std::endl
           << "buffer_size: " << buffer_size;
        ADR_LOG(ss.str().c_str());
      }
    }

    void* data;
    DWORD data_size;
    result = buffer->Lock(0, buffer_size, &data, &data_size, 0, 0, 0);
    if (FAILED(result)) {
      buffer->Release();
      return 0;
    }

    ADR_IF_DEBUG {
      std::ostringstream ss;
      ss << "buffer size: " << buffer_size << std::endl
         << "data size:   " << data_size << std::endl
         << "frame count: " << frame_count;
      ADR_LOG(ss.str().c_str());
    }

    const int actual_size = frame_count * frame_size;
    memcpy(data, samples, actual_size);
    memset((u8*)data + actual_size, 0, buffer_size - actual_size);

    buffer->Unlock(data, data_size, 0, 0);

    DSOutputBuffer* b = new DSOutputBuffer(
      this, buffer, buffer_frame_count, frame_size);
    SYNCHRONIZED(this);
    m_open_buffers.push_back(b);
    return b;
  }
开发者ID:Bananattack,项目名称:audiere,代码行数:85,代码来源:device_ds.cpp

示例6: WinMain


//.........这里部分代码省略.........
	whdr.lpData = new char[pcmWaveFormat.nAvgBytesPerSec * 10];	//ilosc bajtwo na sekunde
	whdr.dwBufferLength = pcmWaveFormat.nAvgBytesPerSec * 10;	//razy ilosc sekund
	whdr.dwUser = 0;
	whdr.dwFlags = 0;
	whdr.dwLoops = 0;
	whdr.dwBytesRecorded = 0;
	whdr.lpNext = nullptr;

	//wypelnienei buffora probek probkami sygnalu ao czestoliwosci 880hz
	for (int i = 0; i < whdr.dwBufferLength; i++)
	{
		whdr.lpData[i] = 128 * sin(i*80.0 / static_cast<double>(pcmWaveFormat.nSamplesPerSec)) + 128;
	}
	/*
	waveOutSetVolume(hwo, 0xFFFFFFFF);
	mmResult = waveOutPrepareHeader(hwo, &whdr, sizeof(WAVEHDR));	//wyslanie naglowska
	if (mmResult != MMSYSERR_NOERROR)									//przygotowanie urzadzenia
	{
		MessageBox(hWnd, TEXT("nie mozna zainisjowac karty"), TEXT("ERROR"), MB_OK);
		return mmResult;
	}
	mmResult = waveOutWrite(hwo, &whdr, sizeof(WAVEHDR));	//wyslanie probek do urzadzenia
	if (mmResult != MMSYSERR_NOERROR)
	{
		MessageBox(hWnd, TEXT("nie idzie zaladowac probek"), TEXT("error"), MB_OK);
		return mmResult;
	}
	while ((whdr.dwFlags&WHDR_DONE) != WHDR_DONE)Sleep(100);//czekanie na koniec
	//zamkniecie urzadzenia
	mmResult = waveOutUnprepareHeader(hwo, &whdr, sizeof(WAVEHDR));
	mmResult = waveOutClose(hwo);
	*/
	IDirectSoundBuffer *DSB;
	DSBUFFERDESC DSBD;
	memset(&DSBD, 0, sizeof(DSBUFFERDESC));
	DSBD.dwSize = sizeof(DSBD);
	DSBD.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
	DSBD.dwBufferBytes = whdr.dwBufferLength;
	DSBD.lpwfxFormat = &pcmWaveFormat;
	if (DS8->CreateSoundBuffer(&DSBD, &DSB, nullptr) != DS_OK)
	{
		MessageBox(nullptr, TEXT("nie mozna utworzy direktosoundbuffer"), TEXT("ERROR"), MB_OK);
	};
	DSB->SetVolume(0xFFF0);//ustawienie glosnosci
	void *ptr1, *ptr2;
	DWORD l1, l2;
	DSB->Lock(0, whdr.dwBufferLength, &ptr1, &l1, &ptr2, &l2, DSBLOCK_ENTIREBUFFER);
	if (ptr1)memcpy(ptr1, whdr.lpData, l1);
	if (ptr2)memcpy(ptr2, whdr.lpData + l1, l2);

	DSB->Unlock(ptr1, l1, ptr2, l2);
	//DSB->Play(0, 0, 0);
	
	

delete[]whdr.lpData;//usuniecie bufora z pamieci


	//---------------------------------------------------------------------------------------


	if (!InitGL())									// Initialize Our Newly Created GL Window
	{
									// Reset The Display
		MessageBox(nullptr, "Initialization Failed.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}
	BOOL done = false;
	
	SetTimer(hWnd, ID_TIMER_REDRAW, 16, nullptr);
	SetTimer(hWnd, ID_TIMER_REDRAW2, 8, nullptr);
	MSG msg;
	
	while (!done)
	{
		
		if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))//czy jest zdarzenie do obslugi?
		{
			if (msg.message == WM_QUIT) done = TRUE;
			else
			{
				
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				
			}
		}
		
	}
	
	if (hRC)
	{
		wglMakeCurrent(nullptr, nullptr);//usuw. kontekstu rend.
		wglDeleteContext(hRC);//usuw. kontekstu rend.
	}
	if (hDC && !ReleaseDC(hWnd, hDC)) {}//wyzerowanie kontekstu
	if (hWnd&& !DestroyWindow(hWnd)){}//wyzerowanie uchwytu okienka

	return 0;
}
开发者ID:manixq,项目名称:Monster-Race,代码行数:101,代码来源:monster_race.cpp

示例7: sizeof

IDirectSoundBuffer *SoundLibrary3dDirectSound::CreateSecondaryBuffer(int _numSamples)
{
	int errCode;
	IDirectSoundBuffer *buffer = NULL;

	WAVEFORMATEX wfx;
	ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); 
	wfx.wFormatTag      = (WORD) WAVE_FORMAT_PCM; 
	wfx.nChannels       = 1; 
	wfx.nSamplesPerSec  = m_sampleRate; // was _mixFreq;
	wfx.wBitsPerSample  = 16; 
	wfx.nBlockAlign     = (WORD) (wfx.wBitsPerSample / 8 * wfx.nChannels);
	wfx.nAvgBytesPerSec = (DWORD) (wfx.nSamplesPerSec * wfx.nBlockAlign);
    
    int flags = DSBCAPS_CTRL3D | 
                DSBCAPS_CTRLFX |
                DSBCAPS_CTRLFREQUENCY | 
                DSBCAPS_CTRLVOLUME |
                DSBCAPS_GETCURRENTPOSITION2;

    if( Hardware3DSupport() && m_hw3dDesired )   flags |= DSBCAPS_LOCHARDWARE;
    else                                         flags |= DSBCAPS_LOCSOFTWARE;
                
	DSBUFFERDESC dsbd;
	ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
	dsbd.dwSize        = sizeof(DSBUFFERDESC);
	dsbd.dwFlags       = flags;
	dsbd.dwBufferBytes = _numSamples * 2;
	dsbd.lpwfxFormat   = &wfx;
    dsbd.guid3DAlgorithm = DS3DALG_DEFAULT;

	errCode = m_directSound->m_device->CreateSoundBuffer(&dsbd, &buffer, NULL);

	//
	// Used to be SOUNDASSERT, early return if fails

	SOUNDDEBUG( errCode, "Direct sound couldn't create a secondary buffer, numSamples(%d)", _numSamples );
	if( errCode != DS_OK )
	{
		return NULL;
	}

    // Fill the buffer with zeros to start with
	void *buf1;
	unsigned long buf1Size;
	errCode = buffer->Lock(0,	        // Offset
						   0,	        // Size (ignored because using DSBLOCK_ENTIREBUFFER)
							&buf1,
							&buf1Size,
							NULL,
							NULL,
							DSBLOCK_ENTIREBUFFER);
    SOUNDASSERT( errCode, "Direct Sound couldn't lock buffer" );
    memset( buf1, 0, buf1Size );        
	buffer->Unlock(buf1, buf1Size, NULL, 0);

	// Start the stream playing
	errCode = buffer->Play( 0, 0, DSBPLAY_LOOPING );
	SOUNDASSERT(errCode, "Direct sound couldn't start playing a stream" );

	return buffer;
}
开发者ID:gene9,项目名称:Darwinia-and-Multiwinia-Source-Code,代码行数:62,代码来源:sound_library_3d_dsound.cpp

示例8: sound_add_from_buffer

int sound_add_from_buffer(int id, void* buffer, size_t bufsize) {
  SoundResource* snd = new SoundResource();
  if (size_t(id) >= sound_resources.size()) {
    sound_resources.resize(size_t(id) + 1);
  }
  sound_resources[id] = snd;

  WaveHeaderType* waveHeader = buffer_get_wave_header((char*)buffer, bufsize);
  WAVEFORMATEX waveFormat = {};
  waveFormat.wFormatTag = waveHeader->audioFormat;
  waveFormat.nSamplesPerSec = waveHeader->sampleRate;
  waveFormat.wBitsPerSample = waveHeader->bitsPerSample;
  waveFormat.nChannels = waveHeader->numChannels;
  waveFormat.nBlockAlign = waveHeader->blockAlign;
  waveFormat.nAvgBytesPerSec = waveHeader->bytesPerSecond;
  waveFormat.cbSize = waveHeader->parSize;

  DSBUFFERDESC bufferDesc = {};
  bufferDesc.dwSize = sizeof(DSBUFFERDESC);
  // DSBCAPS_CTRLFX causes all kinds of weird nasty shit, please read #1508 on GitHub
  // before considering whether to readd it to the dwFlags below
  bufferDesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
  bufferDesc.dwBufferBytes = waveHeader->dataSize;
  bufferDesc.dwReserved = 0;
  bufferDesc.lpwfxFormat = &waveFormat;
  bufferDesc.guid3DAlgorithm = GUID_NULL;
  dsound->CreateSoundBuffer(&bufferDesc, &snd->soundBuffer, NULL);

  LPVOID lpvWrite;
  DWORD dwLength;

  IDirectSoundBuffer* sndBuf = snd->soundBuffer;

  if (DS_OK == sndBuf->Lock(0,                     // Offset at which to start lock.
                            waveHeader->dataSize,  // Size of lock; ignored because of flag.
                            &lpvWrite,             // Gets address of first part of lock.
                            &dwLength,             // Gets size of first part of lock.
                            NULL,                  // Address of wraparound not needed.
                            NULL,                  // Size of wraparound not needed.
                            0))                    // Flag.
  {
    memcpy(lpvWrite, (char*)buffer + waveHeader->dataOffset, waveHeader->dataSize);
    sndBuf->Unlock(lpvWrite,  // Address of lock start.
                   dwLength,  // Size of lock.
                   NULL,      // No wraparound portion.
                   0);        // No wraparound size.
  } else {
    //ErrorHandler();  // Add error-handling here.
  }

  float channels = waveHeader->numChannels,
        freq = waveHeader->sampleRate,
        bits = waveHeader->bitsPerSample,
        size = waveHeader->dataSize;

  snd->length = size / channels / (bits / 8) / freq;

  delete waveHeader;

  snd->soundBuffer->SetCurrentPosition(0);
  // Set volume of the buffer to 100%.
  snd->soundBuffer->SetVolume(0);
  snd->loaded = LOADSTATE_COMPLETE;

  return 0;
}
开发者ID:enigma-dev,项目名称:enigma-dev,代码行数:66,代码来源:DSsystem.cpp


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