00001
00002 #include "Core/precomp.h"
00003
00004 #include <iostream>
00005 #include "API/Core/Display/display.h"
00006 #include "API/Core/System/clanapp.h"
00007 #include "soundbuffer_static_dx.h"
00008 #include "soundbuffer_stream_dx.h"
00009 #include "Core/Sound/Generic/cardsession_manager.h"
00010 #include "soundcard_dx.h"
00011 #include "Core/System/Win32/init_win32.h"
00012 #include "Core/Display/DirectDraw/displaycard_win32compatible.h"
00013
00014
00015
00016
00017
00018 CL_SoundCard_DX::CL_SoundCard_DX(int _card_no, std::string _name, LPGUID _guid)
00019 {
00020 card_no = _card_no;
00021 name = _name;
00022 is_initialized = false;
00023 guid = _guid;
00024 soundcard_enabled = false;
00025 soundcard = NULL;
00026 }
00027
00028 CL_SoundCard_DX::~CL_SoundCard_DX()
00029 {
00030 manager->remove_all_playbacks();
00031 if (soundcard != NULL)
00032 {
00033 soundcard->Release();
00034 }
00035 }
00036
00037 extern LONG WINAPI MainMessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
00038
00039 void CL_SoundCard_DX::init_directsound()
00040 {
00041 HRESULT err;
00042 err = DirectSoundCreate(guid, &soundcard, NULL);
00043 if (err != DS_OK) { std::cout << "Failed to create " << name.c_str() << std::endl; soundcard = NULL; }
00044 else
00045 {
00046 HWND hwnd = NULL;
00047 if (CL_Display::cards.size() > 0)
00048 {
00049 hwnd = ((CL_DisplayCard_Win32Compatible *) CL_Display::cards[0])->get_hwnd();
00050 if (hwnd == NULL)
00051 {
00052 ((CL_DisplayCard_Win32Compatible *) CL_Display::cards[0])->create_window(640, 480, 16, false, true);
00053 hwnd = ((CL_DisplayCard_Win32Compatible *) CL_Display::cards[0])->get_hwnd();
00054 }
00055 }
00056 else
00057 {
00058 WNDCLASS wndclass;
00059
00060 wndclass.style = 0;
00061 wndclass.lpfnWndProc = (WNDPROC) MainMessageHandler;
00062 wndclass.cbClsExtra = 0;
00063 wndclass.cbWndExtra = 0;
00064 wndclass.hInstance = CL_System_Win32::hInstance;
00065 wndclass.hIcon = NULL;
00066 wndclass.hCursor = LoadCursor (NULL,IDC_ARROW);
00067 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
00068 wndclass.lpszMenuName = CL_ClanApplication::app->get_title();
00069 wndclass.lpszClassName = CL_ClanApplication::app->get_title();
00070
00071 if (RegisterClass(&wndclass) != 0)
00072 {
00073 hwnd = CreateWindow(
00074 CL_ClanApplication::app->get_title(),
00075 CL_ClanApplication::app->get_title(),
00076 WS_POPUP ,
00077 0,
00078 0,
00079 1,
00080 1,
00081 NULL,
00082 NULL,
00083 CL_System_Win32::hInstance,
00084 NULL);
00085 }
00086 }
00087 if (hwnd == NULL)
00088 {
00089 soundcard->Release();
00090 soundcard = NULL;
00091 return;
00092 }
00093
00094 err = soundcard->SetCooperativeLevel(hwnd, DSSCL_NORMAL);
00095 if (err != DS_OK)
00096 {
00097 std::cout << "Failed to create " << name.c_str() << std::endl;
00098 soundcard->Release();
00099 soundcard = NULL;
00100 }
00101 else soundcard_enabled = true;
00102 }
00103
00104 is_initialized = true;
00105 }
00106
00107 CL_CardSoundBuffer_Static *CL_SoundCard_DX::create_soundbuffer_static(
00108 CL_SoundBuffer_Generic *owner,
00109 CL_StaticSoundProvider *provider)
00110 {
00111 if (!is_initialized) init_directsound();
00112
00113 return new CL_CardSoundBufferStatic_DX(this, owner, provider);
00114 }
00115
00116 CL_CardSoundBuffer_Playback *CL_SoundCard_DX::create_cardsoundbuffer_playback_streamed(
00117 CL_SoundBuffer_Generic_Stream *soundbuffer)
00118 {
00119 if (!is_initialized) init_directsound();
00120
00121 return new CL_CardSoundBufferPlaybackStream_DX(this, soundbuffer);
00122 }