mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-23 19:16:21 +00:00
CHEWY: Fix pops at start of SFX and speech
SFX and speech data are actually VOC format without the header. This was not correctly processed and non-audio data was played as audio, causing popping. This commit adds a VocStream subclass to handle this variant of the VOC format.
This commit is contained in:
parent
79c778c6c9
commit
d81d6e593e
63
engines/chewy/audio/chewy_voc.cpp
Normal file
63
engines/chewy/audio/chewy_voc.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "chewy/audio/chewy_voc.h"
|
||||
|
||||
#include "common/stream.h"
|
||||
|
||||
namespace Chewy {
|
||||
|
||||
ChewyVocStream::ChewyVocStream(Common::SeekableReadStream* stream, DisposeAfterUse::Flag disposeAfterUse) :
|
||||
VocStream(stream, true, disposeAfterUse) {
|
||||
removeHeaders();
|
||||
}
|
||||
|
||||
void ChewyVocStream::removeHeaders() {
|
||||
// Check the sample blocks for non-standard headers.
|
||||
for (BlockList::iterator i = _blocks.begin(), end = _blocks.end(); i != end; ++i) {
|
||||
if (i->code == 1 && i->sampleBlock.samples > 80) {
|
||||
// Found a sample block. Check for the headers.
|
||||
int headerSize = 0;
|
||||
if (_stream->readUint32BE() == FOURCC_RIFF) {
|
||||
// Found a RIFF header.
|
||||
headerSize = 44;
|
||||
} else {
|
||||
_stream->seek(i->sampleBlock.offset + 76);
|
||||
if (_stream->readUint32BE() == FOURCC_SCRS) {
|
||||
// Found an SCRS (?) header.
|
||||
headerSize = 80;
|
||||
}
|
||||
}
|
||||
|
||||
if (headerSize > 0) {
|
||||
// Move the offset past the header and adjust the length.
|
||||
i->sampleBlock.offset += headerSize;
|
||||
i->sampleBlock.samples -= headerSize;
|
||||
_length = _length.addFrames(-headerSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the stream.
|
||||
rewind();
|
||||
}
|
||||
|
||||
} // End of namespace Chewy
|
49
engines/chewy/audio/chewy_voc.h
Normal file
49
engines/chewy/audio/chewy_voc.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CHEWY_AUDIO_CHEWY_VOC_H
|
||||
#define CHEWY_AUDIO_CHEWY_VOC_H
|
||||
|
||||
#include "audio/decoders/voc.h"
|
||||
|
||||
#include "common/endian.h"
|
||||
|
||||
namespace Chewy {
|
||||
|
||||
// This stream differs from the standard VOC stream on 2 points:
|
||||
// - VOC data header is not present, so not processed.
|
||||
// - Some VOC blocks contain non-standard headers. These are removed because
|
||||
// otherwise they will be interpreted as audio data and cause static.
|
||||
class ChewyVocStream : public Audio::VocStream {
|
||||
protected:
|
||||
static const uint32 FOURCC_SCRS = MKTAG('S', 'C', 'R', 'S');
|
||||
static const uint32 FOURCC_RIFF = MKTAG('R', 'I', 'F', 'F');
|
||||
|
||||
public:
|
||||
ChewyVocStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse);
|
||||
|
||||
protected:
|
||||
void removeHeaders();
|
||||
};
|
||||
|
||||
} // End of namespace Audio
|
||||
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "chewy/music/module_tmf.h"
|
||||
#include "chewy/audio/module_tmf.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/stream.h"
|
@ -19,9 +19,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "chewy/music/tmf_stream.h"
|
||||
#include "chewy/audio/tmf_stream.h"
|
||||
|
||||
#include "chewy/music/module_tmf.h"
|
||||
#include "chewy/audio/module_tmf.h"
|
||||
|
||||
Chewy::TMFStream::TMFStream(Common::SeekableReadStream *stream, int offs) : ProtrackerStream(44100, true) {
|
||||
_module = new Module_TMF();
|
@ -29,14 +29,15 @@ MODULE_OBJS = \
|
||||
text.o \
|
||||
timer.o \
|
||||
types.o \
|
||||
audio/chewy_voc.o \
|
||||
audio/module_tmf.o \
|
||||
audio/tmf_stream.o \
|
||||
dialogs/cinema.o \
|
||||
dialogs/credits.o \
|
||||
dialogs/files.o \
|
||||
dialogs/inventory.o \
|
||||
dialogs/main_menu.o \
|
||||
dialogs/options.o \
|
||||
music/module_tmf.o \
|
||||
music/tmf_stream.o \
|
||||
video/cfo_decoder.o \
|
||||
video/video_player.o \
|
||||
rooms/room00.o \
|
||||
|
@ -287,42 +287,11 @@ SoundChunk *SoundResource::getSound(uint num) {
|
||||
|
||||
Chunk *chunk = &_chunkList[num];
|
||||
SoundChunk *sound = new SoundChunk();
|
||||
sound->size = chunk->size;
|
||||
sound->data = new uint8[sound->size];
|
||||
|
||||
_stream.seek(chunk->pos, SEEK_SET);
|
||||
|
||||
uint8 blocksRemaining;
|
||||
uint32 totalLength = 0;
|
||||
uint32 blockSize;
|
||||
|
||||
do {
|
||||
blocksRemaining = _stream.readByte();
|
||||
|
||||
uint8 b1 = _stream.readByte();
|
||||
uint8 b2 = _stream.readByte();
|
||||
uint8 b3 = _stream.readByte();
|
||||
blockSize = b1 + (b2 << 8) + (b3 << 16);
|
||||
|
||||
totalLength += blockSize;
|
||||
_stream.skip(blockSize);
|
||||
} while (blocksRemaining > 1);
|
||||
|
||||
sound->size = totalLength;
|
||||
sound->data = new uint8[totalLength];
|
||||
uint8 *ptr = sound->data;
|
||||
|
||||
_stream.seek(chunk->pos, SEEK_SET);
|
||||
|
||||
do {
|
||||
blocksRemaining = _stream.readByte();
|
||||
|
||||
uint8 b1 = _stream.readByte();
|
||||
uint8 b2 = _stream.readByte();
|
||||
uint8 b3 = _stream.readByte();
|
||||
blockSize = b1 + (b2 << 8) + (b3 << 16);
|
||||
|
||||
_stream.read(ptr, blockSize);
|
||||
ptr += blockSize;
|
||||
} while (blocksRemaining > 1);
|
||||
_stream.read(sound->data, sound->size);
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
@ -24,12 +24,14 @@
|
||||
#include "audio/decoders/raw.h"
|
||||
#include "audio/mods/protracker.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/memstream.h"
|
||||
#include "common/system.h"
|
||||
#include "chewy/resource.h"
|
||||
#include "chewy/sound.h"
|
||||
#include "chewy/types.h"
|
||||
#include "chewy/globals.h"
|
||||
#include "chewy/music/tmf_stream.h"
|
||||
#include "chewy/audio/chewy_voc.h"
|
||||
#include "chewy/audio/tmf_stream.h"
|
||||
|
||||
namespace Chewy {
|
||||
|
||||
@ -75,10 +77,10 @@ void Sound::playSound(int num, uint channel, bool loop) {
|
||||
|
||||
void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, DisposeAfterUse::Flag dispose) {
|
||||
Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
|
||||
Audio::makeRawStream(data,
|
||||
size, 22050, Audio::FLAG_UNSIGNED,
|
||||
dispose),
|
||||
loop ? 0 : 1);
|
||||
new ChewyVocStream(
|
||||
new Common::MemorySeekableReadWriteStream(data, size, dispose),
|
||||
dispose),
|
||||
loop ? 0 : 1);
|
||||
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream);
|
||||
}
|
||||
@ -175,9 +177,9 @@ void Sound::playSpeech(int num, bool waitForFinish) {
|
||||
delete sound;
|
||||
|
||||
// Play it
|
||||
Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
|
||||
Audio::makeRawStream(data, size, 22050, Audio::FLAG_UNSIGNED,
|
||||
DisposeAfterUse::YES), 1);
|
||||
Audio::AudioStream *stream = new ChewyVocStream(
|
||||
new Common::MemorySeekableReadWriteStream(data, size, DisposeAfterUse::YES),
|
||||
DisposeAfterUse::YES);
|
||||
|
||||
_mixer->playStream(Audio::Mixer::kSpeechSoundType,
|
||||
&_speechHandle, stream);
|
||||
|
Loading…
x
Reference in New Issue
Block a user