implemented sound looping, need to clean up decode() to handle it more smoothly
git-svn-id: svn://anubis/anaglym/trunk@288 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
e3c19daa47
commit
8a49a5089e
48
AV.cc
48
AV.cc
@ -144,6 +144,17 @@ void AV::playSound(AV::Sound * s)
|
||||
SDL_PauseAudio(0);
|
||||
}
|
||||
|
||||
void AV::stopSound(AV::Sound * s)
|
||||
{
|
||||
SDL_mutexP(m_active_sounds_mutex);
|
||||
m_active_sounds.erase(s);
|
||||
if (m_active_sounds.size() == 0)
|
||||
{
|
||||
SDL_PauseAudio(1);
|
||||
}
|
||||
SDL_mutexV(m_active_sounds_mutex);
|
||||
}
|
||||
|
||||
void AV::playCallback(Uint8 * stream, int len)
|
||||
{
|
||||
memset(stream, 0, len);
|
||||
@ -168,8 +179,8 @@ AV::Sound::Sound(AV & av)
|
||||
: m_av(av),
|
||||
m_buff(1)
|
||||
{
|
||||
m_rwops = NULL;
|
||||
m_ss = NULL;
|
||||
m_rwops = NULL;
|
||||
m_ss = NULL;
|
||||
}
|
||||
|
||||
AV::Sound::~Sound()
|
||||
@ -209,19 +220,33 @@ bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path)
|
||||
|
||||
void AV::Sound::play()
|
||||
{
|
||||
if (m_ss != NULL)
|
||||
{
|
||||
Sound_Rewind(m_ss);
|
||||
m_av.playSound(this);
|
||||
}
|
||||
loop(1);
|
||||
}
|
||||
|
||||
void AV::Sound::stop()
|
||||
{
|
||||
if (m_ss != NULL)
|
||||
{
|
||||
m_av.stopSound(this);
|
||||
}
|
||||
}
|
||||
|
||||
void AV::Sound::loop(int times)
|
||||
{
|
||||
if (m_ss != NULL)
|
||||
{
|
||||
rewind();
|
||||
m_loop_count = times;
|
||||
m_av.playSound(this);
|
||||
}
|
||||
}
|
||||
|
||||
void AV::Sound::rewind()
|
||||
{
|
||||
if (m_ss != NULL)
|
||||
{
|
||||
Sound_Rewind(m_ss);
|
||||
}
|
||||
}
|
||||
|
||||
int AV::Sound::decode(Uint8 * stream, int len)
|
||||
@ -235,6 +260,15 @@ int AV::Sound::decode(Uint8 * stream, int len)
|
||||
do
|
||||
{
|
||||
len_decoded_now = Sound_Decode(m_ss);
|
||||
if (len_decoded_now == 0)
|
||||
{
|
||||
if (m_loop_count > 0)
|
||||
{
|
||||
rewind();
|
||||
m_loop_count--;
|
||||
len_decoded_now = Sound_Decode(m_ss);
|
||||
}
|
||||
}
|
||||
samples_decoded_now = len_decoded_now / BYTES_PER_SAMPLE;
|
||||
len_decoded += len_decoded_now;
|
||||
for (int i = 0; i < samples_decoded_now; i++, spos++)
|
||||
|
3
AV.h
3
AV.h
@ -23,12 +23,14 @@ class AV
|
||||
void play();
|
||||
void stop();
|
||||
void loop(int times);
|
||||
void rewind();
|
||||
int decode(Uint8 * stream, int len);
|
||||
protected:
|
||||
AV & m_av;
|
||||
SDL_RWops * m_rwops;
|
||||
Sound_Sample * m_ss;
|
||||
FileLoader::Buffer m_buff;
|
||||
int m_loop_count;
|
||||
};
|
||||
|
||||
AV();
|
||||
@ -61,6 +63,7 @@ class AV
|
||||
}
|
||||
refptr<Sound> createSound();
|
||||
void playSound(Sound * s);
|
||||
void stopSound(Sound * s);
|
||||
|
||||
friend void AV_sound_callback(void * userdata, Uint8 * stream, int len);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user