コード例 #1
0
DWORD WINAPI MixAudio(LPVOID lpParameter )
{
	const int BUFFER_SIZE = 4096;
	const int NUM_BUFFERS = 8;
	char* pcm = new char[BUFFER_SIZE];
	ALuint buffers[NUM_BUFFERS];
	ALuint source;
	int size;

	alGenBuffers(NUM_BUFFERS, buffers);
	alGenSources(1, &source);

	for(int i=0;i<NUM_BUFFERS;i++){
		size = g_ogg.audio_read(pcm,BUFFER_SIZE);
		alBufferData(buffers[i], AL_FORMAT_STEREO16, pcm, size, 44100);
	}
	alSourceQueueBuffers(source, NUM_BUFFERS, buffers);
	alSourcePlay(source);
	while(g_ogg.playing())
	{
		int processed;
		alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
		
		while((processed--)>0)
		{
			ALuint buffer;
			alSourceUnqueueBuffers(source, 1, &buffer);
			size = g_ogg.audio_read(pcm,BUFFER_SIZE);
			if(size>0)
				alBufferData(buffer, AL_FORMAT_STEREO16, pcm, size, 44100);
			alSourceQueueBuffers(source, 1, &buffer);
			ALenum state;
			alGetSourcei(source, AL_SOURCE_STATE, &state);
			if(state!=AL_PLAYING)
				alSourcePlay(source);
		}
		Sleep(5);
	}
	alSourceStop(source);
	alDeleteSources(1, &source);
	alDeleteBuffers(NUM_BUFFERS, buffers);
	delete [] pcm;
	return 0;
}
コード例 #2
0
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
	g_ogg.open("../sample video/trailer_400p.ogg",AF_S16,2,44100,VF_BGRA);
	if(g_ogg.fail()) {
		return -1;
	}

	// Register the window class
	WNDCLASSEX wc =
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		L"liboggstream", NULL
	};

	RegisterClassEx( &wc );


	int width=g_ogg.width();
	int height=g_ogg.height();
	// Create the application's window
	RECT rect;
	rect.left = 100;
	rect.top = 100;
	rect.right = width+rect.left;
	rect.bottom = height+rect.top;
	AdjustWindowRect(&rect,WS_OVERLAPPEDWINDOW,FALSE);
	HWND hWnd = CreateWindow( L"liboggstream", L"D3D9 Theora Player",
		WS_OVERLAPPEDWINDOW, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
		NULL, NULL, wc.hInstance, NULL );

	// Initialize Direct3D and OpenAL
	if( SUCCEEDED( InitD3D( hWnd ) ) && InitAL())
	{
		// Show the window
		ShowWindow( hWnd, SW_SHOWDEFAULT );
		UpdateWindow( hWnd );
		// Start the playback
		g_ogg.play();
		// Run MixAudio in another thread
		HANDLE h_mixaudio= CreateThread(NULL,0,MixAudio,NULL,0,NULL);
		// Enter the message loop
		MSG msg;
		ZeroMemory( &msg, sizeof( msg ) );
		while( msg.message != WM_QUIT && g_ogg.playing() )
		{
			if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}else {
				Render();
				Sleep(0);
			}
		}
		g_ogg.close();
		WaitForSingleObject(h_mixaudio,INFINITE);
		alutExit();
	}

	UnregisterClass( L"liboggstream", wc.hInstance );
	return 0;
}