home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Game Audio Programming
/
GameAudioProgramming.iso
/
Game_Audio
/
AudioTest
/
EAXListener.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2002-06-25
|
15KB
|
464 lines
// EAXListener.cpp : implementation file
//
#include "stdafx.h"
#include "audiotest.h"
#include "AudioTestDlg.h"
#include "EAXListener.h"
#include "Audio.h"
using namespace Audio;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEAXListener dialog
CEAXListener::CEAXListener(CWnd* pParent /*=NULL*/)
: CDialog(CEAXListener::IDD, pParent)
{
//{{AFX_DATA_INIT(CEAXListener)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pTestDlg = 0;
}
void CEAXListener::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEAXListener)
DDX_Control(pDX, IDC_SLIDER_ROOM_VOLUMEHF, m_SliderRoomVolumeHF);
DDX_Control(pDX, IDC_SLIDER_ROOM_VOLUME, m_SliderRoomVolume);
DDX_Control(pDX, IDC_SLIDER_ROOM_ROLLOFF_FACTOR, m_SliderRoomRolloffFactor);
DDX_Control(pDX, IDC_SLIDER_REVERB_VOLUME, m_SliderReverbVolume);
DDX_Control(pDX, IDC_SLIDER_REVERB_DELAY, m_SliderReverbDelay);
DDX_Control(pDX, IDC_SLIDER_REFLECTIONS_VOLUME, m_SliderReflectionsVolume);
DDX_Control(pDX, IDC_SLIDER_REFLECTIONS_DELAY, m_SliderReflectionsDelay);
DDX_Control(pDX, IDC_SLIDER_ENVIRONMENT_SIZE, m_SliderEnvironmentSize);
DDX_Control(pDX, IDC_SLIDER_DIFFUSION, m_SliderDiffusion);
DDX_Control(pDX, IDC_SLIDER_DECAY_TIME, m_SliderDecayTime);
DDX_Control(pDX, IDC_SLIDER_DECAY_HF_RATIO, m_SliderDecayHFRatio);
DDX_Control(pDX, IDC_SLIDER_AIR_ABSORPTION_HF, m_SliderAirAbsorptionHF);
DDX_Control(pDX, IDC_EDIT_ROOM_VOLUMEHF, m_EditRoomVolumeHF);
DDX_Control(pDX, IDC_EDIT_ROOM_VOLUME, m_EditRoomVolume);
DDX_Control(pDX, IDC_EDIT_ROOM_ROLLOFF_FACTOR, m_EditRoomRolloffFactor);
DDX_Control(pDX, IDC_EDIT_REVERB_VOLUME, m_EditReverbVolume);
DDX_Control(pDX, IDC_EDIT_REVERB_DELAY, m_EditReverbDelay);
DDX_Control(pDX, IDC_EDIT_REFLECTIONS_VOLUME, m_EditReflectionsVolume);
DDX_Control(pDX, IDC_EDIT_REFLECTIONS_DELAY, m_EditReflectionsDelay);
DDX_Control(pDX, IDC_EDIT_ENVIRONMENT_SIZE, m_EditEnvironmentSize);
DDX_Control(pDX, IDC_EDIT_DIFFUSION, m_EditDiffusion);
DDX_Control(pDX, IDC_EDIT_DECAY_TIME, m_EditDecayTime);
DDX_Control(pDX, IDC_EDIT_DECAY_HF_RATIO, m_EditDecayHFRatio);
DDX_Control(pDX, IDC_EDIT_AIR_ABSORPTION_HF, m_EditAirAbsorptionHF);
DDX_Control(pDX, IDC_CHECK_SCALE_REVERB_VOLUME, m_CheckScaleReverbVolume);
DDX_Control(pDX, IDC_CHECK_SCALE_REVERB_DELAY, m_CheckScaleReverbDelay);
DDX_Control(pDX, IDC_CHECK_SCALE_REFLECTIONS_VOLUME, m_CheckScaleReflectionsVolume);
DDX_Control(pDX, IDC_CHECK_SCALE_REFLECTIONS_DELAY, m_CheckScaleReflectionsDelay);
DDX_Control(pDX, IDC_CHECK_SCALE_DECAY_TIME, m_CheckScaleDecayTime);
DDX_Control(pDX, IDC_CHECK_DECAY_HF_LIMIT, m_CheckDecayHFLimit);
DDX_Control(pDX, IDC_COMBO_ENVIRONMENT_PRESET, m_ComboEnvironmentPreset);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEAXListener, CDialog)
//{{AFX_MSG_MAP(CEAXListener)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_CHECK_SCALE_DECAY_TIME, OnCheckScaleDecayTime)
ON_BN_CLICKED(IDC_CHECK_SCALE_REFLECTIONS_VOLUME, OnCheckScaleReflectionsVolume)
ON_BN_CLICKED(IDC_CHECK_SCALE_REFLECTIONS_DELAY, OnCheckScaleReflectionsDelay)
ON_BN_CLICKED(IDC_CHECK_SCALE_REVERB_VOLUME, OnCheckScaleReverbVolume)
ON_BN_CLICKED(IDC_CHECK_SCALE_REVERB_DELAY, OnCheckScaleReverbDelay)
ON_BN_CLICKED(IDC_CHECK_DECAY_HF_LIMIT, OnCheckDecayHFLimit)
ON_CBN_SELCHANGE(IDC_COMBO_ENVIRONMENT_PRESET, OnSelchangeComboEnvironmentPreset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEAXListener message handlers
BOOL CEAXListener::OnInitDialog()
{
CDialog::OnInitDialog();
m_SliderRoomVolumeHF.SetRange(-10000, 0, TRUE);
m_SliderRoomVolume.SetRange(-10000, 0, TRUE);
m_SliderRoomRolloffFactor.SetRange(0, 1000, TRUE); // times 100
m_SliderReverbVolume.SetRange(-10000, 2000, TRUE);
m_SliderReverbDelay.SetRange(0, 100, TRUE); // times 1000
m_SliderReflectionsVolume.SetRange(-10000, 1000, TRUE);
m_SliderReflectionsDelay.SetRange(0, 300, TRUE); // times 1000
m_SliderEnvironmentSize.SetRange(0, 10000, TRUE); // times 100
m_SliderDiffusion.SetRange(0, 100, TRUE); // times 100
m_SliderDecayTime.SetRange(10, 2000, TRUE); // times 100
m_SliderDecayHFRatio.SetRange(10, 200, TRUE); // times 100
m_SliderAirAbsorptionHF.SetRange(-10000, 0, TRUE); // times 100
m_ComboEnvironmentPreset.AddString("Generic");
m_ComboEnvironmentPreset.AddString("Padded Cell");
m_ComboEnvironmentPreset.AddString("Room");
m_ComboEnvironmentPreset.AddString("Bathroom");
m_ComboEnvironmentPreset.AddString("Living Room");
m_ComboEnvironmentPreset.AddString("Stone Room");
m_ComboEnvironmentPreset.AddString("Auditorium");
m_ComboEnvironmentPreset.AddString("Concert Hall");
m_ComboEnvironmentPreset.AddString("Cave");
m_ComboEnvironmentPreset.AddString("Arena");
m_ComboEnvironmentPreset.AddString("Hangar");
m_ComboEnvironmentPreset.AddString("Carpeted Hallway");
m_ComboEnvironmentPreset.AddString("Hallway");
m_ComboEnvironmentPreset.AddString("Stone Corridor");
m_ComboEnvironmentPreset.AddString("Alley");
m_ComboEnvironmentPreset.AddString("Forest");
m_ComboEnvironmentPreset.AddString("City");
m_ComboEnvironmentPreset.AddString("Mountains");
m_ComboEnvironmentPreset.AddString("Quarry");
m_ComboEnvironmentPreset.AddString("Plain");
m_ComboEnvironmentPreset.AddString("Parking Lot");
m_ComboEnvironmentPreset.AddString("Sewer Pipe");
m_ComboEnvironmentPreset.AddString("Underwater");
m_ComboEnvironmentPreset.AddString("Drugged");
m_ComboEnvironmentPreset.AddString("Dizzy");
m_ComboEnvironmentPreset.AddString("Psychotic");
UpdateControls();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CEAXListener::PostNcDestroy()
{
CDialog::PostNcDestroy();
if(m_pTestDlg)
m_pTestDlg->m_pEAXListener = 0;
delete this;
}
void CEAXListener::OnOK()
{
CDialog::DestroyWindow();
}
void CEAXListener::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(pScrollBar->IsKindOf(RUNTIME_CLASS(CSliderCtrl)))
{
CSliderCtrl* pSlider = reinterpret_cast<CSliderCtrl*>(pScrollBar);
if(!pSlider)
return;
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pSlider == &m_SliderRoomVolumeHF)
{
if(pListener)
pListener->EAX()->SetRoomHF(pSlider->GetPos());
else
m_Props.lRoomHF = pSlider->GetPos();
}
else if(pSlider == &m_SliderRoomVolume)
{
if(pListener)
pListener->EAX()->SetRoom(pSlider->GetPos());
else
m_Props.lRoom = pSlider->GetPos();
}
else if(pSlider == &m_SliderRoomRolloffFactor)
{
if(pListener)
pListener->EAX()->SetRoomRolloffFactor(float(pSlider->GetPos()) / 100.0f);
else
m_Props.flRoomRolloffFactor = float(pSlider->GetPos()) / 100.0f;
}
else if(pSlider == &m_SliderReverbVolume)
{
if(pListener)
pListener->EAX()->SetReverb(pSlider->GetPos());
else
m_Props.lReverb = pSlider->GetPos();
}
else if(pSlider == &m_SliderReverbDelay)
{
if(pListener)
pListener->EAX()->SetReverbDelay(float(pSlider->GetPos()) / 1000.0f);
else
m_Props.flReverbDelay = float(pSlider->GetPos()) / 1000.0f;
}
else if(pSlider == &m_SliderReflectionsVolume)
{
if(pListener)
pListener->EAX()->SetReflections(pSlider->GetPos());
else
m_Props.lReflections = pSlider->GetPos();
}
else if(pSlider == &m_SliderReflectionsDelay)
{
if(pListener)
pListener->EAX()->SetReflectionsDelay(float(pSlider->GetPos()) / 1000.0f);
else
m_Props.flReflectionsDelay = float(pSlider->GetPos()) / 1000.0f;
}
else if(pSlider == &m_SliderEnvironmentSize)
{
if(pListener)
pListener->EAX()->SetEnvironmentSize(float(pSlider->GetPos()) / 100.0f);
else
m_Props.flEnvironmentSize = float(pSlider->GetPos()) / 100.0f;
}
else if(pSlider == &m_SliderDiffusion)
{
if(pListener)
pListener->EAX()->SetEnvironmentDiffusion(float(pSlider->GetPos()) / 100.0f);
else
m_Props.flEnvironmentDiffusion = float(pSlider->GetPos()) / 100.0f;
}
else if(pSlider == &m_SliderDecayTime)
{
if(pListener)
pListener->EAX()->SetDecayTime(float(pSlider->GetPos()) / 100.0f);
else
m_Props.flDecayTime = float(pSlider->GetPos()) / 100.0f;
}
else if(pSlider == &m_SliderDecayHFRatio)
{
if(pListener)
pListener->EAX()->SetDecayHFRatio(float(pSlider->GetPos()) / 100.0f);
else
m_Props.flDecayHFRatio = float(pSlider->GetPos()) / 100.0f;
}
else if(pSlider == &m_SliderAirAbsorptionHF)
{
if(pListener)
pListener->EAX()->SetAirAbsorptionHF(float(pSlider->GetPos()) / 100.0f);
else
m_Props.flAirAbsorptionHF = float(pSlider->GetPos()) / 100.0f;
}
UpdateControls();
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CEAXListener::UpdateControls()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
m_ComboEnvironmentPreset.SetCurSel(m_Props.dwEnvironment);
CString sVal;
m_SliderRoomVolumeHF.SetPos(m_Props.lRoomHF);
sVal.Format("%d", m_Props.lRoomHF);
m_EditRoomVolumeHF.SetWindowText(sVal);
m_SliderRoomVolume.SetPos(m_Props.lRoom);
sVal.Format("%d", m_Props.lRoom);
m_EditRoomVolume.SetWindowText(sVal);
m_SliderRoomRolloffFactor.SetPos(m_Props.flRoomRolloffFactor * 100);
sVal.Format("%.2f", m_Props.flRoomRolloffFactor);
m_EditRoomRolloffFactor.SetWindowText(sVal);
m_SliderReverbVolume.SetPos(m_Props.lReverb);
sVal.Format("%d", m_Props.lReverb);
m_EditReverbVolume.SetWindowText(sVal);
m_SliderReverbDelay.SetPos(m_Props.flReverbDelay * 1000);
sVal.Format("%.3f", m_Props.flReverbDelay);
m_EditReverbDelay.SetWindowText(sVal);
m_SliderReflectionsVolume.SetPos(m_Props.lReflections);
sVal.Format("%d", m_Props.lReflections);
m_EditReflectionsVolume.SetWindowText(sVal);
m_SliderReflectionsDelay.SetPos(m_Props.flReflectionsDelay * 1000);
sVal.Format("%.3f", m_Props.flReflectionsDelay);
m_EditReflectionsDelay.SetWindowText(sVal);
m_SliderEnvironmentSize.SetPos(m_Props.flEnvironmentSize * 100);
sVal.Format("%.2f", m_Props.flEnvironmentSize);
m_EditEnvironmentSize.SetWindowText(sVal);
m_SliderDiffusion.SetPos(m_Props.flEnvironmentDiffusion * 100);
sVal.Format("%.2f", m_Props.flEnvironmentDiffusion);
m_EditDiffusion.SetWindowText(sVal);
m_SliderDecayTime.SetPos(m_Props.flDecayTime * 100);
sVal.Format("%.2f", m_Props.flDecayTime);
m_EditDecayTime.SetWindowText(sVal);
m_SliderDecayHFRatio.SetPos(m_Props.flDecayHFRatio * 100);
sVal.Format("%.2f", m_Props.flDecayHFRatio);
m_EditDecayHFRatio.SetWindowText(sVal);
m_SliderAirAbsorptionHF.SetPos(m_Props.flAirAbsorptionHF * 100);
sVal.Format("%.2f", m_Props.flAirAbsorptionHF);
m_EditAirAbsorptionHF.SetWindowText(sVal);
if((m_Props.dwFlags & EAXLISTENERFLAGS_DECAYTIMESCALE) == EAXLISTENERFLAGS_DECAYTIMESCALE)
m_CheckScaleDecayTime.SetCheck(1);
else
m_CheckScaleDecayTime.SetCheck(0);
if((m_Props.dwFlags & EAXLISTENERFLAGS_REFLECTIONSSCALE) == EAXLISTENERFLAGS_REFLECTIONSSCALE)
m_CheckScaleReflectionsVolume.SetCheck(1);
else
m_CheckScaleReflectionsVolume.SetCheck(0);
if((m_Props.dwFlags & EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE) == EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE)
m_CheckScaleReflectionsDelay.SetCheck(1);
else
m_CheckScaleReflectionsDelay.SetCheck(0);
if((m_Props.dwFlags & EAXLISTENERFLAGS_REVERBSCALE) == EAXLISTENERFLAGS_REVERBSCALE)
m_CheckScaleReverbVolume.SetCheck(1);
else
m_CheckScaleReverbVolume.SetCheck(0);
if((m_Props.dwFlags & EAXLISTENERFLAGS_REVERBDELAYSCALE) == EAXLISTENERFLAGS_REVERBDELAYSCALE)
m_CheckScaleReverbDelay.SetCheck(1);
else
m_CheckScaleReverbDelay.SetCheck(0);
if((m_Props.dwFlags & EAXLISTENERFLAGS_DECAYHFLIMIT) == EAXLISTENERFLAGS_DECAYHFLIMIT)
m_CheckDecayHFLimit.SetCheck(1);
else
m_CheckDecayHFLimit.SetCheck(0);
}
void CEAXListener::OnCheckScaleDecayTime()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
if(m_CheckScaleDecayTime.GetCheck())
m_Props.dwFlags |= EAXLISTENERFLAGS_DECAYTIMESCALE;
else
m_Props.dwFlags &= ~EAXLISTENERFLAGS_DECAYTIMESCALE;
if(pListener)
pListener->EAX()->SetFlags(m_Props.dwFlags);
}
void CEAXListener::OnCheckScaleReflectionsVolume()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
if(m_CheckScaleReflectionsVolume.GetCheck())
m_Props.dwFlags |= EAXLISTENERFLAGS_REFLECTIONSSCALE;
else
m_Props.dwFlags &= ~EAXLISTENERFLAGS_REFLECTIONSSCALE;
if(pListener)
pListener->EAX()->SetFlags(m_Props.dwFlags);
}
void CEAXListener::OnCheckScaleReflectionsDelay()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
if(m_CheckScaleReflectionsDelay.GetCheck())
m_Props.dwFlags |= EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE;
else
m_Props.dwFlags &= ~EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE;
if(pListener)
pListener->EAX()->SetFlags(m_Props.dwFlags);
}
void CEAXListener::OnCheckScaleReverbVolume()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
if(m_CheckScaleReverbVolume.GetCheck())
m_Props.dwFlags |= EAXLISTENERFLAGS_REVERBSCALE;
else
m_Props.dwFlags &= ~EAXLISTENERFLAGS_REVERBSCALE;
if(pListener)
pListener->EAX()->SetFlags(m_Props.dwFlags);
}
void CEAXListener::OnCheckScaleReverbDelay()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
if(m_CheckScaleReverbDelay.GetCheck())
m_Props.dwFlags |= EAXLISTENERFLAGS_REVERBDELAYSCALE;
else
m_Props.dwFlags &= ~EAXLISTENERFLAGS_REVERBDELAYSCALE;
if(pListener)
pListener->EAX()->SetFlags(m_Props.dwFlags);
}
void CEAXListener::OnCheckDecayHFLimit()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
if(m_CheckDecayHFLimit.GetCheck())
m_Props.dwFlags |= EAXLISTENERFLAGS_DECAYHFLIMIT;
else
m_Props.dwFlags &= ~EAXLISTENERFLAGS_DECAYHFLIMIT;
if(pListener)
pListener->EAX()->SetFlags(m_Props.dwFlags);
}
void CEAXListener::OnSelchangeComboEnvironmentPreset()
{
IListener* pListener = 0;
AudioMgr()->GetListener(pListener);
if(pListener)
pListener->EAX()->GetProperties(m_Props);
m_Props.dwEnvironment = m_ComboEnvironmentPreset.GetCurSel();
if(pListener)
pListener->EAX()->SetEnvironment(m_ComboEnvironmentPreset.GetCurSel());
UpdateControls();
}