Exemplo n.º 1
0
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;
	}
}
Exemplo n.º 2
0
	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;
	}
Exemplo n.º 3
0
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;
    }
}
Exemplo n.º 4
0
void GameAudio::stopMusic(MusicTypes musicType)
{
	if (musicRegistrationMap[musicType] == true)
	{
		IXAudio2SourceVoice *sourceVoice = musicMap[musicType];
		sourceVoice->Stop();
		sourceVoice->FlushSourceBuffers();
	}
}
Exemplo n.º 5
0
void XAudio2_Output::pause()
{
	if( !initialized || failed ) return;

	if( playing ) {
		HRESULT hr = sVoice->Stop( 0 );
		ASSERT( hr == S_OK );
		playing = false;
	}
}
Exemplo n.º 6
0
void XAudio2_Output::reset()
{
	if( !initialized || failed ) return;

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

	sVoice->FlushSourceBuffers();
	sVoice->Start( 0 );
	playing = true;
}
Exemplo n.º 7
0
	void close()
	{
		if( sVoice ) {
			if( !paused ) {
				sVoice->Stop( 0 );
			}
			sVoice->DestroyVoice();
		}

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

		if( xaud ) {
			xaud->Release();
			xaud = NULL;
		}

		delete [] sample_buffer;
		sample_buffer = NULL;
		delete [] samples_in_buffer;
		samples_in_buffer = NULL;
	}
Exemplo n.º 8
0
void StreamingVoiceContext2_7::Stop()
{
	if (m_source_voice)
		m_source_voice->Stop();
}
Exemplo n.º 9
0
//the streaming thread procedure
DWORD WINAPI StreamProc(LPVOID pContext)
{
	//required by XAudio2
	CoInitializeEx(NULL, COINIT_MULTITHREADED);

	if(pContext == NULL)
	{
		CoUninitialize();
		return -1;
	}

	StreamContext* sc = (StreamContext*)pContext;

	//instantiate the voice's callback class
	StreamingVoiceCallback callback;

	//load a file for streaming, non-buffered disk reads (no system cacheing)
	StreamingWave inFile;
	if(!inFile.load(sc->filename))
	{
		SetEvent(sc->VoiceLoadEvent);
		CoUninitialize();
		return -3;
	}

	//create the voice
	IXAudio2SourceVoice* source = NULL;
	if(FAILED(XAudio2->CreateSourceVoice(&source, &inFile.waveFormat.Format, 0, 2.0f, &callback)))
	{
		SetEvent(sc->VoiceLoadEvent);
		CoUninitialize();
		return -5;
	}

	//fill and queue the maximum number of buffers (except the one needed for reading new wave data)
	bool somethingsWrong = false;
	XAUDIO2_VOICE_STATE voiceState = {0};
	source->GetState(&voiceState);
	while(voiceState.BuffersQueued < STREAMINGWAVE_BUFFER_COUNT - 1 && !somethingsWrong)
	{
		//read and fill the next buffer to present
		switch(inFile.prepare())
		{
		case StreamingWave::PR_EOF:
			//if end of file, loop the file read
			inFile.resetFile(); //intentionally fall-through to loop sound
		case StreamingWave::PR_SUCCESS:
			//present the next available buffer
			inFile.swap();
			//submit another buffer
			source->SubmitSourceBuffer(inFile.buffer());
			source->GetState(&voiceState);
			break;
		case StreamingWave::PR_FAILURE:
			somethingsWrong = true;
			break;
		}
	}

	//return the created voice through the context pointer
	sc->pVoice = &source;

	//signal that the voice has prepared for streaming, and ready to start
	SetEvent(sc->VoiceLoadEvent);

	//group the events for the Wait function
	HANDLE Events[2] = {callback.BufferEndEvent, QuitEvent};

	bool quitting = false;
	while(!quitting)
	{
		//wait until either the source voice is ready for another buffer, or the abort signal is set
		DWORD eventFired = WaitForMultipleObjects(2, Events, FALSE, INFINITE);
		switch(eventFired)
		{
		case 0: //buffer ended event for source voice
			//reset the event manually
			ResetEvent(Events[0]);

			//make sure there's a full number of buffers
			source->GetState(&voiceState);
			while(voiceState.BuffersQueued < STREAMINGWAVE_BUFFER_COUNT - 1 && !somethingsWrong)
			{
				//read and fill the next buffer to present
				switch(inFile.prepare())
				{
				case StreamingWave::PR_EOF:
					//if end of file, loop the file read
					inFile.resetFile();	//intentionally fall-through to loop sound
				case StreamingWave::PR_SUCCESS:
					//present the next available buffer
					inFile.swap();
					//submit another buffer
					source->SubmitSourceBuffer(inFile.buffer());
					source->GetState(&voiceState);
					break;
				case StreamingWave::PR_FAILURE:
					somethingsWrong = true;
					break;
				}
			}
			break;
		default: //something's wrong...
			quitting = true;
		}
	}

	//stop and destroy the voice
	source->Stop();
	source->FlushSourceBuffers();
	source->DestroyVoice();

	//close the streaming wave file;
	//this is done automatically in the class destructor,
	//so this is redundant
	inFile.close();

	//cleanup
	CoUninitialize();
	return 0;
}