#include "pch.hpp"
//===========================================================================//
// File:	 Sound Mixer.cpp										         //
// Project:  GameOS					                                         //
// Contents: Sound Mixer													 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 03/23/99  JTR    Created													 //
//																			 //
//---------------------------------------------------------------------------//
// Copyright (C) 1998-1999, Microsoft, Inc.									 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "Sound Renderer.hpp"
#include "Music.hpp"

extern SoundRendererData g_SRData;
extern gos_Music * g_activeMusicList;

SoundMixer::SoundMixer()
{
	// setup standard stuff
	m_fVolume = 1.0f;
	// setup default factors
	m_dopplerFactor = 1.0f; 
	m_rolloffFactor = 1.0f; 	
	m_distanceFactor = 1.0f;	
	m_reverbFactor = .1f;	
	m_decayFactor = 0.0f; 

	// setup default positional information
	m_orientation3DFront.x = m_orientation3DFront.y = m_orientation3DTop.x   =  m_orientation3DTop.z   = 0.0f;
	m_orientation3DFront.z = m_orientation3DTop.y = 1.0f;
	m_position3D.x = m_position3D.y = m_position3D.z = 0.0f;
	m_velocity3D.x = m_velocity3D.y = m_velocity3D.z = 0.0f;

	// setup the mixer's format
	memset ( &m_waveFormatEx, 0, sizeof( WAVEFORMATEX) );
	m_waveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
	m_waveFormatEx.nChannels = 2;
	m_waveFormatEx.nBlockAlign = 4;
	m_waveFormatEx.wBitsPerSample = 16;
	if (Environment.soundHiFi)
	{
		m_waveFormatEx.nSamplesPerSec = 44100;
		m_waveFormatEx.nAvgBytesPerSec = 176400;
	}
	else
	{
		m_waveFormatEx.nSamplesPerSec = 22050;
		m_waveFormatEx.nAvgBytesPerSec = 88200;
	}

	m_freeHW3DChannels = m_totalHW3DChannels = m_freeHWMemory = m_totalHWMemory = 0;
	m_changed = false;
}

SoundMixer::~SoundMixer()
{
}

void SoundMixer::Pause()
{
}

void SoundMixer::Continue()
{
}

void SoundMixer::Clear()
{
}

void SoundMixer::Flush()
{
}

void SoundMixer::SetVolume(float volume)
{
	gosASSERT(volume >= 0.0f && volume <= 1.0f);
	m_fVolume = volume;

	for(int i = 0; i < g_SRData.m_numSoundChannels; i++)
	{
		g_SRData.m_soundChannel[i]->SetVolume(g_SRData.m_soundChannel[i]->m_fVolume);
	}

	HGOSMUSIC music = g_activeMusicList;
	while(music)
	{
		gosMusic_Command(music, gosMusic_Volume, music->m_fVolume);
		music = music->m_pNext;
	}

}

void SoundMixer::SetPosition(float x, float y, float z)
{
	m_position3D.x = x;
	m_position3D.y = y;
	m_position3D.z = z;
}

void SoundMixer::SetVelocity(float x, float y, float z)
{
	m_velocity3D.x = x;
	m_velocity3D.y = y;
	m_velocity3D.z = z;
}

void SoundMixer::SetTopOrientation(float x, float y, float z)
{
	m_orientation3DTop.x = x;
	m_orientation3DTop.y = y;
	m_orientation3DTop.z = z;
}

void SoundMixer::SetFrontOrientation(float x, float y, float z)
{
	m_orientation3DFront.x = x;
	m_orientation3DFront.y = y;
	m_orientation3DFront.z = z;
}

void SoundMixer::SetDopplerFactor(float df)
{
	m_dopplerFactor = df;
}

void SoundMixer::SetRolloffFactor(float rf)
{
	m_rolloffFactor = rf;
}

void SoundMixer::SetDistanceFactor(float df)
{
	m_distanceFactor = df;
}

void SoundMixer::SetReverbFactor(float rf)
{
	m_reverbFactor = rf;
}

void SoundMixer::SetDecayFactor(float df)
{
	m_decayFactor = df;
}

void SoundMixer::Reset()
{
}

void SoundMixer::GetHardwareData()
{
}

void SoundMixer::SetSpeakerConfig(DWORD)
{
}

void SoundMixer::GetSpeakerConfig(DWORD *)
{
}