18
18
* along with this program; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-0-0/engines/scumm/sound.cpp $
22
* $Id: sound.cpp 45144 2009-10-16 02:02:55Z Kirben $
21
* $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-1-1/engines/scumm/sound.cpp $
22
* $Id: sound.cpp 48500 2010-04-04 09:39:40Z Kirben $
35
35
#include "scumm/sound.h"
36
36
#include "scumm/util.h"
38
#include "sound/adpcm.h"
38
#include "sound/decoders/adpcm.h"
39
39
#include "sound/audiocd.h"
40
#include "sound/flac.h"
40
#include "sound/decoders/flac.h"
41
41
#include "sound/mididrv.h"
42
42
#include "sound/mixer.h"
43
#include "sound/mp3.h"
44
#include "sound/voc.h"
45
#include "sound/vorbis.h"
46
#include "sound/wave.h"
43
#include "sound/decoders/mp3.h"
44
#include "sound/decoders/raw.h"
45
#include "sound/decoders/voc.h"
46
#include "sound/decoders/vorbis.h"
47
#include "sound/decoders/wave.h"
160
161
void Sound::playSound(int soundID) {
164
Audio::AudioStream *stream;
165
byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
167
// FIXME: Sound resources are currently missing
168
if (_vm->_game.id == GID_LOOM && _vm->_game.platform == Common::kPlatformPCEngine)
168
if (_vm->_game.id == GID_LOOM && _vm->_game.platform == Common::kPlatformPCEngine) {
169
if (soundID >= 13 && soundID <= 32) {
170
static const char tracks[20] = {3, 4, 5, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 19, 20, 21};
172
_currentCDSound = soundID;
173
playCDTrack(tracks[soundID - 13], 1, 0, 0);
175
if (_vm->_musicEngine) {
176
_vm->_musicEngine->startSound(soundID);
171
182
debugC(DEBUG_SOUND, "playSound #%d (room %d)", soundID,
172
183
_vm->getResourceRoomNr(rtSound, soundID));
191
202
// Allocate a sound buffer, copy the data into it, and play
192
sound = (char *)malloc(size);
203
sound = (byte *)malloc(size);
193
204
memcpy(sound, ptr, size);
194
_mixer->playRaw(Audio::Mixer::kSFXSoundType, NULL, sound, size, rate, flags, soundID);
206
stream = Audio::makeRawStream(sound, size, rate, Audio::FLAG_UNSIGNED);
207
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID);
196
209
// WORKAROUND bug # 1311447
197
210
else if (READ_BE_UINT32(ptr) == 0x460e200d) {
213
226
// Allocate a sound buffer, copy the data into it, and play
214
sound = (char *)malloc(size);
227
sound = (byte *)malloc(size);
215
228
memcpy(sound, ptr, size);
216
_mixer->playRaw(Audio::Mixer::kSFXSoundType, NULL, sound, size, rate, flags, soundID);
229
stream = Audio::makeRawStream(sound, size, rate, Audio::FLAG_UNSIGNED);
230
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID);
218
232
// Support for sampled sound effects in Monkey Island 1 and 2
219
233
else if (READ_BE_UINT32(ptr) == MKID_BE('SBL ')) {
282
296
assert(voc_block_hdr.pack == 0);
284
298
// Allocate a sound buffer, copy the data into it, and play
285
sound = (char *)malloc(size);
299
sound = (byte *)malloc(size);
286
300
memcpy(sound, ptr + 6, size);
287
_mixer->playRaw(Audio::Mixer::kSFXSoundType, NULL, sound, size, rate, flags, soundID);
301
stream = Audio::makeRawStream(sound, size, rate, Audio::FLAG_UNSIGNED);
302
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID);
289
304
else if ((_vm->_game.platform == Common::kPlatformFMTowns && _vm->_game.version == 3) || READ_BE_UINT32(ptr) == MKID_BE('SOUN') || READ_BE_UINT32(ptr) == MKID_BE('TOWS')) {
335
350
size -= waveSize;
338
flags |= Audio::Mixer::FLAG_LOOP;
340
_mixer->playRaw(Audio::Mixer::kSFXSoundType, NULL, sound, waveSize, rate, flags, soundID, 255, 0, loopStart, loopEnd);
353
Audio::SeekableAudioStream *s = Audio::makeRawStream(sound, waveSize, rate, Audio::FLAG_UNSIGNED);
354
stream = new Audio::SubLoopingAudioStream(s, 0, Audio::Timestamp(0, loopStart, rate), Audio::Timestamp(0, loopEnd, rate));
356
stream = Audio::makeRawStream(sound, waveSize, rate, Audio::FLAG_UNSIGNED);
358
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID, 255, 0);
409
427
// offset 26: ? if != 0: stop current sound?
410
428
// offset 27: ? loopcount? 0xff == -1 for infinite?
412
flags = Audio::Mixer::FLAG_AUTOFREE;
413
430
size = READ_BE_UINT16(ptr + 12);
416
433
rate = 3579545 / READ_BE_UINT16(ptr + 20);
417
sound = (char *)malloc(size);
434
sound = (byte *)malloc(size);
418
435
int vol = ptr[24] * 4;
419
436
int loopStart = 0, loopEnd = 0;
420
437
int loopcount = ptr[27];
439
memcpy(sound, ptr + READ_BE_UINT16(ptr + 8), size);
440
Audio::SeekableAudioStream *plainStream = Audio::makeRawStream(sound, size, rate, 0);
421
442
if (loopcount > 1) {
422
// TODO: We can only loop once, or infinitely many times, but
423
// have no support for a finite number of repetitions.
424
// So far, I have seen only 1 and 255 (for infinite repetitions),
425
// so maybe this is not really a problem.
426
443
loopStart = READ_BE_UINT16(ptr + 10) - READ_BE_UINT16(ptr + 8);
427
444
loopEnd = READ_BE_UINT16(ptr + 14);
428
flags |= Audio::Mixer::FLAG_LOOP;
446
// TODO: Currently we will only ever play till "loopEnd", even when we only have
447
// a finite repetition count.
448
stream = new Audio::SubLoopingAudioStream(plainStream, loopcount == 255 ? 0 : loopcount, Audio::Timestamp(0, loopStart, rate), Audio::Timestamp(0, loopEnd, rate));
450
stream = plainStream;
431
memcpy(sound, ptr + READ_BE_UINT16(ptr + 8), size);
432
_mixer->playRaw(Audio::Mixer::kSFXSoundType, NULL, sound, size, rate,
433
flags, soundID, vol, 0, loopStart, loopEnd);
453
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID, vol, 0);
437
457
if (_vm->_game.id == GID_MONKEY_VGA || _vm->_game.id == GID_MONKEY_EGA
438
458
|| (_vm->_game.id == GID_MONKEY && _vm->_game.platform == Common::kPlatformMacintosh)) {
439
// Sound is currently not supported at all in the amiga versions of these games
440
if (_vm->_game.platform == Common::kPlatformAmiga) {
444
else if (ptr[6] == 0x7F && ptr[7] == 0x00 && ptr[8] == 0x80) {
445
static const char tracks[16] = {13,14,10,3,4,9,16,5,1,8,2,15,6,7,11,12};
449
track = tracks[ptr[9] - 0x23];
452
playCDTrack(track,((track < 5) || (track > 16)) ? 1 : -1,0,0);
454
_currentCDSound = soundID;
459
459
// Works around the fact that in some places in MonkeyEGA/VGA,
460
460
// the music is never explicitly stopped.
461
461
// Rather it seems that starting a new music is supposed to
639
639
switch (_soundMode) {
642
642
assert(size > 0);
643
643
tmp = _sfxFile->readStream(size);
645
input = Audio::makeMP3Stream(tmp, true);
645
input = Audio::makeMP3Stream(tmp, DisposeAfterUse::YES);
648
648
case kVorbisMode:
650
650
assert(size > 0);
651
651
tmp = _sfxFile->readStream(size);
653
input = Audio::makeVorbisStream(tmp, true);
653
input = Audio::makeVorbisStream(tmp, DisposeAfterUse::YES);
658
658
assert(size > 0);
659
659
tmp = _sfxFile->readStream(size);
661
input = Audio::makeFlacStream(tmp, true);
661
input = Audio::makeFLACStream(tmp, DisposeAfterUse::YES);
665
input = Audio::makeVOCStream(*_sfxFile, Audio::Mixer::FLAG_UNSIGNED);
665
input = Audio::makeVOCStream(*_sfxFile, Audio::FLAG_UNSIGNED);
1411
1411
memcpy(ptr, "MDhd", 4); ptr += 4;
1412
1412
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 8;
1414
memset(ptr, 0, 8), ptr += 8;
1414
memset(ptr, 0, 8); ptr += 8;
1415
1415
memcpy(ptr, "MThd", 4); ptr += 4;
1416
1416
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 6;