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


C++ IXAudio2SourceVoice::SubmitSourceBuffer方法代码示例

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


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

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

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

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

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

示例5: AddAudioFile

	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:

void StreamingVoiceContext2_7::SubmitBuffer(PBYTE buf_data)
{
	XAUDIO2_BUFFER buf = {};
	buf.AudioBytes = BUFFER_SIZE_BYTES;
	buf.pContext = buf_data;
	buf.pAudioData = buf_data;

	m_source_voice->SubmitSourceBuffer(&buf);
}
开发者ID:albertofem,项目名称:dolphin,代码行数:9,代码来源:XAudio2_7Stream.cpp

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

示例8: SubmitBuffer

	HRESULT SubmitBuffer()
	{
		// Ensure we do have a valid voice
		if (this->SourceVoice == nullptr)
		{
			return E_FAIL;
		}

		MxMixSamples(this->buffer, this->bufferLength / 4);

		XAUDIO2_BUFFER buf = { 0 };
		buf.AudioBytes = this->bufferLength;
		buf.pAudioData = (const BYTE *) this->buffer;

		return SourceVoice->SubmitSourceBuffer(&buf);
	}
开发者ID:IchiroWang,项目名称:OpenTTD,代码行数:16,代码来源:xaudio2_s.cpp

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

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

示例11:

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: memcpy

void XAudio2Streamer::Stream( void const *pSamples )
{
    // Verify buffer availability
    XAUDIO2_VOICE_STATE xa2vs;
    m_pXAudio2SourceVoice->GetState( &xa2vs );
    if( xa2vs.BuffersQueued == m_count )
        return;

    // Copy samples to buffer
    Sample *pBuffer( &m_samples[ m_index * m_size ] );
    using std::memcpy;
    memcpy( pBuffer, pSamples, m_size );

    // Submit buffer to voice
    XAUDIO2_BUFFER xa2b = {};
    xa2b.AudioBytes = UINT32( m_size );
    xa2b.pAudioData = pBuffer;
    if( FAILED( m_pXAudio2SourceVoice->SubmitSourceBuffer( &xa2b ) ) )
        return;

    // Select next buffer
    m_index = ( m_index + 1 ) % m_count;
}
开发者ID:fesh0r,项目名称:beebem,代码行数:23,代码来源:beebsound.cpp

示例13: exception

void WaveBank::Impl::Play( int index )
{
    if ( mStreaming )
    {
        DebugTrace( "ERROR: One-shots can only be created from an in-memory wave bank\n");
        throw std::exception( "WaveBank::Play" );
    }

    if ( index < 0 || uint32_t(index) >= mReader.Count() )
    {
        DebugTrace( "WARNING: Index %d not found in wave bank with only %u entries, one-shot not triggered\n", index, mReader.Count() );
        return;
    }

    if ( !mPrepared )
    {
        mReader.WaitOnPrepare();
        mPrepared = true;
    }

    char wfxbuff[64];
    auto wfx = reinterpret_cast<WAVEFORMATEX*>( wfxbuff );
    HRESULT hr = mReader.GetFormat( index, wfx, 64 );
    ThrowIfFailed( hr );

    IXAudio2SourceVoice* voice = nullptr;
    mEngine->AllocateVoice( wfx, SoundEffectInstance_Default, true, &voice );

    if ( !voice )
        return;

    hr = voice->Start( 0 );
    ThrowIfFailed( hr );

    XAUDIO2_BUFFER buffer;
    memset( &buffer, 0, sizeof(buffer) );

    hr = mReader.GetWaveData( index, &buffer.pAudioData, buffer.AudioBytes );
    ThrowIfFailed( hr );

    WaveBankReader::Metadata metadata;
    hr = mReader.GetMetadata( index, metadata );
    ThrowIfFailed( hr );

    buffer.Flags = XAUDIO2_END_OF_STREAM;
    buffer.pContext = this;

#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8)

    XAUDIO2_BUFFER_WMA wmaBuffer;
    memset( &wmaBuffer, 0, sizeof(wmaBuffer) );

    uint32_t tag;
    hr = mReader.GetSeekTable( index, &wmaBuffer.pDecodedPacketCumulativeBytes, wmaBuffer.PacketCount, tag );
    ThrowIfFailed( hr );

    if ( tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3 )
    {
        hr = voice->SubmitSourceBuffer( &buffer, &wmaBuffer );
    }
    else
#endif
    {
        hr = voice->SubmitSourceBuffer( &buffer, nullptr );
    }
    if ( FAILED(hr) )
    {
        DebugTrace( "ERROR: WaveBank failed (%08X) when submitting buffer:\n", hr );
        DebugTrace( "\tFormat Tag %u, %u channels, %u-bit, %u Hz, %u bytes\n", wfx->wFormatTag, 
                    wfx->nChannels, wfx->wBitsPerSample, wfx->nSamplesPerSec, metadata.lengthBytes );
        throw std::exception( "SubmitSourceBuffer" );
    }

    InterlockedIncrement( &mOneShots );
}
开发者ID:bretthuff22,项目名称:Animation,代码行数:75,代码来源:WaveBank.cpp

示例14: PlayWaveFromWaveBank

//--------------------------------------------------------------------------------------
// Name: PlayWaveFromWaveBank
// Desc: Plays a wave and blocks until the wave finishes playing
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PlayWaveFromWaveBank( IXAudio2* pXaudio2, WaveBankReader& wb, uint32_t index )
{
    if ( index >= wb.Count() )
        return E_INVALIDARG;

    uint8_t waveFormat[64];
    auto pwfx = reinterpret_cast<WAVEFORMATEX*>( &waveFormat );

    HRESULT hr = wb.GetFormat( index, pwfx, 64 );
    if ( FAILED(hr) )
        return hr;

    const uint8_t* waveData = nullptr;
    uint32_t waveSize;

    hr = wb.GetWaveData( index, &waveData, waveSize );
    if ( FAILED(hr) )
        return hr;

    WaveBankReader::Metadata metadata;
    hr = wb.GetMetadata( index, metadata );
    if ( FAILED(hr) )
        return hr;

    //
    // Play the wave using a XAudio2SourceVoice
    //

    // Create the source voice
    IXAudio2SourceVoice* pSourceVoice;
    if( FAILED( hr = pXaudio2->CreateSourceVoice( &pSourceVoice, pwfx ) ) )
    {
        wprintf( L"Error %#X creating source voice\n", hr );
        return hr;
    }

    // Submit the wave sample data using an XAUDIO2_BUFFER structure
    XAUDIO2_BUFFER buffer = {0};
    buffer.pAudioData = waveData;
    buffer.Flags = XAUDIO2_END_OF_STREAM;  // tell the source voice not to expect any data after this buffer
    buffer.AudioBytes = waveSize;

    if ( metadata.loopLength > 0 && metadata.loopLength != metadata.duration )
    {
        buffer.LoopBegin = metadata.loopStart;
        buffer.LoopLength = metadata.loopLength;
        buffer.LoopCount = 1; // We'll just assume we play the loop twice
    }

    const uint32_t* seekTable;
    uint32_t seekTableCount;
    uint32_t tag;
    hr = wb.GetSeekTable( index, &seekTable, seekTableCount, tag );

    if ( seekTable )
    {
        if ( tag == WAVE_FORMAT_WMAUDIO2 || tag == WAVE_FORMAT_WMAUDIO3 )
        {
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ )
            XAUDIO2_BUFFER_WMA xwmaBuffer = {0};
            xwmaBuffer.pDecodedPacketCumulativeBytes = seekTable;
            xwmaBuffer.PacketCount = seekTableCount;
            if( FAILED( hr = pSourceVoice->SubmitSourceBuffer( &buffer, &xwmaBuffer ) ) )
            {
                wprintf( L"Error %#X submitting source buffer (xWMA)\n", hr );
                pSourceVoice->DestroyVoice();
                return hr;
            }
#else
            wprintf( L"This platform does not support xWMA\n" );
            pSourceVoice->DestroyVoice();
            return hr;
#endif
        }
        else if ( tag == 0x166 /* WAVE_FORMAT_XMA2 */ )
        {
            wprintf( L"This platform does not support XMA2\n" );
            pSourceVoice->DestroyVoice();
            return hr;
        }
    }
    else if( FAILED( hr = pSourceVoice->SubmitSourceBuffer( &buffer ) ) )
    {
        wprintf( L"Error %#X submitting source buffer\n", hr );
        pSourceVoice->DestroyVoice();
        return hr;
    }

    hr = pSourceVoice->Start( 0 );

    // Let the sound play
    BOOL isRunning = TRUE;
    while( SUCCEEDED( hr ) && isRunning )
    {
        XAUDIO2_VOICE_STATE state;
//.........这里部分代码省略.........
开发者ID:AndreAhmed,项目名称:directx-sdk-samples,代码行数:101,代码来源:XAudio2WaveBank.cpp

示例15: PlayWave

//--------------------------------------------------------------------------------------
// Name: PlayWave
// Desc: Plays a wave and blocks until the wave finishes playing
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PlayWave( IXAudio2* pXaudio2, LPCWSTR szFilename )
{
    //
    // Locate the wave file
    //
    WCHAR strFilePath[MAX_PATH];
    HRESULT hr = FindMediaFileCch( strFilePath, MAX_PATH, szFilename );
    if( FAILED( hr ) )
    {
        wprintf( L"Failed to find media file: %s\n", szFilename );
        return hr;
    }

    //
    // Read in the wave file
    //
    std::unique_ptr<uint8_t[]> waveFile;
    DirectX::WAVData waveData;
    if ( FAILED( hr = DirectX::LoadWAVAudioFromFileEx( strFilePath, waveFile, waveData ) ) )
    {
        wprintf( L"Failed reading WAV file: %#X (%s)\n", hr, strFilePath );
        return hr;
    }

    //
    // Play the wave using a XAudio2SourceVoice
    //

    // Create the source voice
    IXAudio2SourceVoice* pSourceVoice;
    if( FAILED( hr = pXaudio2->CreateSourceVoice( &pSourceVoice, waveData.wfx ) ) )
    {
        wprintf( L"Error %#X creating source voice\n", hr );
        return hr;
    }

    // Submit the wave sample data using an XAUDIO2_BUFFER structure
    XAUDIO2_BUFFER buffer = {0};
    buffer.pAudioData = waveData.startAudio;
    buffer.Flags = XAUDIO2_END_OF_STREAM;  // tell the source voice not to expect any data after this buffer
    buffer.AudioBytes = waveData.audioBytes;

    if ( waveData.loopLength > 0 )
    {
        buffer.LoopBegin = waveData.loopStart;
        buffer.LoopLength = waveData.loopLength;
        buffer.LoopCount = 1; // We'll just assume we play the loop twice
    }

#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ )
    if ( waveData.seek )
    {
        XAUDIO2_BUFFER_WMA xwmaBuffer = {0};
        xwmaBuffer.pDecodedPacketCumulativeBytes = waveData.seek;
        xwmaBuffer.PacketCount = waveData.seekCount;
        if( FAILED( hr = pSourceVoice->SubmitSourceBuffer( &buffer, &xwmaBuffer ) ) )
        {
            wprintf( L"Error %#X submitting source buffer (xWMA)\n", hr );
            pSourceVoice->DestroyVoice();
            return hr;
        }
    }
#else
    if ( waveData.seek )
    {
        wprintf( L"This platform does not support xWMA or XMA2\n" );
        pSourceVoice->DestroyVoice();
        return hr;
    }
#endif
    else if( FAILED( hr = pSourceVoice->SubmitSourceBuffer( &buffer ) ) )
    {
        wprintf( L"Error %#X submitting source buffer\n", hr );
        pSourceVoice->DestroyVoice();
        return hr;
    }

    hr = pSourceVoice->Start( 0 );

    // Let the sound play
    BOOL isRunning = TRUE;
    while( SUCCEEDED( hr ) && isRunning )
    {
        XAUDIO2_VOICE_STATE state;
        pSourceVoice->GetState( &state );
        isRunning = ( state.BuffersQueued > 0 ) != 0;

        // Wait till the escape key is pressed
        if( GetAsyncKeyState( VK_ESCAPE ) )
            break;

        Sleep( 10 );
    }

    // Wait till the escape key is released
//.........这里部分代码省略.........
开发者ID:AndreAhmed,项目名称:directx-sdk-samples,代码行数:101,代码来源:XAudio2BasicSound.cpp


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