snes9xgx/source/gui/gui_sound.cpp

156 lines
2.3 KiB
C++
Raw Normal View History

2009-03-11 18:28:37 +01:00
/****************************************************************************
2009-04-10 10:12:37 +02:00
* libwiigui
2009-03-11 18:28:37 +01:00
*
2009-04-10 10:12:37 +02:00
* Tantric 2009
2009-03-11 18:28:37 +01:00
*
* gui_sound.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
/**
* Constructor for the GuiSound class.
*/
2009-10-17 02:15:58 +02:00
GuiSound::GuiSound(const u8 * s, s32 l, int t)
2009-03-11 18:28:37 +01:00
{
2009-10-17 02:15:58 +02:00
sound = s;
length = l;
2009-03-11 18:28:37 +01:00
type = t;
voice = -1;
volume = 100;
2009-04-05 03:51:56 +02:00
loop = false;
2009-03-11 18:28:37 +01:00
}
/**
* Destructor for the GuiSound class.
*/
GuiSound::~GuiSound()
{
2009-04-05 03:51:56 +02:00
#ifndef NO_SOUND
if(type == SOUND_OGG)
StopOgg();
#endif
2009-03-11 18:28:37 +01:00
}
void GuiSound::Play()
{
#ifndef NO_SOUND
int vol;
switch(type)
{
case SOUND_PCM:
2010-01-25 08:34:45 +01:00
vol = 2.55f*(volume*GCSettings.SFXVolume);
2009-03-11 18:28:37 +01:00
voice = ASND_GetFirstUnusedVoice();
if(voice >= 0)
2009-04-05 03:51:56 +02:00
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 48000, 0,
2009-03-11 18:28:37 +01:00
(u8 *)sound, length, vol, vol, NULL);
break;
case SOUND_OGG:
voice = 0;
2009-04-05 03:51:56 +02:00
if(loop)
PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME);
2009-04-05 03:51:56 +02:00
else
PlayOgg((char *)sound, length, 0, OGG_ONE_TIME);
2010-01-25 08:34:45 +01:00
SetVolumeOgg(2.55f*(volume));
2009-03-11 18:28:37 +01:00
break;
}
#endif
}
void GuiSound::Stop()
{
#ifndef NO_SOUND
if(voice < 0)
return;
switch(type)
{
case SOUND_PCM:
ASND_StopVoice(voice);
break;
case SOUND_OGG:
StopOgg();
break;
}
#endif
}
void GuiSound::Pause()
{
#ifndef NO_SOUND
if(voice < 0)
return;
switch(type)
{
case SOUND_PCM:
ASND_PauseVoice(voice, 1);
break;
case SOUND_OGG:
PauseOgg(1);
break;
}
#endif
}
void GuiSound::Resume()
{
#ifndef NO_SOUND
if(voice < 0)
return;
switch(type)
{
case SOUND_PCM:
ASND_PauseVoice(voice, 0);
break;
case SOUND_OGG:
PauseOgg(0);
break;
}
#endif
}
2009-04-05 03:51:56 +02:00
bool GuiSound::IsPlaying()
{
if(ASND_StatusVoice(voice) == SND_WORKING || ASND_StatusVoice(voice) == SND_WAITING)
return true;
else
return false;
}
2009-03-11 18:28:37 +01:00
void GuiSound::SetVolume(int vol)
{
#ifndef NO_SOUND
volume = vol;
if(voice < 0)
return;
2010-01-25 08:34:45 +01:00
int newvol = 2.55f*(volume*GCSettings.SFXVolume);
2009-03-11 18:28:37 +01:00
switch(type)
{
case SOUND_PCM:
ASND_ChangeVolumeVoice(voice, newvol, newvol);
break;
case SOUND_OGG:
2010-01-25 08:34:45 +01:00
SetVolumeOgg(2.55f*(volume));
2009-03-11 18:28:37 +01:00
break;
}
#endif
}
2009-04-05 03:51:56 +02:00
void GuiSound::SetLoop(bool l)
{
loop = l;
}