home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************\
- Copyright (C) James Boer, 2002.
- All rights reserved worldwide.
-
- This software is provided "as is" without express or implied
- warranties. You may freely copy and compile this source into
- applications you distribute provided that the copyright text
- below is included in the resulting source code, for example:
- "Portions Copyright (C) James Boer, 2002"
- \***********************************************************/
-
- #include "stdafx.h"
- #include "AudioTest.h"
- #include "System.h"
-
- #include "Audio.h"
-
- #include "AudioTestDlg.h"
- #include "Sound2D.h"
- #include "Sound3D.h"
- #include "Segment.h"
- #include "SoundScript.h"
- #include "MusicScript.h"
-
- using namespace Audio;
-
- const int STATS_TIMER = 1;
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CSystem property page
-
- IMPLEMENT_DYNCREATE(CSystem, CPropertyPage)
-
- CSystem::CSystem() : CPropertyPage(CSystem::IDD)
- {
- //{{AFX_DATA_INIT(CSystem)
- //}}AFX_DATA_INIT
- m_nSoundVolumeUpdateTimer = 0;
- m_nMusicVolumeUpdateTimer = 0;
- }
-
- CSystem::~CSystem()
- {
- }
-
- void CSystem::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSystem)
- DDX_Control(pDX, IDC_SYSTEM_CACHE_BUFFERS, m_CacheBuffers);
- DDX_Control(pDX, IDC_SYSTEM_AUTO_STREAM, m_AutoStream);
- DDX_Control(pDX, IDC_SYSTEM_USE_ZOOMFX, m_UseZoomFX);
- DDX_Control(pDX, IDC_SYSTEM_USE_EAX, m_UseEAX);
- DDX_Control(pDX, IDC_EDIT_FORCE_2D_SOFTWARE, m_Force2DSoftware);
- DDX_Control(pDX, IDC_EDIT_FORCE_3D_SOFTWARE, m_Force3DSoftware);
- DDX_Control(pDX, IDC_EDIT_LOADED_SEGMENTS, m_SegmentsLoaded);
- DDX_Control(pDX, IDC_EDIT_LOADED_3D, m_3DLoaded);
- DDX_Control(pDX, IDC_EDIT_LOADED_2D, m_2DLoaded);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_SEGMENTMAX, m_SegmentMax);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_3DSWBUFFERMAX, m_3DSoftwareBufferMax);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_3DHWBUFFERMIN, m_3DHardwareBufferMin);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_3DHWBUFFERMAX, m_3DHardwareBufferMax);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_2DSWBUFFERMAX, m_2DSoftwareBufferMax);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_2DHWBUFFERMIN, m_2DHardwareBufferMin);
- DDX_Control(pDX, IDC_SPIN_SYSTEM_2DHWBUFFERMAX, m_2DHardwareBufferMax);
- DDX_Control(pDX, IDC_COMBO_OPTIMAL_RATE, m_OptimalRate);
- DDX_Control(pDX, IDC_SYSTEM_USEMUSICREVERB, m_UseMusicReverb);
- DDX_Control(pDX, IDC_SYSTEM_LOADASYNC, m_LoadAsync);
- DDX_Control(pDX, IDC_SYSTEM_FORCESOFTWARE, m_ForceSoftware);
- DDX_Control(pDX, IDC_SLIDER_SOUND, m_SoundVolume);
- DDX_Control(pDX, IDC_SLIDER_MUSIC, m_MusicVolume);
- DDX_Control(pDX, IDC_PAUSEALL, m_PauseAll);
- DDX_Control(pDX, IDC_STOPALL, m_StopAll);
- DDX_Control(pDX, IDC_RESUMEALL, m_ResumeAll);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CSystem, CPropertyPage)
- //{{AFX_MSG_MAP(CSystem)
- ON_BN_CLICKED(IDC_INITIALIZE, OnInitialize)
- ON_BN_CLICKED(IDC_TERM, OnTerm)
- ON_BN_CLICKED(IDC_RESUMEALL, OnResumeall)
- ON_BN_CLICKED(IDC_PAUSEALL, OnPauseall)
- ON_BN_CLICKED(IDC_STOPALL, OnStopall)
- ON_WM_TIMER()
- ON_WM_HSCROLL()
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSystem message handlers
-
- BOOL CSystem::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- m_hFont = GetStockObject(DEFAULT_GUI_FONT);
-
- // Load the play button icons
- m_hPlayIcon = LoadIcon(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_PLAY));
- m_hPauseIcon = LoadIcon(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_PAUSE));
- m_hStopIcon = LoadIcon(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_STOP));
-
- // Set the master play control buttons
- m_ResumeAll.SetIcon(m_hPlayIcon);
- m_PauseAll.SetIcon(m_hPauseIcon);
- m_StopAll.SetIcon(m_hStopIcon);
-
- // Set up the volume sliders
- m_SoundVolume.SetRange(0, 10000);
- m_SoundVolume.SetPos(10000);
- m_SoundVolume.Invalidate();
- m_MusicVolume.SetRange(0, 10000);
- m_MusicVolume.SetPos(10000);
- m_MusicVolume.Invalidate();
-
- // Set all system initialization options to their default values
- AudioMgrInit init;
- m_LoadAsync.SetCheck(init.m_bLoadAsyncronously ? true : false);
- m_ForceSoftware.SetCheck(init.m_bForceSoftware ? true : false);
- m_UseMusicReverb.SetCheck(init.m_bUseMusicReverb ? true : false);
- m_UseEAX.SetCheck(init.m_bUseEAX ? true : false);
- m_UseZoomFX.SetCheck(init.m_bUseZoomFX ? true : false);
- m_AutoStream.SetCheck(init.m_bAutoStream ? true : false);
- m_CacheBuffers.SetCheck(init.m_bCacheBuffers ? true : false);
- m_SegmentMax.SetRange(1, 1024);
- m_SegmentMax.SetPos(init.m_nSegmentMax);
- m_3DSoftwareBufferMax.SetRange(1, 1024);
- m_3DSoftwareBufferMax.SetPos(init.m_n3DSoftwareBufferMax);
- m_3DHardwareBufferMin.SetRange(1, 1024);
- m_3DHardwareBufferMin.SetPos(init.m_n3DHardwareBufferMin);
- m_3DHardwareBufferMax.SetRange(1, 1024);
- m_3DHardwareBufferMax.SetPos(init.m_n3DHardwareBufferMax);
- m_2DSoftwareBufferMax.SetRange(1, 1024);
- m_2DSoftwareBufferMax.SetPos(init.m_n2DSoftwareBufferMax);
- m_2DHardwareBufferMin.SetRange(1, 1024);
- m_2DHardwareBufferMin.SetPos(init.m_n2DHardwareBufferMin);
- m_2DHardwareBufferMax.SetRange(1, 1024);
- m_2DHardwareBufferMax.SetPos(init.m_n2DHardwareBufferMax);
-
- m_OptimalRate.AddString("16-bit, 11.025 KHz");
- m_OptimalRate.AddString("16-bit, 22.05 KHz");
- m_OptimalRate.AddString("16-bit, 44.1KHz");
- m_OptimalRate.AddString("8-bit, 11.025 KHz");
- m_OptimalRate.AddString("8-bit, 22.05 KHz");
- m_OptimalRate.AddString("8-bit, 44.1KHz");
-
- int iCursor = 0;
- if(init.m_nOptimalSampleBits == 8)
- iCursor += 3;
- if(init.m_nOptimalSampleRate == 22050)
- iCursor += 1;
- else if(init.m_nOptimalSampleRate == 44100)
- iCursor += 2;
- m_OptimalRate.SetCurSel(iCursor);
-
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void CSystem::OnInitialize()
- {
- AudioMgrInit audiomgrinit;
- audiomgrinit.m_hWnd = AfxGetMainWnd()->GetSafeHwnd();
- audiomgrinit.m_bLoadAsyncronously = (m_LoadAsync.GetCheck() == 1) ? true : false;
- audiomgrinit.m_bForceSoftware = (m_ForceSoftware.GetCheck() == 1) ? true : false;
- audiomgrinit.m_bUseMusicReverb = (m_UseMusicReverb.GetCheck() == 1) ? true : false;
- audiomgrinit.m_bUseEAX = (m_UseEAX.GetCheck() == 1) ? true : false;
- audiomgrinit.m_bUseZoomFX = (m_UseZoomFX.GetCheck() == 1) ? true : false;
- audiomgrinit.m_bAutoStream = (m_AutoStream.GetCheck() == 1) ? true : false;
- audiomgrinit.m_bCacheBuffers = (m_CacheBuffers.GetCheck() == 1) ? true : false;
- audiomgrinit.m_nSegmentMax = m_SegmentMax.GetPos();
- audiomgrinit.m_n3DSoftwareBufferMax = m_3DSoftwareBufferMax.GetPos();
- audiomgrinit.m_n3DHardwareBufferMin = m_3DHardwareBufferMin.GetPos();
- audiomgrinit.m_n3DHardwareBufferMax = m_3DHardwareBufferMax.GetPos();
- audiomgrinit.m_n2DSoftwareBufferMax = m_2DSoftwareBufferMax.GetPos();
- audiomgrinit.m_n2DHardwareBufferMin = m_2DHardwareBufferMin.GetPos();
- audiomgrinit.m_n2DHardwareBufferMax = m_2DHardwareBufferMax.GetPos();
- int iCursor = m_OptimalRate.GetCurSel();
- switch(iCursor)
- {
- case 0:
- audiomgrinit.m_nOptimalSampleBits = 16;
- audiomgrinit.m_nOptimalSampleRate = 11025;
- break;
- case 1:
- audiomgrinit.m_nOptimalSampleBits = 16;
- audiomgrinit.m_nOptimalSampleRate = 22050;
- break;
- case 2:
- audiomgrinit.m_nOptimalSampleBits = 16;
- audiomgrinit.m_nOptimalSampleRate = 44100;
- break;
- case 3:
- audiomgrinit.m_nOptimalSampleBits = 8;
- audiomgrinit.m_nOptimalSampleRate = 11025;
- break;
- case 4:
- audiomgrinit.m_nOptimalSampleBits = 8;
- audiomgrinit.m_nOptimalSampleRate = 22050;
- break;
- case 5:
- audiomgrinit.m_nOptimalSampleBits = 8;
- audiomgrinit.m_nOptimalSampleRate = 44100;
- break;
- };
-
- audiomgrinit.m_pMusicCallback = MusicMgr();
-
- if(!AudioMgr()->Init(audiomgrinit))
- AfxMessageBox("Error initializing audio system");
-
- m_LoadAsync.EnableWindow(FALSE);
- m_ForceSoftware.EnableWindow(FALSE);
- m_UseMusicReverb.EnableWindow(FALSE);
- m_UseEAX.EnableWindow(FALSE);
- m_UseZoomFX.EnableWindow(FALSE);
- m_AutoStream.EnableWindow(FALSE);
- m_CacheBuffers.EnableWindow(FALSE);
- m_SegmentMax.EnableWindow(FALSE);
- m_3DSoftwareBufferMax.EnableWindow(FALSE);
- m_3DHardwareBufferMin.EnableWindow(FALSE);
- m_3DHardwareBufferMax.EnableWindow(FALSE);
- m_2DSoftwareBufferMax.EnableWindow(FALSE);
- m_2DHardwareBufferMin.EnableWindow(FALSE);
- m_2DHardwareBufferMax.EnableWindow(FALSE);
- m_OptimalRate.EnableWindow(FALSE);
- CButton* pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_2DHWBUFFERMIN);
- pCheck->EnableWindow(FALSE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_3DHWBUFFERMIN);
- pCheck->EnableWindow(FALSE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_2DHWBUFFERMAX);
- pCheck->EnableWindow(FALSE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_3DHWBUFFERMAX);
- pCheck->EnableWindow(FALSE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_2DSWBUFFERMAX);
- pCheck->EnableWindow(FALSE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_3DSWBUFFERMAX);
- pCheck->EnableWindow(FALSE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_SEGMENTMAX);
- pCheck->EnableWindow(FALSE);
-
-
- IListener* pListener;
- if(!AudioMgr()->GetListener(pListener))
- AfxMessageBox("Error getting listener object");
-
- ListenerInit listenerinit;
- if(!pListener->Init(listenerinit))
- AfxMessageBox("Error initializing listener object");
-
- if(!SoundMgr()->Init())
- AfxMessageBox("Error initializing sound manager");
-
- if(!MusicMgr()->Init())
- AfxMessageBox("Error initializing music manager");
-
-
- m_nSoundVolumeUpdateTimer = SetTimer(STATS_TIMER, 100, NULL);
- UpdateStats();
-
- }
-
- void CSystem::OnTerm()
- {
- m_pTestDlg->m_pSound2D->ClearList();
- m_pTestDlg->m_pSound3D->ClearList();
- m_pTestDlg->m_pSegment->ClearList();
- m_pTestDlg->m_pMusicScript->ClearList();
- m_pTestDlg->m_pSoundScript->ClearList();
-
- MusicMgr()->Term();
- SoundMgr()->Term();
-
- IListener* pListener;
- if(AudioMgr()->GetListener(pListener))
- pListener->Term();
-
- AudioMgr()->Term();
-
- KillTimer(m_nSoundVolumeUpdateTimer);
- UpdateStats();
-
- m_LoadAsync.EnableWindow(TRUE);
- m_ForceSoftware.EnableWindow(TRUE);
- m_UseMusicReverb.EnableWindow(TRUE);
- m_UseEAX.EnableWindow(TRUE);
- m_UseZoomFX.EnableWindow(TRUE);
- m_AutoStream.EnableWindow(TRUE);
- m_CacheBuffers.EnableWindow(TRUE);
- m_SegmentMax.EnableWindow(TRUE);
- m_3DSoftwareBufferMax.EnableWindow(TRUE);
- m_3DHardwareBufferMin.EnableWindow(TRUE);
- m_3DHardwareBufferMax.EnableWindow(TRUE);
- m_2DSoftwareBufferMax.EnableWindow(TRUE);
- m_2DHardwareBufferMin.EnableWindow(TRUE);
- m_2DHardwareBufferMax.EnableWindow(TRUE);
- m_OptimalRate.EnableWindow(TRUE);
- CButton* pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_2DHWBUFFERMIN);
- pCheck->EnableWindow(TRUE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_3DHWBUFFERMIN);
- pCheck->EnableWindow(TRUE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_2DHWBUFFERMAX);
- pCheck->EnableWindow(TRUE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_3DHWBUFFERMAX);
- pCheck->EnableWindow(TRUE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_2DSWBUFFERMAX);
- pCheck->EnableWindow(TRUE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_3DSWBUFFERMAX);
- pCheck->EnableWindow(TRUE);
- pCheck = (CButton*) GetDlgItem(IDC_EDIT_SYSTEM_SEGMENTMAX);
- pCheck->EnableWindow(TRUE);
-
-
- }
-
-
- void CSystem::OnResumeall()
- {
- AudioMgr()->ResumeAll();
- }
-
- void CSystem::OnPauseall()
- {
- AudioMgr()->PauseAll();
- }
-
- void CSystem::OnStopall()
- {
- AudioMgr()->StopAll();
- }
-
- void CSystem::UpdateStats()
- {
- // Update stats and volume
- AudioMgrStats stats;
- AudioMgr()->GetStats(stats);
-
- CString sVal;
- sVal.Format("%d", stats.m_n2DSoundsLoaded);
- m_2DLoaded.SetWindowText(sVal);
- sVal.Format("%d", stats.m_n3DSoundsLoaded);
- m_3DLoaded.SetWindowText(sVal);
- sVal.Format("%d", stats.m_nSegmentsLoaded);
- m_SegmentsLoaded.SetWindowText(sVal);
- sVal.Format("%s", (stats.m_bForce2DSoftware) ? "true" : "false");
- m_Force2DSoftware.SetWindowText(sVal);
- sVal.Format("%s", (stats.m_bForce3DSoftware) ? "true" : "false");
- m_Force3DSoftware.SetWindowText(sVal);
-
- float fVol;
- if(AudioMgr()->GetSoundVolume(fVol))
- m_SoundVolume.SetPos(fVol*10000.0f);
- if(AudioMgr()->GetMusicVolume(fVol))
- m_MusicVolume.SetPos(fVol*10000.0f);
- }
-
- // Handles the automatic fade demonstration code
- void CSystem::OnTimer(UINT nIDEvent)
- {
- if(nIDEvent == STATS_TIMER)
- {
- UpdateStats();
- }
-
- CPropertyPage::OnTimer(nIDEvent);
- }
-
- // Intercepts and handles volume control messages
- void CSystem::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if(pScrollBar->IsKindOf(RUNTIME_CLASS(CSliderCtrl)))
- {
- CSliderCtrl* pSlider = reinterpret_cast<CSliderCtrl*>(pScrollBar);
- if(!pSlider)
- return;
- if(pSlider == &m_SoundVolume)
- AudioMgr()->SetSoundVolume(float(pSlider->GetPos()) / 10000.0f);
- else if(pSlider == &m_MusicVolume)
- AudioMgr()->SetMusicVolume(float(pSlider->GetPos()) / 10000.0f);
- }
- CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
- }
-
-
- void CSystem::OnDestroy()
- {
- CPropertyPage::OnDestroy();
-
- if(m_nSoundVolumeUpdateTimer)
- KillTimer(m_nSoundVolumeUpdateTimer);
- if(m_nMusicVolumeUpdateTimer)
- KillTimer(m_nMusicVolumeUpdateTimer);
-
- OnTerm();
-
- }
-