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 "Sound3D.h"
- #include "SoundOpen.h"
- #include "Audio.h"
- #include "EAXBuffer.h"
- #include "ZoomFX.h"
-
- #include "AudioTestDlg.h"
- #include "System.h"
- #include "Sound2D.h"
- #include "Segment.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- using namespace Audio;
-
- const int CURSOR_TIMER = 6;
-
- #define GET_CURRENT_SOUND() \
- int iIndex = m_3DSounds.GetCurSel();\
- if(iIndex == LB_ERR) return;\
- ISound3D* pSound = static_cast<ISound3D*>(m_3DSounds.GetItemDataPtr(iIndex));\
- if(!pSound) return;
-
- /////////////////////////////////////////////////////////////////////////////
- // CSound3D property page
-
- IMPLEMENT_DYNCREATE(CSound3D, CPropertyPage)
-
- CSound3D::CSound3D() : CPropertyPage(CSound3D::IDD)
- {
- //{{AFX_DATA_INIT(CSound3D)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_nCursorTimer = 0;
- m_bInit = false;
- }
-
- CSound3D::~CSound3D()
- {
- }
-
- void CSound3D::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSound3D)
- DDX_Control(pDX, IDC_SLIDER_SOUND3DPOSZ, m_ZPos);
- DDX_Control(pDX, IDC_SLIDER_SOUND3DPOSY, m_YPos);
- DDX_Control(pDX, IDC_SLIDER_SOUND3DPOSX, m_XPos);
- DDX_Control(pDX, IDC_STOP3D, m_Stop);
- DDX_Control(pDX, IDC_PAUSE3D, m_Pause);
- DDX_Control(pDX, IDC_PLAY3D, m_Play);
- DDX_Control(pDX, IDC_LIST_3DSOUNDS, m_3DSounds);
- DDX_Control(pDX, IDC_SLIDER_SOUND3DCURSOR, m_Cursor);
- DDX_Control(pDX, IDC_SLIDER_SOUND3DPITCH, m_Pitch);
- DDX_Control(pDX, IDC_SLIDER_SOUND3DVOLUME, m_Volume);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CSound3D, CPropertyPage)
- //{{AFX_MSG_MAP(CSound3D)
- ON_BN_CLICKED(IDC_3D_INITIALIZE, On3dInitialize)
- ON_BN_CLICKED(IDC_3D_DELETE, On3dDelete)
- ON_BN_CLICKED(IDC_LOAD3D, OnLoad3d)
- ON_BN_CLICKED(IDC_UNLOAD3D, OnUnload3d)
- ON_BN_CLICKED(IDC_PLAY3D, OnPlay3d)
- ON_BN_CLICKED(IDC_PAUSE3D, OnPause3d)
- ON_BN_CLICKED(IDC_STOP3D, OnStop3d)
- ON_WM_HSCROLL()
- ON_WM_TIMER()
- ON_LBN_SELCHANGE(IDC_LIST_3DSOUNDS, OnSelChangeList3dSounds)
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_BUFFER_EAX, OnBufferEAX)
- ON_BN_CLICKED(IDC_ZOOM_FX, OnZoomFx)
- ON_LBN_DBLCLK(IDC_LIST_3DSOUNDS, OnDblclkList3dsounds)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSound3D message handlers
-
- BOOL CSound3D::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- // 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_Play.SetIcon(m_hPlayIcon);
- m_Pause.SetIcon(m_hPauseIcon);
- m_Stop.SetIcon(m_hStopIcon);
-
- // Set up the volume sliders
- m_Volume.SetRange(0, 10000);
- m_Volume.SetPos(10000);
- m_Volume.Invalidate();
- m_Pitch.SetRange(0, 10000);
- m_Pitch.SetPos(5000);
- m_Pitch.Invalidate();
-
- m_XPos.SetRange(0, 10000, TRUE);
- m_YPos.SetRange(0, 10000, TRUE);
- m_ZPos.SetRange(0, 10000, TRUE);
- m_XPos.SetPos(5000);
- m_YPos.SetPos(5000);
- m_ZPos.SetPos(5000);
-
- m_nCursorTimer = SetTimer(CURSOR_TIMER, 100, NULL);
-
- m_bInit = true;
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void CSound3D::ClearList()
- {
- if(m_bInit)
- {
- ISound3D* pSound;
- int iSize = m_3DSounds.GetCount();
- for(int i = 0; i < iSize; i++)
- {
- pSound = static_cast<ISound3D*>(m_3DSounds.GetItemDataPtr(0));
- pSound->Destroy();
- m_3DSounds.DeleteString(0);
- }
- m_3DSounds.ResetContent();
- }
- }
-
- void CSound3D::On3dInitialize()
- {
- CSoundOpen dlg(TRUE);
- if(dlg.DoModal() != IDOK)
- return;
-
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
-
- POSITION pos = dlg.GetStartPosition();
- CString sPathName;
- while(pos)
- {
- sPathName = dlg.GetNextPathName(pos);
- _splitpath(sPathName, drive, dir, fname, ext);
- Sound3DInit init;
- init.m_bLooping = dlg.m_bLooping;
- init.m_bStreaming = dlg.m_bStreaming;
- init.m_bMusic = dlg.m_bMusic;
- init.m_sFileName = sPathName;
-
- ISound3D* pSound;
- if(!AudioMgr()->CreateSound3D(pSound))
- return;
- if(!pSound->Init(init))
- {
- AfxMessageBox("Error initializing audio file");
- return;
- }
- int iIndex = m_3DSounds.AddString(CString(fname) + CString(ext));
- if(iIndex != LB_ERR)
- m_3DSounds.SetItemDataPtr(iIndex, pSound);
- }
- }
-
- void CSound3D::On3dDelete()
- {
- GET_CURRENT_SOUND();
- pSound->Destroy();
- int iSize = m_3DSounds.DeleteString(iIndex);
- if(!iSize)
- return;
- if(iIndex > (iSize - 1))
- iIndex = iSize - 1;
- m_3DSounds.SetCurSel(iIndex);
- }
-
- void CSound3D::OnLoad3d()
- {
- GET_CURRENT_SOUND();
- if(!pSound->Load())
- AfxMessageBox("Unable to load sound");
-
- m_pTestDlg->m_pSystem->UpdateStats();
- UpdateControls();
- }
-
- void CSound3D::OnUnload3d()
- {
- GET_CURRENT_SOUND();
- pSound->Unload();
- m_pTestDlg->m_pSystem->UpdateStats();
- UpdateControls();
- }
-
- void CSound3D::OnPlay3d()
- {
- GET_CURRENT_SOUND();
- if(!pSound->Play())
- AfxMessageBox("Unable to play sound");
- m_pTestDlg->m_pSystem->UpdateStats();
- UpdateControls();
- }
-
- void CSound3D::OnPause3d()
- {
- GET_CURRENT_SOUND();
- pSound->Pause();
- }
-
- void CSound3D::OnStop3d()
- {
- GET_CURRENT_SOUND();
- pSound->Stop();
- }
-
- void CSound3D::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if(pScrollBar->IsKindOf(RUNTIME_CLASS(CSliderCtrl)))
- {
- CSliderCtrl* pSlider = reinterpret_cast<CSliderCtrl*>(pScrollBar);
- if(!pSlider)
- return;
- GET_CURRENT_SOUND();
- if(pSlider == &m_Volume)
- {
- pSound->SetVolume(static_cast<float>(pSlider->GetPos()) / 10000.0f);
- }
- else if(pSlider == &m_Pitch)
- {
- pSound->SetPitch((float(pSlider->GetPos() + 5000.0f) / 10000.0f) );
- }
- else if(pSlider == &m_Cursor)
- {
- pSound->SetReadCursor(nPos);
- }
- else if(pSlider == &m_XPos)
- {
- AUDIOVECTOR pos;
- pSound->GetPosition(pos);
- pos.x = ((float(pSlider->GetPos()) - 5000.0f) / 10000.0f) * 20.0f;
- pSound->SetPosition(pos);
- }
- else if(pSlider == &m_YPos)
- {
- AUDIOVECTOR pos;
- pSound->GetPosition(pos);
- pos.y = ((float(pSlider->GetPos()) - 5000.0f) / 10000.0f) * 20.0f;
- pSound->SetPosition(pos);
- }
- else if(pSlider == &m_ZPos)
- {
- AUDIOVECTOR pos;
- pSound->GetPosition(pos);
- pos.z = ((float(pSlider->GetPos()) - 5000.0f) / 10000.0f) * 20.0f;
- pSound->SetPosition(pos);
- }
- }
- CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
- }
-
- void CSound3D::OnTimer(UINT nIDEvent)
- {
- if(nIDEvent == CURSOR_TIMER)
- {
- GET_CURRENT_SOUND();
-
- unsigned long nVal;
- if(pSound->IsPlaying())
- {
- pSound->GetReadCursor(nVal);
- m_Cursor.SetPos(nVal);
- m_Cursor.Invalidate();
- }
- else
- {
- pSound->GetReadCursor(nVal);
- if(m_Cursor.GetPos() != nVal)
- {
- m_Cursor.SetPos(nVal);
- m_Cursor.Invalidate();
- }
- }
- }
-
- CPropertyPage::OnTimer(nIDEvent);
- }
-
- void CSound3D::UpdateControls()
- {
- int iIndex = m_3DSounds.GetCurSel();
- if(iIndex == LB_ERR)
- return;
- ISound3D* pSound = static_cast<ISound3D*>(m_3DSounds.GetItemDataPtr(iIndex));
- if(!pSound) return;
-
- float fVal;
- unsigned long nVal;
- pSound->GetVolume(fVal);
- m_Volume.SetPos(static_cast<int>(fVal * 10000.0f));
- pSound->GetPitch(fVal);
- m_Pitch.SetPos(static_cast<int>((fVal * 10000.0f) - 5000.0f));
- pSound->GetSourceSize(nVal);
- m_Cursor.SetRange(0, nVal);
- AUDIOVECTOR pos;
- pSound->GetPosition(pos);
- m_XPos.SetPos(static_cast<int>(((pos.x / 20.0f) * 10000.0f) + 5000.0f));
- m_YPos.SetPos(static_cast<int>(((pos.y / 20.0f) * 10000.0f) + 5000.0f));
- m_ZPos.SetPos(static_cast<int>(((pos.z / 20.0f) * 10000.0f) + 5000.0f));
- }
-
- void CSound3D::OnSelChangeList3dSounds()
- {
- UpdateControls();
-
- if(m_pTestDlg->m_pEAXBuffer)
- m_pTestDlg->m_pEAXBuffer->UpdateControls();
- if(m_pTestDlg->m_pZoomFX)
- m_pTestDlg->m_pZoomFX->UpdateControls();
-
- }
-
- void CSound3D::OnDestroy()
- {
- CPropertyPage::OnDestroy();
-
- if(m_nCursorTimer)
- KillTimer(m_nCursorTimer);
- ClearList();
- }
-
- void CSound3D::OnBufferEAX()
- {
- if(!m_pTestDlg->m_pEAXBuffer)
- {
- m_pTestDlg->m_pEAXBuffer = new CEAXBuffer;
- m_pTestDlg->m_pEAXBuffer->m_pTestDlg = m_pTestDlg;
- m_pTestDlg->m_pEAXBuffer->Create(IDD_EAX_BUFFER, this);
- m_pTestDlg->m_pEAXBuffer->ShowWindow(SW_SHOW);
- }
- }
-
- void CSound3D::OnZoomFx()
- {
- if(!m_pTestDlg->m_pZoomFX)
- {
- m_pTestDlg->m_pZoomFX = new CZoomFX;
- m_pTestDlg->m_pZoomFX->m_pTestDlg = m_pTestDlg;
- m_pTestDlg->m_pZoomFX->Create(IDD_ZOOMFX, this);
- m_pTestDlg->m_pZoomFX->ShowWindow(SW_SHOW);
- }
- }
-
- ISound3D* CSound3D::GetCurrentSound()
- {
- int iIndex = m_3DSounds.GetCurSel();
- if(iIndex == LB_ERR)
- return NULL;
- ISound3D* pSound = static_cast<ISound3D*>(m_3DSounds.GetItemDataPtr(iIndex));
- return pSound;
- }
-
-
- void CSound3D::OnDblclkList3dsounds()
- {
- OnPlay3d();
- }
-