~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to engines/agos/sound.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
20
20
 *
21
 
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/engines/agos/sound.cpp $
22
 
 * $Id: sound.cpp 52909 2010-09-26 12:29:40Z eriktorbjorn $
 
21
 * $URL$
 
22
 * $Id$
23
23
 *
24
24
 */
25
25
 
26
26
#include "common/file.h"
 
27
#include "common/memstream.h"
 
28
#include "common/textconsole.h"
27
29
#include "common/util.h"
28
30
 
29
31
#include "agos/agos.h"
30
32
#include "agos/sound.h"
31
33
 
32
 
#include "sound/audiostream.h"
33
 
#include "sound/decoders/flac.h"
34
 
#include "sound/mixer.h"
35
 
#include "sound/decoders/mp3.h"
36
 
#include "sound/decoders/raw.h"
37
 
#include "sound/decoders/voc.h"
38
 
#include "sound/decoders/vorbis.h"
39
 
#include "sound/decoders/wave.h"
40
 
 
41
 
using Common::File;
 
34
#include "audio/audiostream.h"
 
35
#include "audio/decoders/flac.h"
 
36
#include "audio/mixer.h"
 
37
#include "audio/decoders/mp3.h"
 
38
#include "audio/decoders/raw.h"
 
39
#include "audio/decoders/voc.h"
 
40
#include "audio/decoders/vorbis.h"
 
41
#include "audio/decoders/wave.h"
42
42
 
43
43
namespace AGOS {
44
44
 
46
46
 
47
47
class BaseSound : Common::NonCopyable {
48
48
protected:
49
 
        File *_file;
 
49
        Common::File *_file;
50
50
        uint32 *_offsets;
51
51
        Audio::Mixer *_mixer;
52
52
        bool _freeOffsets;
53
53
        DisposeAfterUse::Flag _disposeFile;
54
54
 
55
55
public:
56
 
        BaseSound(Audio::Mixer *mixer, File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
57
 
        BaseSound(Audio::Mixer *mixer, File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
 
56
        BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
 
57
        BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
58
58
        virtual ~BaseSound();
59
59
 
60
60
        void playSound(uint sound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0) {
64
64
        virtual Audio::AudioStream *makeAudioStream(uint sound) = 0;
65
65
};
66
66
 
67
 
BaseSound::BaseSound(Audio::Mixer *mixer, File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse)
 
67
BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse)
68
68
        : _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) {
69
69
 
70
70
        uint res = 0;
98
98
        _offsets[res] = _file->size();
99
99
}
100
100
 
101
 
BaseSound::BaseSound(Audio::Mixer *mixer, File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse)
 
101
BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse)
102
102
        : _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) {
103
103
 
104
104
        _offsets = offsets;
225
225
 
226
226
class WavSound : public BaseSound {
227
227
public:
228
 
        WavSound(Audio::Mixer *mixer, File *file, uint32 base = 0, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES)
 
228
        WavSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES)
229
229
                : BaseSound(mixer, file, base, false, disposeFileAfterUse) {}
230
 
        WavSound(Audio::Mixer *mixer, File *file, uint32 *offsets) : BaseSound(mixer, file, offsets) {}
 
230
        WavSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets) : BaseSound(mixer, file, offsets) {}
231
231
        Audio::AudioStream *makeAudioStream(uint sound);
232
232
        void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0);
233
233
};
251
251
class VocSound : public BaseSound {
252
252
        const byte _flags;
253
253
public:
254
 
        VocSound(Audio::Mixer *mixer, File *file, bool isUnsigned, uint32 base = 0, bool bigEndian = false, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES)
 
254
        VocSound(Audio::Mixer *mixer, Common::File *file, bool isUnsigned, uint32 base = 0, bool bigEndian = false, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES)
255
255
                : BaseSound(mixer, file, base, bigEndian, disposeFileAfterUse), _flags(isUnsigned ? Audio::FLAG_UNSIGNED : 0) {}
256
256
        Audio::AudioStream *makeAudioStream(uint sound);
257
257
        void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0);
275
275
class RawSound : public BaseSound {
276
276
        const byte _flags;
277
277
public:
278
 
        RawSound(Audio::Mixer *mixer, File *file, bool isUnsigned)
 
278
        RawSound(Audio::Mixer *mixer, Common::File *file, bool isUnsigned)
279
279
                : BaseSound(mixer, file, 0, SOUND_BIG_ENDIAN), _flags(isUnsigned ? Audio::FLAG_UNSIGNED : 0) {}
280
280
        Audio::AudioStream *makeAudioStream(uint sound);
281
281
        void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0);
305
305
 
306
306
class CompressedSound : public BaseSound {
307
307
public:
308
 
        CompressedSound(Audio::Mixer *mixer, File *file, uint32 base) : BaseSound(mixer, file, base, false) {}
 
308
        CompressedSound(Audio::Mixer *mixer, Common::File *file, uint32 base) : BaseSound(mixer, file, base, false) {}
309
309
 
310
 
        Common::MemoryReadStream *loadStream(uint sound) const {
 
310
        Common::SeekableReadStream *loadStream(uint sound) const {
311
311
                if (_offsets == NULL)
312
312
                        return NULL;
313
313
 
334
334
#ifdef USE_MAD
335
335
class MP3Sound : public CompressedSound {
336
336
public:
337
 
        MP3Sound(Audio::Mixer *mixer, File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
 
337
        MP3Sound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
338
338
        Audio::AudioStream *makeAudioStream(uint sound) {
339
 
                Common::MemoryReadStream *tmp = loadStream(sound);
 
339
                Common::SeekableReadStream *tmp = loadStream(sound);
340
340
                if (!tmp)
341
341
                        return NULL;
342
342
                return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES);
350
350
#ifdef USE_VORBIS
351
351
class VorbisSound : public CompressedSound {
352
352
public:
353
 
        VorbisSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
 
353
        VorbisSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
354
354
        Audio::AudioStream *makeAudioStream(uint sound) {
355
 
                Common::MemoryReadStream *tmp = loadStream(sound);
 
355
                Common::SeekableReadStream *tmp = loadStream(sound);
356
356
                if (!tmp)
357
357
                        return NULL;
358
358
                return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES);
366
366
#ifdef USE_FLAC
367
367
class FLACSound : public CompressedSound {
368
368
public:
369
 
        FLACSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
 
369
        FLACSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
370
370
        Audio::AudioStream *makeAudioStream(uint sound) {
371
 
                Common::MemoryReadStream *tmp = loadStream(sound);
 
371
                Common::SeekableReadStream *tmp = loadStream(sound);
372
372
                if (!tmp)
373
373
                        return NULL;
374
374
                return Audio::makeFLACStream(tmp, DisposeAfterUse::YES);
379
379
///////////////////////////////////////////////////////////////////////////////
380
380
#pragma mark -
381
381
 
382
 
static CompressedSound *makeCompressedSound(Audio::Mixer *mixer, File *file, const Common::String &basename) {
 
382
static CompressedSound *makeCompressedSound(Audio::Mixer *mixer, Common::File *file, const Common::String &basename) {
383
383
#ifdef USE_FLAC
384
384
        file->open(basename + ".fla");
385
385
        if (file->isOpen()) {
451
451
 
452
452
 
453
453
        char filename[16];
454
 
        File *file = new File();
 
454
        Common::File *file = new Common::File();
455
455
 
456
456
        if (!_hasVoiceFile) {
457
457
                _voice = makeCompressedSound(_mixer, file, gss->speech_filename);
506
506
 
507
507
void Sound::loadSfxFile(const GameSpecificSettings *gss) {
508
508
        char filename[16];
509
 
        File *file = new File();
 
509
        Common::File *file = new Common::File();
510
510
 
511
511
        if (!_hasEffectsFile) {
512
512
                _effects = makeCompressedSound(_mixer, file, gss->effects_filename);
540
540
 
541
541
        _mixer->stopHandle(_effectsHandle);
542
542
 
543
 
        File *file = new File();
 
543
        Common::File *file = new Common::File();
544
544
        file->open(filename);
545
545
 
546
546
        if (file->isOpen() == false) {
557
557
}
558
558
 
559
559
// This method is only used by Simon2
560
 
void Sound::loadSfxTable(File *gameFile, uint32 base) {
 
560
void Sound::loadSfxTable(Common::File *gameFile, uint32 base) {
561
561
        stopAll();
562
562
 
563
563
        delete _effects;
572
572
void Sound::readVoiceFile(const Common::String &filename) {
573
573
        _mixer->stopHandle(_voiceHandle);
574
574
 
575
 
        File *file = new File();
 
575
        Common::File *file = new Common::File();
576
576
        file->open(filename);
577
577
 
578
578
        if (file->isOpen() == false)
592
592
                        char filename[16];
593
593
                        _lastVoiceFile = _filenums[sound];
594
594
                        sprintf(filename, "voices%d.dat", _filenums[sound]);
595
 
                        File *file = new File();
 
595
                        Common::File *file = new Common::File();
596
596
                        file->open(filename);
597
597
                        if (file->isOpen() == false)
598
598
                                error("playVoice: Can't load voice file %s", filename);
777
777
 
778
778
void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint sound, int pan, int vol, bool loop) {
779
779
        int size = READ_LE_UINT32(soundData + 4) + 8;
780
 
        Common::MemoryReadStream *stream = new Common::MemoryReadStream(soundData, size);
 
780
        Common::SeekableReadStream *stream = new Common::MemoryReadStream(soundData, size);
781
781
        Audio::RewindableAudioStream *sndStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
782
782
 
783
783
        convertVolume(vol);
801
801
        _lastVoiceFile = disc;
802
802
 
803
803
        char filename[16];
804
 
        File *file = new File();
 
804
        Common::File *file = new Common::File();
805
805
 
806
806
        if (!_hasVoiceFile) {
807
807
                sprintf(filename, "%s%d", gss->speech_filename, disc);