fixed audio decoding bug, sounds can play now!
git-svn-id: svn://anubis/anaglym/trunk@285 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
a4024bfd2c
commit
1705af029d
16
AV.cc
16
AV.cc
@ -191,7 +191,7 @@ bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path)
|
||||
desired.format = AUDIO_S16SYS;
|
||||
desired.rate = SOUND_RATE;
|
||||
m_ss = Sound_NewSample(m_rwops, NULL, &desired,
|
||||
CALLBACK_SAMPLES * BYTES_PER_SAMPLE * CHANNELS);
|
||||
CALLBACK_SAMPLES * BYTES_PER_SAMPLE);
|
||||
if (m_ss != NULL)
|
||||
{
|
||||
return true;
|
||||
@ -211,11 +211,7 @@ void AV::Sound::play()
|
||||
{
|
||||
if (m_ss != NULL)
|
||||
{
|
||||
#if 0
|
||||
cerr << "play()" << endl;
|
||||
Sound_Rewind(m_ss);
|
||||
cerr << "end play()" << endl;
|
||||
#endif
|
||||
m_av.playSound(this);
|
||||
}
|
||||
}
|
||||
@ -233,6 +229,7 @@ int AV::Sound::decode(Uint8 * stream, int len)
|
||||
int len_decoded = 0, len_decoded_now;
|
||||
int samples_decoded_now;
|
||||
int spos = 0;
|
||||
int len_samples = len / BYTES_PER_SAMPLE;
|
||||
int16_t * s16stream = (int16_t *) stream;
|
||||
int16_t * decoded_stream = (int16_t *) m_ss->buffer;
|
||||
do
|
||||
@ -240,11 +237,16 @@ int AV::Sound::decode(Uint8 * stream, int len)
|
||||
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++)
|
||||
for (int i = 0; i < samples_decoded_now; i++, spos++)
|
||||
{
|
||||
if (spos >= len_samples)
|
||||
{
|
||||
cerr << "Sorry, anaglym bug in " __FILE__ ":" << __LINE__
|
||||
<< ": rework sound buffer sizes" << endl;
|
||||
exit(33);
|
||||
}
|
||||
int val = s16stream[spos] + decoded_stream[i];
|
||||
s16stream[spos] = (val > SHRT_MAX) ? SHRT_MAX : val;
|
||||
spos++;
|
||||
}
|
||||
} while ( (len_decoded_now == (int) m_ss->buffer_size)
|
||||
&& (len_decoded < len) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user