mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2025-01-11 19:39:09 +01:00
-fixed wrong played default wiiflow sounds (issue 23)
also replaced all spaces by tabs in the gui_sound.cpp ;) -made the default wave sounds smaller
This commit is contained in:
parent
8ed9ea593d
commit
649dfd6731
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -31,45 +31,46 @@
|
|||||||
#include "WavDecoder.hpp"
|
#include "WavDecoder.hpp"
|
||||||
#include "loader/sys.h"
|
#include "loader/sys.h"
|
||||||
|
|
||||||
#define MAX_SND_VOICES 16
|
#define MAX_SND_VOICES 16
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static bool VoiceUsed[MAX_SND_VOICES] =
|
static bool VoiceUsed[MAX_SND_VOICES] =
|
||||||
{
|
{
|
||||||
true, false, false, false, false, false,
|
true, false, false, false, false, false,
|
||||||
false, false, false, false, false, false,
|
false, false, false, false, false, false,
|
||||||
false, false, false, false
|
false, false, false, false
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int GetFirstUnusedVoice()
|
static inline int GetFirstUnusedVoice()
|
||||||
{
|
{
|
||||||
for(int i = 1; i < MAX_SND_VOICES; i++)
|
for(int i = 1; i < MAX_SND_VOICES; i++)
|
||||||
{
|
{
|
||||||
if(VoiceUsed[i] == false)
|
if(VoiceUsed[i] == false)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
gprintf("ALL VOICES USED UP!!\n");
|
gprintf("ALL VOICES USED UP!!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void SoundCallback(s32 voice)
|
extern "C" void SoundCallback(s32 voice)
|
||||||
{
|
{
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder) return;
|
if(!decoder)
|
||||||
|
return;
|
||||||
|
|
||||||
if(decoder->IsBufferReady())
|
if(decoder->IsBufferReady())
|
||||||
{
|
{
|
||||||
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
|
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
|
||||||
{
|
{
|
||||||
decoder->LoadNext();
|
decoder->LoadNext();
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(decoder->IsEOF())
|
else if(decoder->IsEOF())
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
else
|
else
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiSound::GuiSound()
|
GuiSound::GuiSound()
|
||||||
@ -98,8 +99,9 @@ GuiSound::GuiSound(GuiSound *g)
|
|||||||
voice = -1;
|
voice = -1;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
if (g == NULL) return;
|
if (g == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (g->sound != NULL)
|
if (g->sound != NULL)
|
||||||
{
|
{
|
||||||
u8 * snd = (u8 *) malloc(g->length);
|
u8 * snd = (u8 *) malloc(g->length);
|
||||||
@ -123,9 +125,9 @@ void GuiSound::Init()
|
|||||||
|
|
||||||
if (voice == -1)
|
if (voice == -1)
|
||||||
voice = GetFirstUnusedVoice();
|
voice = GetFirstUnusedVoice();
|
||||||
if(voice > 0)
|
if(voice > 0)
|
||||||
VoiceUsed[voice] = true;
|
VoiceUsed[voice] = true;
|
||||||
|
|
||||||
volume = 255;
|
volume = 255;
|
||||||
SoundEffectLength = 0;
|
SoundEffectLength = 0;
|
||||||
loop = false;
|
loop = false;
|
||||||
@ -140,94 +142,89 @@ void GuiSound::FreeMemory()
|
|||||||
if (!Sys_Exiting())
|
if (!Sys_Exiting())
|
||||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||||
|
|
||||||
if(allocated)
|
if(allocated)
|
||||||
{
|
{
|
||||||
SAFE_FREE(sound);
|
SAFE_FREE(sound);
|
||||||
allocated = false;
|
allocated = false;
|
||||||
}
|
}
|
||||||
filepath = "";
|
filepath = "";
|
||||||
|
|
||||||
SoundEffectLength = 0;
|
SoundEffectLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::Load(const char * filepath)
|
bool GuiSound::Load(const char * filepath)
|
||||||
{
|
{
|
||||||
FreeMemory();
|
FreeMemory();
|
||||||
|
|
||||||
if(!filepath || filepath[strlen(filepath)-1] == '/' || strlen(filepath) < 4)
|
if(!filepath || filepath[strlen(filepath)-1] == '/' || strlen(filepath) < 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FILE * f = fopen(filepath, "rb");
|
FILE * f = fopen(filepath, "rb");
|
||||||
if(!f)
|
if(!f)
|
||||||
{ gprintf("Failed to load file %s!!\n", filepath);
|
{
|
||||||
return false;
|
gprintf("Failed to load file %s!!\n", filepath);
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
u32 magic;
|
|
||||||
fread(&magic, 1, 4, f);
|
u32 magic;
|
||||||
fclose(f);
|
fread(&magic, 1, 4, f);
|
||||||
|
fclose(f);
|
||||||
SoundHandler::Instance()->AddDecoder(voice, filepath);
|
|
||||||
gprintf("Loading %s using voice %d\n", filepath, voice);
|
SoundHandler::Instance()->AddDecoder(voice, filepath);
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
gprintf("Loading %s using voice %d\n", filepath, voice);
|
||||||
if(!decoder)
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
{ gprintf("No Decoder!!!\n");
|
if(!decoder)
|
||||||
|
{
|
||||||
|
gprintf("No Decoder!!!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!decoder->IsBufferReady())
|
||||||
|
{
|
||||||
|
gprintf("Buffer not ready!!n");
|
||||||
|
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!decoder->IsBufferReady())
|
|
||||||
{ gprintf("Buffer not ready!!n");
|
|
||||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->filepath = filepath;
|
this->filepath = filepath;
|
||||||
SetLoop(loop);
|
SetLoop(loop);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
|
bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
|
||||||
{
|
{
|
||||||
FreeMemory();
|
FreeMemory();
|
||||||
this->voice = voice;
|
this->voice = voice;
|
||||||
|
|
||||||
if(!snd)
|
if(!snd)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!isallocated && *((u32 *) snd) == 'RIFF')
|
||||||
|
return LoadSoundEffect(snd, len);
|
||||||
|
|
||||||
|
if(*((u32 *) snd) == 'IMD5')
|
||||||
|
UncompressSoundbin(snd, len, isallocated);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return false;
|
sound = (u8 *) snd;
|
||||||
|
length = len;
|
||||||
|
allocated = isallocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isallocated && *((u32 *) snd) == 'RIFF')
|
SoundHandler::Instance()->AddDecoder(this->voice, sound, length);
|
||||||
{
|
|
||||||
return LoadSoundEffect(snd, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(*((u32 *) snd) == 'IMD5')
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
{
|
if(!decoder)
|
||||||
UncompressSoundbin(snd, len, isallocated);
|
return false;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sound = (u8 *) snd;
|
|
||||||
length = len;
|
|
||||||
allocated = isallocated;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundHandler::Instance()->AddDecoder(this->voice, sound, length);
|
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
if(!decoder->IsBufferReady())
|
||||||
if(!decoder)
|
|
||||||
{
|
{
|
||||||
return false;
|
SoundHandler::Instance()->RemoveDecoder(voice);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!decoder->IsBufferReady())
|
SetLoop(loop);
|
||||||
{
|
|
||||||
SoundHandler::Instance()->RemoveDecoder(voice);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetLoop(loop);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -236,77 +233,71 @@ bool GuiSound::LoadSoundEffect(const u8 * snd, u32 len)
|
|||||||
{
|
{
|
||||||
FreeMemory();
|
FreeMemory();
|
||||||
|
|
||||||
WavDecoder decoder(snd, len);
|
WavDecoder decoder(snd, len);
|
||||||
decoder.Rewind();
|
decoder.Rewind();
|
||||||
|
|
||||||
u32 done = 0;
|
u32 done = 0;
|
||||||
sound = (u8 *) malloc(4096);
|
sound = (u8 *) malloc(4096);
|
||||||
memset(sound, 0, 4096);
|
memset(sound, 0, 4096);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
u8 * tmpsnd = (u8 *) realloc(sound, done+4096);
|
u8 * tmpsnd = (u8 *) realloc(sound, done+4096);
|
||||||
if(!tmpsnd)
|
if(!tmpsnd)
|
||||||
{
|
{
|
||||||
SAFE_FREE(sound);
|
SAFE_FREE(sound);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sound = tmpsnd;
|
sound = tmpsnd;
|
||||||
|
|
||||||
int read = decoder.Read(sound+done, 4096, done);
|
int read = decoder.Read(sound+done, 4096, done);
|
||||||
if(read <= 0)
|
if(read <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
done += read;
|
done += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
sound = (u8 *) realloc(sound, done);
|
sound = (u8 *) realloc(sound, done);
|
||||||
SoundEffectLength = done;
|
SoundEffectLength = done;
|
||||||
allocated = true;
|
allocated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Play(int vol, bool restart)
|
void GuiSound::Play(int vol, bool restart)
|
||||||
{
|
{
|
||||||
if(SoundEffectLength > 0)
|
if(SoundEffectLength > 0)
|
||||||
{
|
|
||||||
ASND_StopVoice(voice);
|
|
||||||
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 32000, 0, sound, SoundEffectLength, vol, vol, NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(IsPlaying() && !restart)
|
|
||||||
{
|
{
|
||||||
|
ASND_StopVoice(voice);
|
||||||
|
ASND_SetVoice(voice, VOICE_MONO_16BIT, 22050, 0, sound, SoundEffectLength, vol, vol, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(IsPlaying() && !restart)
|
||||||
|
return;
|
||||||
|
|
||||||
if(voice < 0 || voice >= 16)
|
if(voice < 0 || voice >= 16)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
if(!decoder)
|
||||||
if(!decoder)
|
return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
if(decoder->IsEOF())
|
if(decoder->IsEOF())
|
||||||
{
|
{
|
||||||
decoder->ClearBuffer();
|
decoder->ClearBuffer();
|
||||||
decoder->Rewind();
|
decoder->Rewind();
|
||||||
decoder->Decode();
|
decoder->Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 * curbuffer = decoder->GetBuffer();
|
u8 * curbuffer = decoder->GetBuffer();
|
||||||
int bufsize = decoder->GetBufferSize();
|
int bufsize = decoder->GetBufferSize();
|
||||||
decoder->LoadNext();
|
decoder->LoadNext();
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
|
|
||||||
ASND_SetVoice(voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback);
|
ASND_SetVoice(voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Play()
|
void GuiSound::Play()
|
||||||
@ -323,16 +314,14 @@ void GuiSound::Stop()
|
|||||||
|
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
{
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder->ClearBuffer();
|
decoder->ClearBuffer();
|
||||||
Rewind();
|
Rewind();
|
||||||
|
|
||||||
SoundHandler::Instance()->ThreadSignal();
|
SoundHandler::Instance()->ThreadSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Pause()
|
void GuiSound::Pause()
|
||||||
@ -340,12 +329,12 @@ void GuiSound::Pause()
|
|||||||
if(voice < 0 || voice >= 16)
|
if(voice < 0 || voice >= 16)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ASND_StopVoice(voice);
|
ASND_StopVoice(voice);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Resume()
|
void GuiSound::Resume()
|
||||||
{
|
{
|
||||||
Play();
|
Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GuiSound::IsPlaying()
|
bool GuiSound::IsPlaying()
|
||||||
@ -353,7 +342,7 @@ bool GuiSound::IsPlaying()
|
|||||||
if(voice < 0 || voice >= 16)
|
if(voice < 0 || voice >= 16)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int result = ASND_StatusVoice(voice);
|
int result = ASND_StatusVoice(voice);
|
||||||
|
|
||||||
if(result == SND_WORKING || result == SND_WAITING)
|
if(result == SND_WORKING || result == SND_WAITING)
|
||||||
return true;
|
return true;
|
||||||
@ -375,33 +364,33 @@ void GuiSound::SetVolume(int vol)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
volume = vol;
|
volume = vol;
|
||||||
ASND_ChangeVolumeVoice(voice, volume, volume);
|
ASND_ChangeVolumeVoice(voice, volume, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::SetLoop(u8 l)
|
void GuiSound::SetLoop(u8 l)
|
||||||
{
|
{
|
||||||
loop = l;
|
loop = l;
|
||||||
|
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
decoder->SetLoop(l == 1);
|
decoder->SetLoop(l == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiSound::Rewind()
|
void GuiSound::Rewind()
|
||||||
{
|
{
|
||||||
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
|
||||||
if(!decoder)
|
if(!decoder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
decoder->Rewind();
|
decoder->Rewind();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct _LZ77Info
|
struct _LZ77Info
|
||||||
{
|
{
|
||||||
u16 length : 4;
|
u16 length : 4;
|
||||||
u16 offset : 12;
|
u16 offset : 12;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef struct _LZ77Info LZ77Info;
|
typedef struct _LZ77Info LZ77Info;
|
||||||
@ -439,7 +428,7 @@ u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * size)
|
|||||||
inBuf += sizeof (LZ77Info);
|
inBuf += sizeof (LZ77Info);
|
||||||
int length = info->length + 3;
|
int length = info->length + 3;
|
||||||
if (bufCur - info->offset - 1 < buffer || bufCur + length > bufEnd)
|
if (bufCur - info->offset - 1 < buffer || bufCur + length > bufEnd)
|
||||||
return buffer;
|
return buffer;
|
||||||
memcpy(bufCur, bufCur - info->offset - 1, length);
|
memcpy(bufCur, bufCur - info->offset - 1, length);
|
||||||
bufCur += length;
|
bufCur += length;
|
||||||
}
|
}
|
||||||
@ -460,40 +449,41 @@ u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * size)
|
|||||||
|
|
||||||
void GuiSound::UncompressSoundbin(const u8 * snd, u32 len, bool isallocated)
|
void GuiSound::UncompressSoundbin(const u8 * snd, u32 len, bool isallocated)
|
||||||
{
|
{
|
||||||
const u8 * file = snd+32;
|
const u8 * file = snd+32;
|
||||||
|
|
||||||
length = len-32;
|
length = len-32;
|
||||||
if (length <= 0) return;
|
if (length <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if(*((u32 *) file) == 'LZ77')
|
if(*((u32 *) file) == 'LZ77')
|
||||||
{
|
|
||||||
u32 size = 0;
|
|
||||||
sound = uncompressLZ77(file, length, &size);
|
|
||||||
if (!sound)
|
|
||||||
{
|
|
||||||
length = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
length = size;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sound = (u8 *) malloc(length);
|
|
||||||
if (!sound)
|
|
||||||
{
|
|
||||||
length = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
memcpy(sound, file, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isallocated)
|
|
||||||
{
|
{
|
||||||
void *p = (void *) snd;
|
u32 size = 0;
|
||||||
SAFE_FREE(p);
|
sound = uncompressLZ77(file, length, &size);
|
||||||
|
if (!sound)
|
||||||
|
{
|
||||||
|
length = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
length = size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sound = (u8 *) malloc(length);
|
||||||
|
if (!sound)
|
||||||
|
{
|
||||||
|
length = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(sound, file, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
allocated = true;
|
if(isallocated)
|
||||||
|
{
|
||||||
|
void *p = (void *) snd;
|
||||||
|
SAFE_FREE(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
allocated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void soundInit(void)
|
void soundInit(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user