00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "gui.h"
00012
00013
00014
00015
00016 GuiSound::GuiSound(const u8 * snd, s32 len, int t)
00017 {
00018 sound = snd;
00019 length = len;
00020 type = t;
00021 voice = -1;
00022 volume = 100;
00023 loop = false;
00024 }
00025
00026
00027
00028
00029 GuiSound::~GuiSound()
00030 {
00031 #ifndef NO_SOUND
00032 if(type == SOUND_OGG)
00033 StopOgg();
00034 #endif
00035 }
00036
00037 void GuiSound::Play()
00038 {
00039 #ifndef NO_SOUND
00040 int vol;
00041
00042 switch(type)
00043 {
00044 case SOUND_PCM:
00045 vol = 255*(volume/100.0);
00046 voice = ASND_GetFirstUnusedVoice();
00047 if(voice >= 0)
00048 ASND_SetVoice(voice, VOICE_STEREO_16BIT, 48000, 0,
00049 (u8 *)sound, length, vol, vol, NULL);
00050 break;
00051
00052 case SOUND_OGG:
00053 voice = 0;
00054 if(loop)
00055 PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME);
00056 else
00057 PlayOgg((char *)sound, length, 0, OGG_ONE_TIME);
00058 SetVolumeOgg(255*(volume/100.0));
00059 break;
00060 }
00061 #endif
00062 }
00063
00064 void GuiSound::Stop()
00065 {
00066 #ifndef NO_SOUND
00067 if(voice < 0)
00068 return;
00069
00070 switch(type)
00071 {
00072 case SOUND_PCM:
00073 ASND_StopVoice(voice);
00074 break;
00075
00076 case SOUND_OGG:
00077 StopOgg();
00078 break;
00079 }
00080 #endif
00081 }
00082
00083 void GuiSound::Pause()
00084 {
00085 #ifndef NO_SOUND
00086 if(voice < 0)
00087 return;
00088
00089 switch(type)
00090 {
00091 case SOUND_PCM:
00092 ASND_PauseVoice(voice, 1);
00093 break;
00094
00095 case SOUND_OGG:
00096 PauseOgg(1);
00097 break;
00098 }
00099 #endif
00100 }
00101
00102 void GuiSound::Resume()
00103 {
00104 #ifndef NO_SOUND
00105 if(voice < 0)
00106 return;
00107
00108 switch(type)
00109 {
00110 case SOUND_PCM:
00111 ASND_PauseVoice(voice, 0);
00112 break;
00113
00114 case SOUND_OGG:
00115 PauseOgg(0);
00116 break;
00117 }
00118 #endif
00119 }
00120
00121 bool GuiSound::IsPlaying()
00122 {
00123 if(ASND_StatusVoice(voice) == SND_WORKING || ASND_StatusVoice(voice) == SND_WAITING)
00124 return true;
00125 else
00126 return false;
00127 }
00128
00129 void GuiSound::SetVolume(int vol)
00130 {
00131 #ifndef NO_SOUND
00132 volume = vol;
00133
00134 if(voice < 0)
00135 return;
00136
00137 int newvol = 255*(volume/100.0);
00138
00139 switch(type)
00140 {
00141 case SOUND_PCM:
00142 ASND_ChangeVolumeVoice(voice, newvol, newvol);
00143 break;
00144
00145 case SOUND_OGG:
00146 SetVolumeOgg(255*(volume/100.0));
00147 break;
00148 }
00149 #endif
00150 }
00151
00152 void GuiSound::SetLoop(bool l)
00153 {
00154 loop = l;
00155 }