2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
#include "agi/agi.h"
|
|
|
|
|
|
|
|
#include "agi/sound_2gs.h"
|
|
|
|
#include "agi/sound_coco3.h"
|
|
|
|
#include "agi/sound_midi.h"
|
|
|
|
#include "agi/sound_sarien.h"
|
|
|
|
#include "agi/sound_pcjr.h"
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
namespace Agi {
|
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
//
|
|
|
|
// TODO: add support for variable sampling rate in the output device
|
|
|
|
//
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:34:45 +00:00
|
|
|
AgiSound *AgiSound::createFromRawResource(uint8 *data, uint32 len, int resnum, SoundMgr &manager, int soundemu) {
|
2009-01-03 14:05:57 +00:00
|
|
|
if (data == NULL || len < 2) // Check for too small resource or no resource at all
|
|
|
|
return NULL;
|
2007-08-15 22:00:31 +00:00
|
|
|
uint16 type = READ_LE_UINT16(data);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
switch (type) { // Create a sound object based on the type
|
2009-05-24 15:17:42 +00:00
|
|
|
case AGI_SOUND_SAMPLE:
|
2009-01-03 14:05:57 +00:00
|
|
|
return new IIgsSample(data, len, resnum, manager);
|
2009-05-24 15:17:42 +00:00
|
|
|
case AGI_SOUND_MIDI:
|
2010-06-15 10:34:45 +00:00
|
|
|
return new IIgsMidi(data, len, resnum, manager);
|
2009-05-24 15:17:42 +00:00
|
|
|
case AGI_SOUND_4CHN:
|
2010-06-15 10:34:45 +00:00
|
|
|
if (soundemu == SOUND_EMU_MIDI) {
|
|
|
|
return new MIDISound(data, len, resnum, manager);
|
|
|
|
} else {
|
|
|
|
return new PCjrSound(data, len, resnum, manager);
|
|
|
|
}
|
2007-08-15 22:00:31 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
warning("Sound resource (%d) has unknown type (0x%04x). Not using the sound", resnum, type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCjrSound::PCjrSound(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : AgiSound(manager) {
|
|
|
|
_data = data; // Save the resource pointer
|
|
|
|
_len = len; // Save the resource's length
|
|
|
|
_type = READ_LE_UINT16(data); // Read sound resource's type
|
|
|
|
_isValid = (_type == AGI_SOUND_4CHN) && (_data != NULL) && (_len >= 2);
|
|
|
|
|
|
|
|
if (!_isValid) // Check for errors
|
|
|
|
warning("Error creating PCjr 4-channel sound from resource %d (Type %d, length %d)", resnum, _type, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8 *PCjrSound::getVoicePointer(uint voiceNum) {
|
2007-08-16 18:42:28 +00:00
|
|
|
assert(voiceNum < 4);
|
2007-08-15 22:00:31 +00:00
|
|
|
uint16 voiceStartOffset = READ_LE_UINT16(_data + voiceNum * 2);
|
2009-06-06 17:39:13 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
return _data + voiceStartOffset;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
#if 0
|
2007-08-19 20:48:11 +00:00
|
|
|
static const uint16 period[] = {
|
2006-05-23 23:43:52 +00:00
|
|
|
1024, 1085, 1149, 1218, 1290, 1367,
|
|
|
|
1448, 1534, 1625, 1722, 1825, 1933
|
|
|
|
};
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
static int noteToPeriod(int note) {
|
2006-05-23 23:43:52 +00:00
|
|
|
return 10 * (period[note % 12] >> (note / 12 - 3));
|
|
|
|
}
|
2007-09-03 12:23:50 +00:00
|
|
|
#endif
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SoundMgr::unloadSound(int resnum) {
|
|
|
|
if (_vm->_game.dirSound[resnum].flags & RES_LOADED) {
|
2007-08-15 22:00:31 +00:00
|
|
|
if (_vm->_game.sounds[resnum]->isPlaying()) {
|
|
|
|
_vm->_game.sounds[resnum]->stop();
|
2007-09-19 08:40:12 +00:00
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
// Release the sound resource's data
|
|
|
|
delete _vm->_game.sounds[resnum];
|
|
|
|
_vm->_game.sounds[resnum] = NULL;
|
2007-01-16 12:40:51 +00:00
|
|
|
_vm->_game.dirSound[resnum].flags &= ~RES_LOADED;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SoundMgr::startSound(int resnum, int flag) {
|
2010-06-15 10:35:10 +00:00
|
|
|
AgiSoundEmuType type;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
if (_vm->_game.sounds[resnum] != NULL && _vm->_game.sounds[resnum]->isPlaying())
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
stopSound();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
if (_vm->_game.sounds[resnum] == NULL) // Is this needed at all?
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-15 10:35:10 +00:00
|
|
|
type = (AgiSoundEmuType)_vm->_game.sounds[resnum]->type();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
if (type != AGI_SOUND_SAMPLE && type != AGI_SOUND_MIDI && type != AGI_SOUND_4CHN)
|
|
|
|
return;
|
|
|
|
|
2007-08-15 22:00:31 +00:00
|
|
|
_vm->_game.sounds[resnum]->play();
|
2007-08-19 20:48:11 +00:00
|
|
|
_playingSound = resnum;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-17 23:16:21 +00:00
|
|
|
debugC(3, kDebugLevelSound, "startSound(resnum = %d, flag = %d) type = %d", resnum, flag, type);
|
2007-08-18 12:41:24 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
_soundGen->play(resnum);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-08-19 20:48:11 +00:00
|
|
|
_endflag = flag;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// Nat Budin reports that the flag should be reset when sound starts
|
2007-08-19 20:48:11 +00:00
|
|
|
_vm->setflag(_endflag, false);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SoundMgr::stopSound() {
|
2009-06-13 22:48:16 +00:00
|
|
|
debugC(3, kDebugLevelSound, "stopSound() --> %d", _playingSound);
|
|
|
|
|
2007-08-19 20:48:11 +00:00
|
|
|
_endflag = -1;
|
2010-06-15 10:36:10 +00:00
|
|
|
|
2007-08-19 20:48:11 +00:00
|
|
|
if (_playingSound != -1) {
|
2009-06-13 22:48:16 +00:00
|
|
|
if (_vm->_game.sounds[_playingSound]) // sanity checking
|
|
|
|
_vm->_game.sounds[_playingSound]->stop();
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
_soundGen->stop();
|
2010-06-15 10:36:10 +00:00
|
|
|
|
2007-08-19 20:48:11 +00:00
|
|
|
_playingSound = -1;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
2010-06-15 10:35:42 +00:00
|
|
|
|
|
|
|
if (_endflag != -1)
|
|
|
|
_vm->setflag(_endflag, true);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
int SoundMgr::initSound() {
|
2010-06-15 10:36:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:36:54 +00:00
|
|
|
void SoundMgr::deinitSound() {
|
|
|
|
stopSound();
|
|
|
|
|
|
|
|
delete _soundGen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundMgr::soundIsFinished() {
|
|
|
|
if (_endflag != -1)
|
|
|
|
_vm->setflag(_endflag, true);
|
|
|
|
|
|
|
|
if (_playingSound != -1)
|
|
|
|
_vm->_game.sounds[_playingSound]->stop();
|
|
|
|
_playingSound = -1;
|
|
|
|
_endflag = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundMgr::SoundMgr(AgiEngine *agi, Audio::Mixer *pMixer) {
|
|
|
|
_vm = agi;
|
|
|
|
_endflag = -1;
|
|
|
|
_playingSound = -1;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-02-13 15:27:36 +00:00
|
|
|
switch (_vm->_soundemu) {
|
2006-05-23 23:43:52 +00:00
|
|
|
case SOUND_EMU_AMIGA:
|
|
|
|
case SOUND_EMU_MAC:
|
2010-06-15 10:36:54 +00:00
|
|
|
_soundGen = new SoundGenSarien(_vm, pMixer);
|
|
|
|
break;
|
2010-09-20 21:17:49 +00:00
|
|
|
case SOUND_EMU_NONE:
|
2010-06-15 10:45:14 +00:00
|
|
|
case SOUND_EMU_PC:
|
2010-06-15 10:36:54 +00:00
|
|
|
case SOUND_EMU_PCJR:
|
|
|
|
_soundGen = new SoundGenPCJr(_vm, pMixer);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2007-08-17 13:10:57 +00:00
|
|
|
case SOUND_EMU_APPLE2GS:
|
2010-06-15 10:36:54 +00:00
|
|
|
_soundGen = new SoundGen2GS(_vm, pMixer);
|
2007-08-17 13:10:57 +00:00
|
|
|
break;
|
2009-06-17 23:16:21 +00:00
|
|
|
case SOUND_EMU_COCO3:
|
2010-06-15 10:36:54 +00:00
|
|
|
_soundGen = new SoundGenCoCo3(_vm, pMixer);
|
2009-06-17 23:16:21 +00:00
|
|
|
break;
|
2010-06-15 10:34:45 +00:00
|
|
|
case SOUND_EMU_MIDI:
|
2010-06-15 10:36:54 +00:00
|
|
|
_soundGen = new SoundGenMIDI(_vm, pMixer);
|
2010-06-15 10:34:45 +00:00
|
|
|
break;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void SoundMgr::setVolume(uint8 volume) {
|
2006-05-23 23:43:52 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
SoundMgr::~SoundMgr() {
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-05-24 14:00:08 +00:00
|
|
|
} // End of namespace Agi
|