mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-14 07:48:58 +00:00
EMI: Add basic support for sound effects
This commit is contained in:
parent
5a9a81764f
commit
bca3cac978
@ -26,11 +26,18 @@
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_getwd
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
|
||||
|
||||
#include "audio/mixer.h"
|
||||
#include "audio/audiostream.h"
|
||||
#include "common/system.h"
|
||||
|
||||
#include "engines/grim/emi/sound/aifftrack.h"
|
||||
#include "engines/grim/emi/lua_v2.h"
|
||||
#include "engines/grim/lua/lua.h"
|
||||
|
||||
#include "engines/grim/sound.h"
|
||||
#include "engines/grim/grim.h"
|
||||
#include "engines/grim/resource.h"
|
||||
#include "audio/decoders/aiff.h"
|
||||
|
||||
namespace Grim {
|
||||
|
||||
@ -172,6 +179,18 @@ void Lua_V2::ImFlushStack() {
|
||||
warning("Lua_V2::ImFlushStack: implement opcode");
|
||||
}
|
||||
|
||||
class PoolSound : public PoolObject<PoolSound, MKTAG('A', 'I', 'F', 'F')>{
|
||||
public:
|
||||
PoolSound(const Common::String &filename);
|
||||
AIFFTrack *track;
|
||||
};
|
||||
|
||||
PoolSound::PoolSound(const Common::String &filename) {
|
||||
track = new AIFFTrack(Audio::Mixer::kSFXSoundType);
|
||||
Common::SeekableReadStream *stream = g_resourceloader->openNewStreamFile(filename);
|
||||
track->openSound(filename, stream);
|
||||
}
|
||||
|
||||
void Lua_V2::LoadSound() {
|
||||
lua_Object strObj = lua_getparam(1);
|
||||
|
||||
@ -179,12 +198,23 @@ void Lua_V2::LoadSound() {
|
||||
return;
|
||||
|
||||
const char *str = lua_getstring(strObj);
|
||||
// FIXME: implement code
|
||||
warning("Lua_V2::LoadSound: implement opcode, wants to load %s", str);
|
||||
|
||||
Common::String filename = str;
|
||||
filename += ".aif";
|
||||
|
||||
PoolSound *sound = new PoolSound(filename);
|
||||
lua_pushusertag(sound->getId(), MKTAG('A', 'I', 'F', 'F'));
|
||||
}
|
||||
|
||||
void Lua_V2::FreeSound() {
|
||||
warning("Lua_V2::FreeSound: implement opcode");
|
||||
lua_Object idObj = lua_getparam(1);
|
||||
if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F'))
|
||||
return;
|
||||
PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj));
|
||||
if (sound) {
|
||||
sound->track->stop();
|
||||
delete sound;
|
||||
}
|
||||
}
|
||||
|
||||
void Lua_V2::PlayLoadedSound() {
|
||||
@ -193,7 +223,15 @@ void Lua_V2::PlayLoadedSound() {
|
||||
lua_Object volumeObj = lua_getparam(3);
|
||||
lua_Object bool2Obj = lua_getparam(4);
|
||||
|
||||
warning("Lua_V2::PlayLoadedSound: implement opcode");
|
||||
|
||||
if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F'))
|
||||
return;
|
||||
|
||||
bool looping = !lua_isnil(bool1Obj);
|
||||
|
||||
PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj));
|
||||
sound->track->setLooping(looping);
|
||||
sound->track->play();
|
||||
}
|
||||
|
||||
void Lua_V2::ImSetMusicVol() {
|
||||
|
59
engines/grim/emi/sound/aifftrack.cpp
Normal file
59
engines/grim/emi/sound/aifftrack.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM 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 library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/mutex.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "audio/mixer.h"
|
||||
#include "audio/audiostream.h"
|
||||
#include "audio/decoders/aiff.h"
|
||||
#include "engines/grim/resource.h"
|
||||
#include "engines/grim/emi/sound/aifftrack.h"
|
||||
|
||||
namespace Grim {
|
||||
|
||||
AIFFTrack::AIFFTrack(Audio::Mixer::SoundType soundType) {
|
||||
_soundType = soundType;
|
||||
}
|
||||
|
||||
AIFFTrack::~AIFFTrack() {
|
||||
stop();
|
||||
delete _handle;
|
||||
}
|
||||
|
||||
bool AIFFTrack::openSound(Common::String soundName, Common::SeekableReadStream *file) {
|
||||
if (!file) {
|
||||
warning("Stream for %s not open", soundName.c_str());
|
||||
//return false;
|
||||
}
|
||||
_soundName = soundName;
|
||||
_stream = Audio::makeAIFFStream(file, DisposeAfterUse::YES);
|
||||
_handle = new Audio::SoundHandle();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AIFFTrack::setLooping(bool looping) {
|
||||
if (looping) {
|
||||
_stream = Audio::makeLoopingAudioStream(dynamic_cast<Audio::SeekableAudioStream *>(_stream), 0);
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace Grim
|
47
engines/grim/emi/sound/aifftrack.h
Normal file
47
engines/grim/emi/sound/aifftrack.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM 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 library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GRIM_AIFFTRACK_H
|
||||
#define GRIM_AIFFTRACK_H
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/stream.h"
|
||||
#include "engines/grim/emi/sound/track.h"
|
||||
|
||||
namespace Audio {
|
||||
class AudioStream;
|
||||
class SoundHandle;
|
||||
}
|
||||
|
||||
namespace Grim {
|
||||
|
||||
class AIFFTrack : public SoundTrack {
|
||||
public:
|
||||
AIFFTrack(Audio::Mixer::SoundType soundType);
|
||||
~AIFFTrack();
|
||||
bool openSound(Common::String soundName, Common::SeekableReadStream *file);
|
||||
bool isPlaying() { return true; }
|
||||
void setLooping(bool looping);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -18,6 +18,7 @@ MODULE_OBJS := \
|
||||
emi/costume/emimesh_component.o \
|
||||
emi/costume/emiskel_component.o \
|
||||
emi/costume/emisprite_component.o \
|
||||
emi/sound/aifftrack.o \
|
||||
emi/sound/mp3track.o \
|
||||
emi/sound/scxtrack.o \
|
||||
emi/sound/vimatrack.o \
|
||||
|
Loading…
x
Reference in New Issue
Block a user