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


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

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


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

示例1: DXTRACE_ERR

//-----------------------------------------------------------------------------
// Name: CSoundManager::Get3DListenerInterface()
// Desc: Returns the 3D listener interface associated with primary buffer.
//-----------------------------------------------------------------------------
HRESULT CSoundManager::Get3DListenerInterface( IDirectSound3DListener** ppDSListener )
{
	HRESULT             hr;
	DSBUFFERDESC        dsbdesc;
	IDirectSoundBuffer* pDSBPrimary = NULL;

	if( ppDSListener == NULL )
		return E_INVALIDARG;
	if( m_pDS == NULL )
		return CO_E_NOTINITIALIZED;

	*ppDSListener = NULL;

	// Obtain primary buffer, asking it for 3D control
	ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) );
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER;
	if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbdesc, &pDSBPrimary, NULL ) ) )
		return DXTRACE_ERR( TEXT("CreateSoundBuffer"), hr );

	if( FAILED( hr = pDSBPrimary->QueryInterface( IID_IDirectSound3DListener,
						                          (VOID**)ppDSListener ) ) )
	{
		SAFE_RELEASE( pDSBPrimary );
		return DXTRACE_ERR( TEXT("QueryInterface"), hr );
	}

	// Release the primary buffer, since it is not need anymore
	SAFE_RELEASE( pDSBPrimary );

	return S_OK;
}
开发者ID:Solarisbf,项目名称:D2D_egg_factory,代码行数:36,代码来源:SoundManager.cpp

示例2:

bool VDAudioOutputDirectSoundW32::InitPlayback() {
	tWAVEFORMATEX *wf = &*mInitFormat;
	mMillisecsPerByte = 1000.0 * (double)wf->nBlockAlign / (double)wf->nAvgBytesPerSec;

	// create looping secondary buffer
	DSBUFFERDESC dsd={sizeof(DSBUFFERDESC)};
	dsd.dwFlags			= DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
	dsd.dwBufferBytes	= mDSBufferSize;
	dsd.lpwfxFormat		= (WAVEFORMATEX *)wf;
	dsd.guid3DAlgorithm	= DS3DALG_DEFAULT;

	IDirectSoundBuffer *pDSB;
	HRESULT hr = mpDS8->CreateSoundBuffer(&dsd, &pDSB, NULL);
	if (FAILED(hr)) {
		VDDEBUG("VDAudioOutputDirectSound: Failed to create secondary buffer! hr=%08x\n", hr);
		return false;
	}

	// query to IDirectSoundBuffer8
	hr = pDSB->QueryInterface(IID_IDirectSoundBuffer8, (void **)&mpDSBuffer);
	pDSB->Release();
	if (FAILED(hr)) {
		VDDEBUG("VDAudioOutputDirectSound: Failed to obtain IDirectSoundBuffer8 interface! hr=%08x\n", hr);
		return false;
	}

	// all done!
	mDSWriteCursor = 0;
	return true;
}
开发者ID:KGE-INC,项目名称:VirtualDub,代码行数:30,代码来源:audioout.cpp

示例3: LoadSoundWave

		HRESULT NatsumeSound::LoadSoundWave(TCHAR *_FileName)
		{
			// Waveファイルオープン
			WAVEFORMATEX wFmt;
			char *pWaveData = 0;
			DWORD WaveSize = 0;
			if(FAILED(
				OpenWave(_FileName,wFmt,&pWaveData,WaveSize)
				))
			{
				Error("Waveファイルのロードに失敗しました。");
				return E_FAIL;
			}

			DSBUFFERDESC DSBufferDesc;
			DSBufferDesc.dwSize = sizeof(DSBUFFERDESC);
			DSBufferDesc.dwFlags = 0;
			DSBufferDesc.dwBufferBytes = WaveSize;
			DSBufferDesc.dwReserved = 0;
			DSBufferDesc.lpwfxFormat = &wFmt;
			DSBufferDesc.guid3DAlgorithm = GUID_NULL;


			IDirectSoundBuffer *ptmpBuf = 0;

			LpDirectSound->CreateSoundBuffer( &DSBufferDesc, &ptmpBuf, NULL );
			ptmpBuf->QueryInterface( IID_IDirectSoundBuffer8 ,(void**)&SoundDataBuffer[SoundDataBufferNextKey] );
			ptmpBuf->Release();
			if ( SoundDataBuffer[SoundDataBufferNextKey] == 0 )
			{
				//pDS8->Release();
				return E_FAIL;
			}

			// セカンダリバッファにWaveデータ書き込み
			LPVOID lpvWrite = 0;
			DWORD dwLength = 0;
			if ( DS_OK == SoundDataBuffer[SoundDataBufferNextKey]->Lock( 0, 0, &lpvWrite, &dwLength, NULL, NULL, DSBLOCK_ENTIREBUFFER ) )
			{
				memcpy( lpvWrite, pWaveData, dwLength);
				SoundDataBuffer[SoundDataBufferNextKey]->Unlock( lpvWrite, dwLength, NULL, 0);
			}
			delete[] pWaveData; // 元音はもういらない

			return S_OK;
		}
开发者ID:Yoruichigo,项目名称:CircleWave,代码行数:46,代码来源:NatsumeSound.cpp

示例4: CreateStreaming

//-----------------------------------------------------------------------------
// Name: CSoundManager::CreateStreaming()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CSoundManager::CreateStreaming( CStreamingSound** ppStreamingSound,
						                LPTSTR strWaveFileName,
						                DWORD dwCreationFlags,
						                GUID guid3DAlgorithm,
						                DWORD dwNotifyCount,
						                DWORD dwNotifySize,
						                HANDLE hNotifyEvent )
{
	HRESULT hr;

	if( m_pDS == NULL )
		return CO_E_NOTINITIALIZED;
	if( strWaveFileName == NULL || ppStreamingSound == NULL || hNotifyEvent == NULL )
		return E_INVALIDARG;

	IDirectSoundBuffer* pDSBuffer      = NULL;
	DWORD               dwDSBufferSize = NULL;
	CWaveFile*          pWaveFile      = NULL;
	DSBPOSITIONNOTIFY*  aPosNotify     = NULL;
	IDirectSoundNotify* pDSNotify      = NULL;

	pWaveFile = new CWaveFile();
	if( pWaveFile == NULL )
		return E_OUTOFMEMORY;
	pWaveFile->Open( strWaveFileName, NULL, WAVEFILE_READ );

	// Figure out how big the DirectSound buffer should be
	dwDSBufferSize = dwNotifySize * dwNotifyCount;

	// Set up the direct sound buffer.  Request the NOTIFY flag, so
	// that we are notified as the sound buffer plays.  Note, that using this flag
	// may limit the amount of hardware acceleration that can occur.
	DSBUFFERDESC dsbd;
	ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
	dsbd.dwSize          = sizeof(DSBUFFERDESC);
	dsbd.dwFlags         = dwCreationFlags |
						   DSBCAPS_CTRLPOSITIONNOTIFY |
						   DSBCAPS_GETCURRENTPOSITION2;
	dsbd.dwBufferBytes   = dwDSBufferSize;
	dsbd.guid3DAlgorithm = guid3DAlgorithm;
	dsbd.lpwfxFormat     = pWaveFile->m_pwfx;

	if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBuffer, NULL ) ) )
	{
		// If wave format isn't then it will return
		// either DSERR_BADFORMAT or E_INVALIDARG
		if( hr == DSERR_BADFORMAT || hr == E_INVALIDARG )
			return DXTRACE_ERR( TEXT("CreateSoundBuffer"), hr );

		return DXTRACE_ERR( TEXT("CreateSoundBuffer"), hr );
	}

	// Create the notification events, so that we know when to fill
	// the buffer as the sound plays.
	if( FAILED( hr = pDSBuffer->QueryInterface( IID_IDirectSoundNotify,
						                        (VOID**)&pDSNotify ) ) )
	{
		SAFE_DELETE_ARRAY( aPosNotify );
		return DXTRACE_ERR( TEXT("QueryInterface"), hr );
	}

	aPosNotify = new DSBPOSITIONNOTIFY[ dwNotifyCount ];
	if( aPosNotify == NULL )
		return E_OUTOFMEMORY;

	for( DWORD i = 0; i < dwNotifyCount; i++ )
	{
		aPosNotify[i].dwOffset     = (dwNotifySize * i) + dwNotifySize - 1;
		aPosNotify[i].hEventNotify = hNotifyEvent;
	}

	// Tell DirectSound when to notify us. The notification will come in the from
	// of signaled events that are handled in WinMain()
	if( FAILED( hr = pDSNotify->SetNotificationPositions( dwNotifyCount,
						                                  aPosNotify ) ) )
	{
		SAFE_RELEASE( pDSNotify );
		SAFE_DELETE_ARRAY( aPosNotify );
		return DXTRACE_ERR( TEXT("SetNotificationPositions"), hr );
	}

	SAFE_RELEASE( pDSNotify );
	SAFE_DELETE_ARRAY( aPosNotify );

	// Create the sound
	*ppStreamingSound = new CStreamingSound( pDSBuffer, dwDSBufferSize, pWaveFile, dwNotifySize );

	return S_OK;
}
开发者ID:Solarisbf,项目名称:D2D_egg_factory,代码行数:93,代码来源:SoundManager.cpp

示例5: CreateSoundBuffer

void Window::CreateSoundBuffer(void)
{
	//Fill in structures describing the sound buffer
	WAVEFORMATEX bufferFormat = {0};
	bufferFormat.wFormatTag		= WAVE_FORMAT_PCM;
	bufferFormat.nChannels		= 2;
	bufferFormat.nSamplesPerSec	= 44100;
	bufferFormat.wBitsPerSample	= 16;
	bufferFormat.nBlockAlign	= bufferFormat.nChannels * bufferFormat.wBitsPerSample / 8;
	bufferFormat.nAvgBytesPerSec= bufferFormat.nSamplesPerSec * bufferFormat.nBlockAlign;

	DSBUFFERDESC bufferDesc = {0};
	bufferDesc.dwSize			= sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags			= DSBCAPS_GLOBALFOCUS;
	bufferDesc.dwBufferBytes	= bufferFormat.nAvgBytesPerSec;
	bufferDesc.lpwfxFormat		= &bufferFormat;

    //Create an IDirectSoundBuffer
    IDirectSoundBuffer * tempSoundBuffer;

	if(FAILED(directSound->CreateSoundBuffer(&bufferDesc, &tempSoundBuffer, 0)))
		throw Ex("Window Error: directSound->CreateSoundBuffer failed");

	//Promote to an IDirectSoundBuffer8
	if(FAILED(tempSoundBuffer->QueryInterface(	IID_IDirectSoundBuffer8,
												reinterpret_cast<LPVOID *>(&soundBuffer))))
	{
		throw Ex("Window Error: tempSoundBuffer->QueryInterface failed");
	}

	//Release the temporary sound buffer
	tempSoundBuffer->Release();

	//Zero the contents of the sound buffer
	Dword numSoundBufferBytes;
	void * soundBufferDataPtr;

	if(FAILED(soundBuffer->Lock(0, 0, &soundBufferDataPtr, &numSoundBufferBytes, 0, 0, DSBLOCK_ENTIREBUFFER)))
		throw Ex("Window Error: soundBuffer->Lock failed");

	ZeroMemory(soundBufferDataPtr, numSoundBufferBytes);

	if(FAILED(soundBuffer->Unlock(soundBufferDataPtr, numSoundBufferBytes, 0, 0)))
		throw Ex("Window Error: soundBuffer->Unlock failed");
}
开发者ID:Creeper20428,项目名称:Data,代码行数:45,代码来源:Window_CreateSoundBuffer.cpp

示例6: toear

int CSoundResource::play3D( int sndID, const DS3DBUFFER& props3D, DWORD priority, DWORD flags, LONG volume, LONG freq )
{
	HRESULT hr;
	DWORD	baseFreq;
	
	assert( mDSBuffers );

	// cull the sound if too far
	const SVector3& earPos = G_AUDIOCTX->getListener().transform.getOrigin();
	SVector3 toear( earPos.x - props3D.vPosition.x, earPos.y - props3D.vPosition.y, earPos.z - props3D.vPosition.z );
	if( toear.lengthSq() >= props3D.flMaxDistance * props3D.flMaxDistance )
		return 0;

	
	
	int bufferIdx = getFreeBufferIndex();
	IDirectSoundBuffer* buffer = mDSBuffers[bufferIdx];
	if( !restoreBufferAndFill( buffer, false ) )
		return -1;
	
	if( mCreationFlags & DSBCAPS_CTRLVOLUME )
		buffer->SetVolume( volume );
	if( mCreationFlags & DSBCAPS_CTRLFREQUENCY ) {
		buffer->GetFrequency( &baseFreq );
		buffer->SetFrequency( baseFreq + freq );
	}
	
	IDirectSound3DBuffer* buf3D;
	hr = buffer->QueryInterface( IID_IDirectSound3DBuffer, (void**)&buf3D );
	if( SUCCEEDED( hr ) ) {
		hr = buf3D->SetAllParameters( &props3D, DS3D_IMMEDIATE );
		if( SUCCEEDED( hr ) ) {
			mPlayingIDs[bufferIdx] = sndID;
			hr = buffer->Play( 0, priority, flags );
		}
		buf3D->Release();
	}
	
	return bufferIdx;
}
开发者ID:BackupTheBerlios,项目名称:dingus-svn,代码行数:40,代码来源:SoundResource.cpp

示例7: Init

//	Initialise DirectSound and buffers
void Loudspeaker::Init(HWND hwnd)
{
	//	Direct sound
	DirectSoundCreate8(NULL, &directSound, NULL);
	directSound->SetCooperativeLevel(hwnd, DSSCL_PRIORITY);

	//	Primary (soundcard) buffer
	DSBUFFERDESC bufferDesc;
	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
	bufferDesc.dwBufferBytes = 0;
	bufferDesc.dwReserved = 0;
	bufferDesc.lpwfxFormat = NULL;
	bufferDesc.guid3DAlgorithm = GUID_NULL;
	directSound->CreateSoundBuffer(&bufferDesc, &primaryBuffer, NULL);

	WAVEFORMATEX waveFormat;
	waveFormat.wFormatTag = WAVE_FORMAT_PCM;
	waveFormat.nSamplesPerSec = 44100;
	waveFormat.wBitsPerSample = 16;
	waveFormat.nChannels = 1;
	waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8) * waveFormat.nChannels;
	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
	waveFormat.cbSize = 0;
	primaryBuffer->SetFormat(&waveFormat);

	//	Secondary (CPU) buffer
	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
	bufferDesc.dwBufferBytes = 1764;
	bufferDesc.dwReserved = 0;
	bufferDesc.lpwfxFormat = &waveFormat;
	bufferDesc.guid3DAlgorithm = GUID_NULL;

	IDirectSoundBuffer* temp;
	directSound->CreateSoundBuffer(&bufferDesc, &temp, NULL);
	temp->QueryInterface(IID_IDirectSoundBuffer8, (void**)&secondaryBuffer);
	temp->Release();
	temp = 0;
}
开发者ID:jo215,项目名称:ZXpp,代码行数:41,代码来源:Loudspeaker.cpp

示例8: initialize

bool OutputDirectSound::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format)
{
    Q_UNUSED(format);
    DSBUFFERDESC bufferDesc;

    HRESULT result = DirectSoundCreate8(0, &m_ds, 0);
    if(result != DS_OK)
    {
        qWarning("OutputDirectSound: DirectSoundCreate8 failed, error code = 0x%lx", result);
        m_ds = 0;
        return false;
    }

    if((result = m_ds->SetCooperativeLevel(GetDesktopWindow(), DSSCL_PRIORITY)) != DS_OK)
    {
        qWarning("OutputDirectSound: SetCooperativeLevel failed, error code = 0x%lx", result);
        return false;
    }

    ZeroMemory(&bufferDesc, sizeof(DSBUFFERDESC));
    bufferDesc.dwSize        = sizeof(DSBUFFERDESC);
    bufferDesc.dwFlags       = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
    bufferDesc.dwBufferBytes = 0;
    bufferDesc.lpwfxFormat   = NULL;

    if((result = m_ds->CreateSoundBuffer(&bufferDesc, &m_primaryBuffer, NULL)) != DS_OK)
    {
        m_primaryBuffer = 0;
        qWarning("OutputDirectSound: CreateSoundBuffer failed, error code = 0x%lx", result);
        return false;
    }

    WAVEFORMATEX wfex;
    ZeroMemory(&wfex, sizeof(WAVEFORMATEX));
    wfex.wFormatTag      = WAVE_FORMAT_PCM;
    wfex.nChannels       = map.count();
    wfex.nSamplesPerSec  = freq;
    wfex.wBitsPerSample  = 16;
    wfex.nBlockAlign     = (wfex.wBitsPerSample / 8) * wfex.nChannels;
    wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;

    if((result = m_primaryBuffer->SetFormat(&wfex)) != DS_OK)
    {
        qWarning("OutputDirectSound: SetFormat failed, error code = 0x%lx", result);
        return false;
    }

    if((result = m_primaryBuffer->Play(0, 0, DSBPLAY_LOOPING)) != DS_OK)
    {
        qWarning("OutputDirectSound: Play failed, error code = 0x%lx", result);
        return false;
    }

    ZeroMemory(&wfex, sizeof(WAVEFORMATEX));
    wfex.wFormatTag      = WAVE_FORMAT_PCM;
    wfex.nChannels       = map.count();
    wfex.nSamplesPerSec  = freq;
    wfex.wBitsPerSample  = 16;
    wfex.nBlockAlign     = (wfex.wBitsPerSample / 8) * wfex.nChannels;
    wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;

    ZeroMemory(&bufferDesc, sizeof(DSBUFFERDESC));
    bufferDesc.dwSize        = sizeof(DSBUFFERDESC);
    bufferDesc.dwFlags       = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME |
            DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY;
    bufferDesc.lpwfxFormat   = &wfex;
    bufferDesc.dwBufferBytes = DS_BUFSIZE; // buffer size

    IDirectSoundBuffer *pDSB;
    if((result = m_ds->CreateSoundBuffer(&bufferDesc, &pDSB, NULL)) != DS_OK)
    {
        qWarning("OutputDirectSound: CreateSoundBuffer failed, error code = 0x%lx", result);
        return false;
    }

    if((result = pDSB->QueryInterface(IID_IDirectSoundBuffer8, (void**)&m_dsBuffer)) != DS_OK)
    {
        m_dsBuffer = 0;
        qWarning("OutputDirectSound: QueryInterface failed, error code = 0x%lx", result);
        pDSB->Release();
        return false;
    }

    m_dsBuffer->SetCurrentPosition(0);
    m_dsBuffer->Play(0,0,DSBPLAY_LOOPING);
    m_dsBufferAt = 0;
    configure(freq, map, Qmmp::PCM_S16LE);
    if(volumeControl)
        volumeControl->restore();
    return true;
}
开发者ID:Greedysky,项目名称:qmmp,代码行数:91,代码来源:outputdirectsound.cpp

示例9: mmioOpen

TDDSDGenWave::TDDSDGenWave( TDDSD* OWner, const wstring& fname, bool is3D, bool useFX )
{
	FIsStream = false;
	FOwner = OWner;
	FUseFX = useFX;

	//サウンドカードが無いなら、何もしない
	if( ! FOwner->Initialized() )
		return;

	HMMIO hm  =  mmioOpen((LPWSTR)fname.c_str(), NULL, MMIO_READ | MMIO_ALLOCBUF);

	if( hm == 0 ) {
		//PutDebugMessage(fname + 'が、見つかりません');
		return;
	}

	//WAVEに入る
	MMCKINFO mckP;    //親チャンクの情報
	mckP.fccType = MakeFourCC('W','A','V','E');
	if( (mmioDescend(hm, &mckP, NULL, MMIO_FINDRIFF)) != 0 ) {
		mmioClose(hm, 0);
		//PutDebugMessage(fname + 'は、WAVEファイルではありません');
		return;
	}

	//fmtチャンクに入る
	MMCKINFO mckC;    //子チャンクの情報
	mckC.ckid = MakeFourCC('f','m','t',' ');
	if( mmioDescend(hm, &mckC, &mckP, MMIO_FINDCHUNK) != 0 ) {
		mmioClose(hm, 0);
		//PutDebugMessage(fname + 'には、fmtチャンクが有りません');
		return;
	}

	//fmtチャンクを読み取る
	u32 fmtSize  =  mckC.cksize;
	if( mmioRead(hm, (HPSTR)&FWaveFormat, fmtSize) != fmtSize ) {
		mmioClose(hm, 0);
		//PutDebugMessage(fname + 'のfmtチャンクが不正です');
		return;
	}

	//fmtチャンクを抜け、dataチャンクに入る
	mmioAscend(hm, &mckC, 0);
	mckC.ckid = MakeFourCC('d','a','t','a');
	if( mmioDescend(hm, &mckC, &mckP, MMIO_FINDCHUNK) != 0 ) {
		mmioClose(hm, 0);
		//PutDebugMessage(fname + 'には、dataチャンクが有りません');
		return;
	}

	u32 dataSize = mckC.cksize;

	//二次バッファの作成
	DSBUFFERDESC dsbd;
	ZeroMemory(&dsbd, sizeof(dsbd));
	dsbd.dwSize = sizeof(dsbd);
	if( is3D )
		dsbd.dwFlags = DSBCAPS_CTRLVOLUME + DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRL3D;
	else
		dsbd.dwFlags = DSBCAPS_CTRLPAN + DSBCAPS_CTRLVOLUME + DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN;

	if( FUseFX )
		dsbd.dwFlags = DSBCAPS_CTRLPAN + DSBCAPS_CTRLVOLUME + DSBCAPS_CTRLFREQUENCY + DSBCAPS_CTRLFX;


	if( FOwner->FStickyFocus )
		dsbd.dwFlags = dsbd.dwFlags | DSBCAPS_STICKYFOCUS;

	dsbd.dwBufferBytes = dataSize;
	dsbd.lpwfxFormat = &FWaveFormat;

	FLength = dataSize;

	IDirectSoundBuffer* dsb;
	FOwner->DSound()->CreateSoundBuffer(&dsbd, &dsb, NULL);
	dsb->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&FSoundBuffer);
	dsb->Release(); 


	//二次バッファのロック
	LPVOID lpBuf1, lpBuf2;
	DWORD dwBuf1, dwBuf2;
	FSoundBuffer->Lock(0,dataSize, &lpBuf1, &dwBuf1, &lpBuf2, &dwBuf2, 0);

	//音データのロード(dataチャンクを読み取る)
	mmioRead(hm, (HPSTR)lpBuf1, dwBuf1);
	if( dwBuf2 != 0 ) {
		mmioRead(hm, (HPSTR)lpBuf2, dwBuf2);
	}

	FSoundBuffer->Unlock(lpBuf1,dwBuf1,lpBuf2,dwBuf2);
	FSoundBuffer->SetFrequency(FWaveFormat.nSamplesPerSec);
	mmioClose(hm, 0);


}
开发者ID:ukifuku,项目名称:cloudphobia_cpp,代码行数:98,代码来源:DDSD.cpp

示例10: LoadWav

HRESULT DirectSoundDevice::LoadWav(char* filename, SGE::Sound::Sound *sound){
	//This method is based of an example featured on http://www.rastertek.com/dx11tut14.html
	struct WaveHeaderType
	{
		char chunkId[4];
		unsigned long chunkSize;
		char format[4];
		char subChunkId[4];
		unsigned long subChunkSize;
		unsigned short audioFormat;
		unsigned short numChannels;
		unsigned long sampleRate;
		unsigned long bytesPerSecond;
		unsigned short blockAlign;
		unsigned short bitsPerSample;
		char dataChunkId[4];
		unsigned long dataSize;
	};

	sound->index = -1;

	int error;
	FILE* filePtr = NULL;
	unsigned int count;
	WaveHeaderType waveFileHeader;
	WAVEFORMATEX waveFormat;
	DSBUFFERDESC bufferDesc;
	HRESULT result;
	IDirectSoundBuffer* tempBuffer = NULL;
	unsigned char* waveData = NULL;
	unsigned char *bufferPtr = NULL;
	unsigned long bufferSize = NULL;

	if(fopen_s(&filePtr, filename, "rb") != 0)
		return E_FAIL;

	count = fread(&waveFileHeader, sizeof(waveFileHeader), 1, filePtr);

	if(count != 1)
	{
		return E_FAIL;
	}

	// Check that the chunk ID is the RIFF format.
	if((waveFileHeader.chunkId[0] != 'R') || (waveFileHeader.chunkId[1] != 'I') || 
	   (waveFileHeader.chunkId[2] != 'F') || (waveFileHeader.chunkId[3] != 'F'))
	{
		return E_FAIL;
	}
 
	// Check that the file format is the WAVE format.
	if((waveFileHeader.format[0] != 'W') || (waveFileHeader.format[1] != 'A') ||
	   (waveFileHeader.format[2] != 'V') || (waveFileHeader.format[3] != 'E'))
	{
		return E_FAIL;
	}
 
	// Check that the sub chunk ID is the fmt format.
	if((waveFileHeader.subChunkId[0] != 'f') || (waveFileHeader.subChunkId[1] != 'm') ||
	   (waveFileHeader.subChunkId[2] != 't') || (waveFileHeader.subChunkId[3] != ' '))
	{
		return E_FAIL;
	}
 

	// Check for the data chunk header.
	if((waveFileHeader.dataChunkId[0] != 'd') || (waveFileHeader.dataChunkId[1] != 'a') ||
	   (waveFileHeader.dataChunkId[2] != 't') || (waveFileHeader.dataChunkId[3] != 'a'))
	{
		return E_FAIL;
	}

	// Set the wave format of secondary buffer that this wave file will be loaded onto.
	waveFormat.wFormatTag = waveFileHeader.audioFormat;
	waveFormat.nSamplesPerSec = waveFileHeader.sampleRate;
	waveFormat.wBitsPerSample = waveFileHeader.bitsPerSample;
	waveFormat.nChannels = waveFileHeader.numChannels;
	waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8) * waveFormat.nChannels;
	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
	waveFormat.cbSize = 0;
 
	// Set the buffer description of the secondary sound buffer that the wave file will be loaded onto.
	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
	bufferDesc.dwBufferBytes = waveFileHeader.dataSize;
	bufferDesc.dwReserved = 0;
	bufferDesc.lpwfxFormat = &waveFormat;
	bufferDesc.guid3DAlgorithm = GUID_NULL;

	IDirectSoundBuffer8 * soundBuffer = NULL;

	result = lpds->CreateSoundBuffer(&bufferDesc, &tempBuffer, NULL);
	if(FAILED(result)) return result;
	result = tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (void**)&soundBuffer);
	if(FAILED(result)) return result;

	tempBuffer->Release();
	tempBuffer = 0;

	fseek(filePtr, sizeof(WaveHeaderType), SEEK_SET);
//.........这里部分代码省略.........
开发者ID:SHession,项目名称:SGE,代码行数:101,代码来源:DirectSoundDevice.cpp

示例11: LoadWaveFile

bool SoundClass::LoadWaveFile(char* filename, IDirectSoundBuffer8** secondaryBuffer)
{
	int error;
	FILE* filePtr;
	unsigned int count;
	WaveHeaderType waveFileHeader;
	WAVEFORMATEX waveFormat;
	DSBUFFERDESC bufferDesc;
	HRESULT result;
	IDirectSoundBuffer* tempBuffer;
	unsigned char* waveData;
	unsigned char* bufferPtr;
	unsigned long bufferSize;

	error = fopen_s(&filePtr, filename, "rb");
	if (error != 0)
	{
		return false;
	}

	count = fread(&waveFileHeader, sizeof(waveFileHeader), 1, filePtr);
	if (count != 1)
	{
		return false;
	}

	if ((waveFileHeader.chunkId[0] != 'R') || (waveFileHeader.chunkId[1] != 'I') ||
		(waveFileHeader.chunkId[2] != 'F') || (waveFileHeader.chunkId[3] != 'F'))
	{
		return false;
	}

	if ((waveFileHeader.format[0] != 'W') || (waveFileHeader.format[1] != 'A') ||
		(waveFileHeader.format[2] != 'V') || (waveFileHeader.format[3] != 'E'))
	{
		return false;
	}

	if ((waveFileHeader.subChunkId[0] != 'f') || (waveFileHeader.subChunkId[1] != 'm') ||
		(waveFileHeader.subChunkId[2] != 't') || (waveFileHeader.subChunkId[3] != ' '))
	{
		return false;
	}

	if (waveFileHeader.audioFormat != WAVE_FORMAT_PCM)
	{
		return false;
	}

	if (waveFileHeader.numChannels != 2)
	{
		return false;
	}

	if (waveFileHeader.sampleRate != 44100)
	{
		return false;
	}

	if (waveFileHeader.bitsPerSample != 16)
	{
		return false;
	}

	if ((waveFileHeader.dataChunkId[0] != 'd') || (waveFileHeader.dataChunkId[1] != 'a') ||
		(waveFileHeader.dataChunkId[2] != 't') || (waveFileHeader.dataChunkId[3] != 'a'))
	{
		return false;
	}

	waveFormat.wFormatTag = WAVE_FORMAT_PCM;
	waveFormat.nSamplesPerSec = 44100;
	waveFormat.wBitsPerSample = 16;
	waveFormat.nChannels = 2;
	waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8) * waveFormat.nChannels;
	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
	waveFormat.cbSize = 0;

	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
	bufferDesc.dwBufferBytes = waveFileHeader.dataSize;
	bufferDesc.dwReserved = 0;
	bufferDesc.lpwfxFormat = &waveFormat;
	bufferDesc.guid3DAlgorithm = GUID_NULL;

	result = m_DirectSound->CreateSoundBuffer(&bufferDesc, &tempBuffer, NULL);
	if (FAILED(result))
	{
		return false;
	}

	result = tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (void**)&*secondaryBuffer);
	if (FAILED(result))
	{
		return false;
	}

	tempBuffer->Release();
	tempBuffer = 0;

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

示例12: loadWav

bool cSound::loadWav(char* fileName, IDirectSoundBuffer8**secondaryBuffer)
{
	int error;
	FILE *filePtr;
	unsigned int count=0;
	wavFileHeader waveFileHeader; //Stores the header of the wav file type
	WAVEFORMATEX waveFormat; //Stores the buffer wav format
	DSBUFFERDESC bufferDesc; //To sotre the details of the buffer
	IDirectSoundBuffer* tmpBuffer;
	unsigned char *waveData; //To load the wav file temporarily
	unsigned char *bufferPtr;
	unsigned long bufferSize;

	error = fopen_s(&filePtr, fileName, "rb");
	if (error!=0)
		return false;
	if (filePtr)
	count = fread(&waveFileHeader, sizeof(wavFileHeader), 1, filePtr);
	if (count != 1)
		return false;
	
	if ((waveFileHeader.chunkId[0] != 'R') || (waveFileHeader.chunkId[1] != 'I') ||
		(waveFileHeader.chunkId[2] != 'F') || (waveFileHeader.chunkId[3] != 'F'))
	{
		return false;// Check that the chunk ID is the RIFF format.
	}
		
	if ((waveFileHeader.format[0] != 'W') || (waveFileHeader.format[1] != 'A') ||
		(waveFileHeader.format[2] != 'V') || (waveFileHeader.format[3] != 'E'))
	{
		return false;// Check that the file format is the WAVE format.
	}

	if ((waveFileHeader.subChunkId[0] != 'f') || (waveFileHeader.subChunkId[1] != 'm') ||
		(waveFileHeader.subChunkId[2] != 't') || (waveFileHeader.subChunkId[3] != ' '))
	{
		return false;// Check that the sub chunk ID is the fmt format.
	}

	if (waveFileHeader.audioFormat != WAVE_FORMAT_PCM)
	{
		return false;// Check that the audio format is WAVE_FORMAT_PCM.
	}
	int numChannels = waveFileHeader.numChannels;
	int sampleRate = waveFileHeader.sampleRate;
	int bitsPerSample = waveFileHeader.bitsPerSample;
		
	if ((waveFileHeader.dataChunkId[0] != 'd') || (waveFileHeader.dataChunkId[1] != 'a') ||
		(waveFileHeader.dataChunkId[2] != 't') || (waveFileHeader.dataChunkId[3] != 'a'))
		return false;// Check for the data chunk header.

	waveFormat.wFormatTag = WAVE_FORMAT_PCM;
	waveFormat.nSamplesPerSec = sampleRate;
	waveFormat.nChannels = numChannels;
	waveFormat.wBitsPerSample = bitsPerSample;
	waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8)*waveFormat.nChannels;
	waveFormat.nAvgBytesPerSec = waveFormat.nBlockAlign*waveFormat.nSamplesPerSec;
	waveFormat.cbSize = 0;

	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
	bufferDesc.dwBufferBytes = waveFileHeader.dataSize;
	bufferDesc.dwReserved = 0;
	bufferDesc.lpwfxFormat = &waveFormat;
	bufferDesc.guid3DAlgorithm = GUID_NULL;

	HRESULT result;
	result = intSound->CreateSoundBuffer(&bufferDesc, &tmpBuffer, NULL);
	if (FAILED(result))return false;
	result = tmpBuffer->QueryInterface(IID_IDirectSoundBuffer8, (void**)&*secondaryBuffer);
	if (FAILED(result))return false;
	tmpBuffer->Release();
	tmpBuffer = NULL;

	//R E A D I N G  T H E  W A V  F I L E  S T A R T S  H E R E
	fseek(filePtr, sizeof(waveFileHeader), SEEK_SET);
	waveData = new unsigned char[waveFileHeader.dataSize];
	memset(waveData, 0, waveFileHeader.dataSize);
	if(!waveData)	return false;
	while (count<waveFileHeader.dataSize)
	count = fread(waveData, 1, waveFileHeader.dataSize, filePtr);
	error = fclose(filePtr);
	if (error != 0)return false;
	result = (*secondaryBuffer)->Lock(0,waveFileHeader.dataSize,(void**)&bufferPtr,(DWORD*)&bufferSize,NULL,0,0);
	if (FAILED(result))return false;
	memcpy(bufferPtr, waveData, waveFileHeader.dataSize);
	result = (*secondaryBuffer)->Unlock((void**)bufferPtr, bufferSize, NULL, 0);
	if (FAILED(result))return false;
	delete[]waveData;

	return true;
}
开发者ID:AakashDabas,项目名称:DrBrain,代码行数:92,代码来源:sound.cpp

示例13: LoadWaveFile

bool Sound::LoadWaveFile(const char* filename, IDirectSoundBuffer8** secondaryBuffer)
{
	int error;
	FILE* filePtr;
	unsigned int count;
	WaveHeaderType waveFileHeader;
	WAVEFORMATEX waveFormat;
	DSBUFFERDESC bufferDesc;
	HRESULT result;
	IDirectSoundBuffer* tempBuffer;
	unsigned char* waveData;
	unsigned char* bufferPtr;
	unsigned long bufferSize;

	error = fopen_s(&filePtr, filename, "rb");
	if(error != 0)
	{
		return false;
	}

	count = fread(&waveFileHeader, sizeof(waveFileHeader), 1, filePtr);
	if(count != 1)
	{
		return false;
	}

	//check through the header to make sure that it is a non-corrupted WAV file
	if((waveFileHeader.chunkId[0] != 'R') || (waveFileHeader.chunkId[1] != 'I') || 
	   (waveFileHeader.chunkId[2] != 'F') || (waveFileHeader.chunkId[3] != 'F'))
	{
		return false;
	}

	if((waveFileHeader.format[0] != 'W') || (waveFileHeader.format[1] != 'A') ||
	   (waveFileHeader.format[2] != 'V') || (waveFileHeader.format[3] != 'E'))
	{
		return false;
	}

	if((waveFileHeader.subChunkId[0] != 'f') || (waveFileHeader.subChunkId[1] != 'm') ||
	   (waveFileHeader.subChunkId[2] != 't') || (waveFileHeader.subChunkId[3] != ' '))
	{
		return false;
	}

	if(waveFileHeader.audioFormat != WAVE_FORMAT_PCM)
	{
		return false;
	}

	if(waveFileHeader.numChannels != 2)
	{
		return false;
	}

	if(waveFileHeader.sampleRate != 44100)
	{
		return false;
	}

	if(waveFileHeader.bitsPerSample != 16)
	{
		return false;
	}

	if((waveFileHeader.dataChunkId[0] != 'd') || (waveFileHeader.dataChunkId[1] != 'a') ||
	   (waveFileHeader.dataChunkId[2] != 't') || (waveFileHeader.dataChunkId[3] != 'a'))
	{
		return false;
	}

	waveFormat.wFormatTag = WAVE_FORMAT_PCM;
	waveFormat.nSamplesPerSec = 44100;
	waveFormat.wBitsPerSample = 16;
	waveFormat.nChannels = 2;
	waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8) * waveFormat.nChannels;
	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
	waveFormat.cbSize = 0;

	bufferDesc.dwSize = sizeof(DSBUFFERDESC);
	bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
	bufferDesc.dwBufferBytes = waveFileHeader.dataSize;
	bufferDesc.dwReserved = 0;
	bufferDesc.lpwfxFormat = &waveFormat;
	bufferDesc.guid3DAlgorithm = GUID_NULL;

	result = m_DirectSound->CreateSoundBuffer(&bufferDesc, &tempBuffer, NULL);
	if(FAILED(result))
	{
		return false;
	}

	result = tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (void**)&*secondaryBuffer);
	if(FAILED(result))
	{
		return false;
	}

	tempBuffer->Release();
	tempBuffer = 0;
//.........这里部分代码省略.........
开发者ID:JakeJimmyThorne,项目名称:ColourSpace,代码行数:101,代码来源:sound.cpp

示例14: sSetSoundHandler

sBool sSetSoundHandler(sInt freq,sSoundHandler handler,sInt latency,sInt flags)
{
  HRESULT hr;
  DSBUFFERDESC dsbd;
  IDirectSoundBuffer *buffer = 0;
  void *p1,*p2;
  DWORD c1,c2;

  WAVEFORMATEXTENSIBLE sformat = { { WAVE_FORMAT_PCM,2,freq,freq*4,4,16,0 }, {0}, {3}, {0} };

  sClearSoundHandler();
  if(!DXSThread) return 0;
  sLockSound();
  DXSOSamples = latency;
  DXSORate = freq;
  DXSOChannels = 2;

  if (flags & sSOF_5POINT1)
  {
    DXSOChannels=6;
    sformat.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
    sformat.Format.cbSize=22;
    sformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
  }

  sformat.Format.nChannels=DXSOChannels;
  sformat.Format.nBlockAlign=2*DXSOChannels;
  sformat.Format.nAvgBytesPerSec=freq*sformat.Format.nBlockAlign;
  sformat.Samples.wValidBitsPerSample=16;
  sformat.dwChannelMask=(1<<DXSOChannels)-1; // very space opera

  // open device

  hr = DirectSoundCreate8(0,&DXSO,0);
  if(FAILED(hr)) goto error;

  hr = DXSO->SetCooperativeLevel(sHWND,DSSCL_PRIORITY);
  if(FAILED(hr)) goto error;

  // set primary buffer sample rate

  sSetMem(&dsbd,0,sizeof(dsbd));
  dsbd.dwSize = sizeof(dsbd);
  dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
  dsbd.dwBufferBytes = 0;
  dsbd.lpwfxFormat = 0;
  hr = DXSO->CreateSoundBuffer(&dsbd,&DXSOPrimary,0);
  if(SUCCEEDED(hr)) 
    DXSOPrimary->SetFormat(&sformat.Format);

  // create streaming buffer

  sSetMem(&dsbd,0,sizeof(dsbd));
  dsbd.dwSize = sizeof(dsbd);
  dsbd.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
  if(flags & sSOF_GLOBALFOCUS)
    dsbd.dwFlags |= DSBCAPS_GLOBALFOCUS;
  dsbd.dwBufferBytes = latency*DXSOChannels*2;
  dsbd.lpwfxFormat = &sformat.Format;
  hr = DXSO->CreateSoundBuffer(&dsbd,&buffer,0);
  if(FAILED(hr)) goto error;
  hr = buffer->QueryInterface(IID_IDirectSoundBuffer8,(void**)&DXSOBuffer);
  if(FAILED(hr)) goto error;
  buffer->Release(); buffer = 0;

  hr = DXSOBuffer->Lock(0,0,&p1,&c1,&p2,&c2,DSBLOCK_ENTIREBUFFER);
  if(!FAILED(hr))
  {
    if (p1) sSetMem(p1,0,c1);
    if (p2) sSetMem(p2,0,c2);
    DXSOBuffer->Unlock(p1,c1,p2,c2);
  }
  DXSOHandler = handler;

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

  sUnlockSound();
  sPingSound();
  return sTRUE;
error:
  sClearSoundHandler();
  sUnlockSound();
  return sFALSE;
}
开发者ID:Ambrevar,项目名称:fr_public,代码行数:84,代码来源:sound.cpp

示例15: Acquire

bool BufferCache::Acquire(const DSBUFFERDESC& desc, IDirectSoundBuffer8*& pBuffer, bool bUseCache)
{

	// If buffer caching is enabled, try to find a 
	// buffer with a matching description structure
	if(DXAudioMgr()->GetInit()->m_bCacheBuffers && bUseCache)
	{
		BufferInfoVector::iterator itr;
		for(itr = m_Free.begin(); itr != m_Free.end(); ++itr)
		{
			if((*itr)->m_Desc == desc)
			{
				pBuffer = (*itr)->m_pBuffer;
				pBuffer->SetCurrentPosition(0);
				pBuffer->AddRef();
				m_Used.push_back(*itr);
				m_Free.erase(itr);
				return true;
			}
		}
	}

	// Create a buffer normally
	IDirectSoundBuffer* pDSBuffer;
	HRESULT hr = DXAudioMgr()->DirectSound()->CreateSoundBuffer(&desc, &pDSBuffer, NULL);
	if(FAILED(hr))
	{
		DebugOut(3, "First attempt at sound buffer creation failed.  Error = %s.  Attempting again...", DXGetErrorString(hr));
		if(desc.dwFlags & DSBCAPS_CTRL3D)
		{
			DXAudioMgr()->ResetSound3DLimit();
			if(!DXAudioMgr()->RemoveSound3D(0))
				return Error::Handle("Could not create sound buffer.  Error = %s", DXGetErrorString(hr));
		}
		else
		{
			DXAudioMgr()->ResetSoundLimit();
			if(!DXAudioMgr()->RemoveSound(0))
				return Error::Handle("Could not create sound buffer.  Error = %s", DXGetErrorString(hr));
		}

		hr = DXAudioMgr()->DirectSound()->CreateSoundBuffer(&desc, &pDSBuffer, NULL);
		if(FAILED(hr))
			return Error::Handle("Could not create sound buffer.  Error = %s", DXGetErrorString(hr));
	}

	// Get the IDirectSoundBuffer8 interface
	hr = pDSBuffer->QueryInterface(IID_IDirectSoundBuffer8, (void**)&pBuffer);
	if(FAILED(hr))
		return Error::Handle("Could not obtain DirectSoundBuffer8 interface.  Error = %s", DXGetErrorString(hr));

	// Release the temporary DirectSoundBuffer interface
	pDSBuffer->Release();

	// If buffer caching is enabled,
	if(DXAudioMgr()->GetInit()->m_bCacheBuffers && bUseCache)
	{
		BufferInfo* pInfo = new BufferInfo;
		pInfo->m_pBuffer = pBuffer;
		pInfo->m_pBuffer->AddRef();
		memcpy(&pInfo->m_Format, desc.lpwfxFormat, sizeof(WAVEFORMATEX));
		memcpy(&pInfo->m_Desc, &desc, sizeof(DSBUFFERDESC));
		pInfo->m_Desc.lpwfxFormat = &pInfo->m_Format;
		m_Used.push_back(pInfo);
	}

	return true;
}
开发者ID:F5000,项目名称:spree,代码行数:68,代码来源:BufferCache.cpp


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