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
44
AV.cc
44
AV.cc
@ -144,6 +144,17 @@ void AV::playSound(AV::Sound * s)
|
|||||||
SDL_PauseAudio(0);
|
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)
|
void AV::playCallback(Uint8 * stream, int len)
|
||||||
{
|
{
|
||||||
memset(stream, 0, len);
|
memset(stream, 0, len);
|
||||||
@ -209,19 +220,33 @@ bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path)
|
|||||||
|
|
||||||
void AV::Sound::play()
|
void AV::Sound::play()
|
||||||
{
|
{
|
||||||
if (m_ss != NULL)
|
loop(1);
|
||||||
{
|
|
||||||
Sound_Rewind(m_ss);
|
|
||||||
m_av.playSound(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AV::Sound::stop()
|
void AV::Sound::stop()
|
||||||
{
|
{
|
||||||
|
if (m_ss != NULL)
|
||||||
|
{
|
||||||
|
m_av.stopSound(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AV::Sound::loop(int times)
|
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)
|
int AV::Sound::decode(Uint8 * stream, int len)
|
||||||
@ -235,6 +260,15 @@ int AV::Sound::decode(Uint8 * stream, int len)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
len_decoded_now = Sound_Decode(m_ss);
|
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;
|
samples_decoded_now = len_decoded_now / BYTES_PER_SAMPLE;
|
||||||
len_decoded += len_decoded_now;
|
len_decoded += len_decoded_now;
|
||||||
for (int i = 0; i < samples_decoded_now; i++, spos++)
|
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 play();
|
||||||
void stop();
|
void stop();
|
||||||
void loop(int times);
|
void loop(int times);
|
||||||
|
void rewind();
|
||||||
int decode(Uint8 * stream, int len);
|
int decode(Uint8 * stream, int len);
|
||||||
protected:
|
protected:
|
||||||
AV & m_av;
|
AV & m_av;
|
||||||
SDL_RWops * m_rwops;
|
SDL_RWops * m_rwops;
|
||||||
Sound_Sample * m_ss;
|
Sound_Sample * m_ss;
|
||||||
FileLoader::Buffer m_buff;
|
FileLoader::Buffer m_buff;
|
||||||
|
int m_loop_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
AV();
|
AV();
|
||||||
@ -61,6 +63,7 @@ class AV
|
|||||||
}
|
}
|
||||||
refptr<Sound> createSound();
|
refptr<Sound> createSound();
|
||||||
void playSound(Sound * s);
|
void playSound(Sound * s);
|
||||||
|
void stopSound(Sound * s);
|
||||||
|
|
||||||
friend void AV_sound_callback(void * userdata, Uint8 * stream, int len);
|
friend void AV_sound_callback(void * userdata, Uint8 * stream, int len);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user