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


C++ IXAudio2SourceVoice类代码示例

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


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

示例1: processPunchSound

void GameAudio::processPunchSound()
{
	if (soundEffectRegistrationMap[ENUM_SOUND_EFFECT_PUNCH] == true)
	{
		Game *game = Game::getSingleton();
		GameStateManager *gsm = game->getGSM();
		SpriteManager *spriteMgr = gsm->getSpriteManager();
		PlayerSprite *player = spriteMgr->getPlayer();

		wstring playerState = player->getCurrentState();

		if (playerState.compare(L"PUNCH_LEFT") == 0 || playerState.compare(L"PUNCH_RIGHT") == 0
			|| playerState.compare(L"PUNCH_BACK") == 0 || playerState.compare(L"PUNCH_FRONT") == 0)
		{
			IXAudio2SourceVoice *punchSound = soundEffectMap[ENUM_SOUND_EFFECT_PUNCH];

			XAUDIO2_VOICE_STATE voiceState;
			punchSound->GetState(&voiceState);

			//// [voiceState.BuffersQueued <= 0] means there are nothing in the buffer
			//// so let's make a new buffer to queue the sound
			if (voiceState.BuffersQueued <= 0)
			{
				XAUDIO2_BUFFER *proto = audioBufferPrototypeMap[ENUM_SOUND_EFFECT_PUNCH];
				bool ssbSuccess = SUCCEEDED(punchSound->SubmitSourceBuffer(proto));
				punchSound->Start();
			}
			//// if there is something in the buffer
			else
			{
				/// do nothing
			}
		}
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:35,代码来源:GameAudio.cpp

示例2: processHealSound

void GameAudio::processHealSound()
{
	if (soundEffectRegistrationMap[ENUM_SOUND_EFFECT_HEAL] == true)
	{
		Game *game = Game::getSingleton();
		GameStateManager *gsm = game->getGSM();
		SpriteManager *spriteMgr = gsm->getSpriteManager();
		PlayerSprite *player = spriteMgr->getPlayer();

		bool isHealing = player->getIshealing();

		if (isHealing == true)
		{
			IXAudio2SourceVoice *healSound = soundEffectMap[ENUM_SOUND_EFFECT_HEAL];

			XAUDIO2_VOICE_STATE voiceState;
			healSound->GetState(&voiceState);

			//// [voiceState.BuffersQueued <= 0] means there are nothing in the buffer
			//// so let's make a new buffer to queue the sound
			if (voiceState.BuffersQueued <= 0)
			{
				XAUDIO2_BUFFER *proto = audioBufferPrototypeMap[ENUM_SOUND_EFFECT_HEAL];
				bool ssbSuccess = SUCCEEDED(healSound->SubmitSourceBuffer(proto));
				healSound->Start();
				//// After all, there will be only one buffer node in the queue always ...
			}
			//// if there is something in the buffer
			else
			{
				/// do nothing
			}
		}
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:35,代码来源:GameAudio.cpp

示例3: XAUDIO2_CloseDevice

static void
XAUDIO2_CloseDevice(_THIS)
{
    if (_this->hidden != NULL) {
        IXAudio2 *ixa2 = _this->hidden->ixa2;
        IXAudio2SourceVoice *source = _this->hidden->source;
        IXAudio2MasteringVoice *mastering = _this->hidden->mastering;

        if (source != NULL) {
			source->Stop();
            source->FlushSourceBuffers();
            source->DestroyVoice();
        }
        if (ixa2 != NULL) {
            ixa2->StopEngine();
        }
        if (mastering != NULL) {
            mastering->DestroyVoice();
        }
        if (ixa2 != NULL) {
            ixa2->Release();
        }
        SDL_free(_this->hidden->mixbuf);
        if (_this->hidden->semaphore != NULL) {
            CloseHandle(_this->hidden->semaphore);
        }

        SDL_free(_this->hidden);
        _this->hidden = NULL;
    }
}
开发者ID:langresser,项目名称:SDLWP8,代码行数:31,代码来源:SDL_xaudio2.cpp

示例4: stopMusic

void GameAudio::stopMusic(MusicTypes musicType)
{
	if (musicRegistrationMap[musicType] == true)
	{
		IXAudio2SourceVoice *sourceVoice = musicMap[musicType];
		sourceVoice->Stop();
		sourceVoice->FlushSourceBuffers();
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:9,代码来源:GameAudio.cpp

示例5: CreateFile

	bool Audio::AddAudioFile(const char* i_AudioPath, bool bLoop, float i_InitialVolume)
	{
		WAVEFORMATEXTENSIBLE wfx = { 0 };
		XAUDIO2_BUFFER buffer = { 0 };

		// Open the file
		HANDLE hFile = CreateFile(
			i_AudioPath,
			GENERIC_READ,
			FILE_SHARE_READ,
			NULL,
			OPEN_EXISTING,
			0,
			NULL);


		SetFilePointer(hFile, 0, NULL, FILE_BEGIN);

		DWORD dwChunkSize;
		DWORD dwChunkPosition;
		//check the file type, should be fourccWAVE or 'XWMA'
		FindChunk(hFile, fourccRIFF, dwChunkSize, dwChunkPosition);
		DWORD filetype;
		ReadChunkData(hFile, &filetype, sizeof(DWORD), dwChunkPosition);
		if (filetype != fourccWAVE)
			return false;

		FindChunk(hFile, fourccFMT, dwChunkSize, dwChunkPosition);
		ReadChunkData(hFile, &wfx, dwChunkSize, dwChunkPosition);

		//fill out the audio data buffer with the contents of the fourccDATA chunk
		FindChunk(hFile, fourccDATA, dwChunkSize, dwChunkPosition);
		BYTE * pDataBuffer = new BYTE[dwChunkSize];
		ReadChunkData(hFile, pDataBuffer, dwChunkSize, dwChunkPosition);

		buffer.AudioBytes = dwChunkSize;  //buffer containing audio data
		buffer.pAudioData = pDataBuffer;  //size of the audio buffer in bytes
		buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer
		if (bLoop)
		{
			buffer.LoopLength = 0;
			buffer.LoopCount = XAUDIO2_LOOP_INFINITE;
		}

		HRESULT hr;
		IXAudio2SourceVoice* pSourceVoice;
		if (FAILED(hr = s_pXAudio2->CreateSourceVoice(&pSourceVoice, (WAVEFORMATEX*)&wfx)))
			return false;

		if (FAILED(hr = pSourceVoice->SubmitSourceBuffer(&buffer)))
			return false;

		pSourceVoice->SetVolume(i_InitialVolume);

		s_SourceVoices.push_back(pSourceVoice);
		s_AudioBuffers.push_back(buffer);
	}
开发者ID:snkulkarni92,项目名称:CPPGameEngine,代码行数:57,代码来源:Audio.cpp

示例6: XAUDIO2_WaitDone

static void
XAUDIO2_WaitDone(_THIS)
{
    IXAudio2SourceVoice *source = _this->hidden->source;
    XAUDIO2_VOICE_STATE state;
    SDL_assert(!_this->enabled);  /* flag that stops playing. */
    source->Discontinuity();
    source->GetState(&state);
    while (state.BuffersQueued > 0) {
        WaitForSingleObjectEx(_this->hidden->semaphore, INFINITE, 0);
        source->GetState(&state);
    }
}
开发者ID:langresser,项目名称:SDLWP8,代码行数:13,代码来源:SDL_xaudio2.cpp

示例7: updateListener

void SoundManager::update(Camera* p_gameCamera)
{
	m_masterVoice->SetVolume(m_masterVolume,0);
	updateListener(p_gameCamera);

	X3DAudioCalculate(m_X3DAudioInstance, &m_listener, &m_music->getEmitter(),
		X3DAUDIO_CALCULATE_MATRIX, &m_music->getDSPSettings());

	IXAudio2SourceVoice* voice = m_music->getSource();
	m_left = m_matrixCoefficients[0];
	m_right = m_matrixCoefficients[1];
	voice->SetOutputMatrix( m_masterVoice, 1, m_destChannels, m_matrixCoefficients);

	if(!m_music->isPlaying())
		m_music->play();
}
开发者ID:jarllarsson,项目名称:PA2505-Stort-Spelprojekt-Prototyp,代码行数:16,代码来源:SoundManager.cpp

示例8: playMusicRepeat

void GameAudio::playMusicRepeat(MusicTypes musicType)
{
	if (musicRegistrationMap[musicType] == true)
	{
		IXAudio2SourceVoice *sourceVoice = musicMap[musicType];

		XAUDIO2_VOICE_STATE voiceState;
		sourceVoice->GetState(&voiceState);

		if (voiceState.BuffersQueued <= 0)
		{
			XAUDIO2_BUFFER *proto = musicBufferPrototypeMap[musicType];
			bool ssbSuccess = SUCCEEDED(sourceVoice->SubmitSourceBuffer(proto));
			sourceVoice->Start();
		}
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:17,代码来源:GameAudio.cpp

示例9: processMoneySound

void GameAudio::processMoneySound()
{
	if (soundEffectRegistrationMap[ENUM_SOUND_EFFECT_MONEY] == true)
	{
		if (moneySoundSignal == true)
		{
			IXAudio2SourceVoice *moneySound = soundEffectMap[ENUM_SOUND_EFFECT_MONEY];

			XAUDIO2_VOICE_STATE voiceState;
			moneySound->GetState(&voiceState);

			XAUDIO2_BUFFER *proto = audioBufferPrototypeMap[ENUM_SOUND_EFFECT_MONEY];
			bool ssbSuccess = SUCCEEDED(moneySound->SubmitSourceBuffer(proto));
			moneySound->Start();

			moneySoundSignal = false;
		}
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:19,代码来源:GameAudio.cpp

示例10: playMusicOnce

void GameAudio::playMusicOnce(MusicTypes musicType)
{
	if (musicRegistrationMap[musicType] == true)
	{
		IXAudio2SourceVoice *sourceVoice = musicMap[musicType];

		XAUDIO2_VOICE_STATE voiceState;
		sourceVoice->GetState(&voiceState);

		if (musicType == ENUM_MUSIC_LEVEL_COMPLETE)
		{
			if (levelCompleteMusicBuffered == false)
			{
				XAUDIO2_BUFFER *proto = musicBufferPrototypeMap[musicType];
				bool ssbSuccess = SUCCEEDED(sourceVoice->SubmitSourceBuffer(proto));
				sourceVoice->Start();
				levelCompleteMusicBuffered = true;
			}
		}

		/// here put the game over music
		else if (musicType == ENUM_MUSIC_GAMEOVER)
		{
			if (gameOverMusicBuffered == false)
			{
				XAUDIO2_BUFFER *proto = musicBufferPrototypeMap[musicType];
				bool ssbSuccess = SUCCEEDED(sourceVoice->SubmitSourceBuffer(proto));
				sourceVoice->Start();
				gameOverMusicBuffered = true;
			}
		}
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:33,代码来源:GameAudio.cpp

示例11: XAUDIO2_PlayDevice

static void
XAUDIO2_PlayDevice(_THIS)
{
    XAUDIO2_BUFFER buffer;
    Uint8 *mixbuf = _this->hidden->mixbuf;
    Uint8 *nextbuf = _this->hidden->nextbuf;
    const int mixlen = _this->hidden->mixlen;
    IXAudio2SourceVoice *source = _this->hidden->source;
    HRESULT result = S_OK;

    if (!_this->enabled) { /* shutting down? */
        return;
    }

    /* Submit the next filled buffer */
    SDL_zero(buffer);
    buffer.AudioBytes = mixlen;
    buffer.pAudioData = nextbuf;
    buffer.pContext = _this;
	buffer.LoopCount = 1;

    if (nextbuf == mixbuf) {
        nextbuf += mixlen;
    } else {
        nextbuf = mixbuf;
    }
    _this->hidden->nextbuf = nextbuf;

    result = source->SubmitSourceBuffer(&buffer);
    if (result == XAUDIO2_E_DEVICE_INVALIDATED) {
        /* !!! FIXME: possibly disconnected or temporary lost. Recover? */
    }

    if (result != S_OK) {  /* uhoh, panic! */
         source->FlushSourceBuffers();
         _this->enabled = 0;
    }
}
开发者ID:langresser,项目名称:SDLWP8,代码行数:38,代码来源:SDL_xaudio2.cpp

示例12: open

	virtual const char* write_frame( void * buffer, unsigned num_samples, bool wait )
	{
		if ( paused )
		{
			if ( wait ) Sleep( MulDiv( num_samples / nch, 1000, sample_rate ) );
			return 0;
		}

		if ( reopen_count )
		{
			if ( ! --reopen_count )
			{
				const char * err = open( hwnd, sample_rate, nch, max_samples_per_frame, num_frames );
				if ( err )
				{
					reopen_count = 60 * 5;
					return err;
				}
			}
			else
			{
				if ( wait ) Sleep( MulDiv( num_samples / nch, 1000, sample_rate ) );
				return 0;
			}
		}

		for (;;) {
			sVoice->GetState( &vState );
			assert( vState.BuffersQueued <= num_frames );
			if( vState.BuffersQueued < num_frames ) {
				if( vState.BuffersQueued == 0 ) {
					// buffers ran dry
				}
				// there is at least one free buffer
				break;
			} else {
				// wait for one buffer to finish playing
				ResetEvent( notify.hBufferEndEvent );
				WaitForSingleObject( notify.hBufferEndEvent, INFINITE );
			}
		}
		samples_in_buffer[ buffer_write_cursor ] = num_samples / nch;
		XAUDIO2_BUFFER buf = {0};
		unsigned num_bytes = num_samples * 2;
		buf.AudioBytes = num_bytes;
		buf.pAudioData = ( const BYTE * )( sample_buffer + max_samples_per_frame * buffer_write_cursor );
		buf.pContext = this;
		buffer_write_cursor = ( buffer_write_cursor + 1 ) % num_frames;
		memcpy( ( void * ) buf.pAudioData, buffer, num_bytes );
		if( sVoice->SubmitSourceBuffer( &buf ) == S_OK )
		{
			InterlockedIncrement( &buffered_count );
			return 0;
		}

		close();
		reopen_count = 60 * 5;

		return 0;
	}
开发者ID:Starscreamss,项目名称:pj64,代码行数:60,代码来源:sound_out_xaudio2.cpp

示例13:

void XAudio2_Output::close()
{
	initialized = false;

	if( sVoice ) {
		if( playing ) {
			HRESULT hr = sVoice->Stop( 0 );
			ASSERT( hr == S_OK );
		}
		sVoice->DestroyVoice();
		sVoice = NULL;
	}

	if( buffers ) {
		free( buffers );
		buffers = NULL;
	}

	if( mVoice ) {
		mVoice->DestroyVoice();
		mVoice = NULL;
	}

	if( xaud ) {
		xaud->Release();
		xaud = NULL;
	}
}
开发者ID:RetroAchievements,项目名称:RASuite,代码行数:28,代码来源:XAudio2.cpp

示例14: pause

	virtual const char* pause( bool pausing )
	{
		if ( pausing )
		{
			if ( ! paused )
			{
				paused = true;
				HRESULT hr = sVoice->Stop( 0 );
				if ( FAILED(hr) )
				{
					close();
					reopen_count = 60 * 5;
				}
			}
		}
		else
		{
			if ( paused )
			{
				paused = false;
				HRESULT hr = sVoice->Start( 0 );
				if ( FAILED(hr) )
				{
					close();
					reopen_count = 60 * 5;
				}
			}
		}

		return 0;
	}
开发者ID:Starscreamss,项目名称:pj64,代码行数:31,代码来源:sound_out_xaudio2.cpp

示例15: enough

void XAudio2_Output::write(u16 * finalWave, int length)
{
	if( !initialized || failed ) return;

	while( true ) {
		if ( device_changed ) {
			close();
			if (!init(freq)) return;
		}

		sVoice->GetState( &vState );

		ASSERT( vState.BuffersQueued <= bufferCount );

		if( vState.BuffersQueued < bufferCount ) {
			if( vState.BuffersQueued == 0 ) {
				// buffers ran dry
				if( systemVerbose & VERBOSE_SOUNDOUTPUT ) {
					static unsigned int i = 0;
					log( "XAudio2: Buffers were not refilled fast enough (i=%i)\n", i++ );
				}
			}
			// there is at least one free buffer
			break;
		} else {
			// the maximum number of buffers is currently queued
			if( synchronize && !speedup && !theApp.throttle ) {
				// wait for one buffer to finish playing
				if (WaitForSingleObject( notify.hBufferEndEvent, 10000 ) == WAIT_TIMEOUT) {
					device_changed = true;
				}
			} else {
				// drop current audio frame
				return;
			}
		}
	}

	// copy & protect the audio data in own memory area while playing it
	CopyMemory( &buffers[ currentBuffer * soundBufferLen ], finalWave, soundBufferLen );

	buf.AudioBytes = soundBufferLen;
	buf.pAudioData = &buffers[ currentBuffer * soundBufferLen ];

	currentBuffer++;
	currentBuffer %= ( bufferCount + 1 ); // + 1 because we need one temporary buffer

	HRESULT hr = sVoice->SubmitSourceBuffer( &buf ); // send buffer to queue
	ASSERT( hr == S_OK );
}
开发者ID:RetroAchievements,项目名称:RASuite,代码行数:50,代码来源:XAudio2.cpp


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