diff --git a/AV.cc b/AV.cc index 83ca517..80a0360 100644 --- a/AV.cc +++ b/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) );