mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-20 00:45:10 +00:00
Objectize sndres.cpp
svn-id: r13664
This commit is contained in:
parent
b59c8004a5
commit
1ad6498bd5
@ -30,6 +30,7 @@
|
||||
Hardcoded actor table present in r_actordata.c
|
||||
*/
|
||||
|
||||
#include "saga.h"
|
||||
#include "reinherit.h"
|
||||
|
||||
#include "yslib.h"
|
||||
@ -42,7 +43,7 @@
|
||||
#include "console_mod.h"
|
||||
#include "rscfile_mod.h"
|
||||
#include "script_mod.h"
|
||||
#include "sndres_mod.h"
|
||||
#include "sndres.h"
|
||||
#include "sprite_mod.h"
|
||||
#include "font_mod.h"
|
||||
#include "text_mod.h"
|
||||
@ -678,7 +679,7 @@ HandleSpeakIntent(R_ACTOR * actor,
|
||||
if (!a_dialogue->d_playing) {
|
||||
/* Dialogue voice hasn't played yet - play it now */
|
||||
|
||||
SND_PlayVoice(a_dialogue->d_voice_rn);
|
||||
_vm->_snd->playVoice(a_dialogue->d_voice_rn);
|
||||
a_dialogue->d_playing = 1;
|
||||
}
|
||||
|
||||
@ -732,7 +733,7 @@ int ACTOR_GetSpeechTime(const char *d_string, uint d_voice_rn)
|
||||
{
|
||||
int voice_len;
|
||||
|
||||
voice_len = SND_GetVoiceLength(d_voice_rn);
|
||||
voice_len = _vm->_snd->getVoiceLength(d_voice_rn);
|
||||
|
||||
if (voice_len < 0) {
|
||||
voice_len = strlen(d_string) * ACTOR_DIALOGUE_LETTERTIME;
|
||||
|
@ -29,6 +29,7 @@
|
||||
Notes:
|
||||
*/
|
||||
|
||||
#include "saga.h"
|
||||
#include "reinherit.h"
|
||||
|
||||
#include "yslib.h"
|
||||
@ -44,7 +45,8 @@
|
||||
#include "text_mod.h"
|
||||
#include "palanim_mod.h"
|
||||
#include "render_mod.h"
|
||||
#include "sndres_mod.h"
|
||||
#include "game_mod.h"
|
||||
#include "sndres.h"
|
||||
|
||||
/*
|
||||
* Begin module
|
||||
@ -308,7 +310,7 @@ static int HandleOneShot(R_EVENT * event)
|
||||
|
||||
case R_VOICE_EVENT:
|
||||
|
||||
SND_PlayVoice(event->param);
|
||||
_vm->_snd->playVoice(event->param);
|
||||
break;
|
||||
|
||||
case R_MUSIC_EVENT:
|
||||
|
@ -27,15 +27,11 @@
|
||||
|
||||
Notes:
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "saga.h"
|
||||
#include "reinherit.h"
|
||||
|
||||
#include "yslib.h"
|
||||
|
||||
#include "reinherit.h"
|
||||
|
||||
/*
|
||||
* Uses the following modules:
|
||||
\*--------------------------------------------------------------------------*/
|
||||
@ -46,7 +42,7 @@
|
||||
#include "game_mod.h"
|
||||
#include "rscfile_mod.h"
|
||||
#include "scene_mod.h"
|
||||
#include "sndres_mod.h"
|
||||
#include "sndres.h"
|
||||
#include "text_mod.h"
|
||||
#include "palanim_mod.h"
|
||||
|
||||
@ -354,7 +350,7 @@ int ITE_IntroCave1Proc(int param, R_SCENE_INFO * scene_info)
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
voice_len =
|
||||
SND_GetVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
_vm->_snd->getVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
if (voice_len < 0) {
|
||||
voice_len = strlen(IntroDiag[i].i_str) *
|
||||
VOICE_LETTERLEN;
|
||||
@ -474,7 +470,7 @@ int ITE_IntroCave2Proc(int param, R_SCENE_INFO * scene_info)
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
voice_len =
|
||||
SND_GetVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
_vm->_snd->getVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
if (voice_len < 0) {
|
||||
voice_len = strlen(IntroDiag[i].i_str) *
|
||||
VOICE_LETTERLEN;
|
||||
@ -592,7 +588,7 @@ int ITE_IntroCave3Proc(int param, R_SCENE_INFO * scene_info)
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
voice_len =
|
||||
SND_GetVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
_vm->_snd->getVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
if (voice_len < 0) {
|
||||
voice_len = strlen(IntroDiag[i].i_str) *
|
||||
VOICE_LETTERLEN;
|
||||
@ -709,7 +705,7 @@ int ITE_IntroCave4Proc(int param, R_SCENE_INFO * scene_info)
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
voice_len =
|
||||
SND_GetVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
_vm->_snd->getVoiceLength(IntroDiag[i].i_voice_rn);
|
||||
if (voice_len < 0) {
|
||||
voice_len = strlen(IntroDiag[i].i_str) *
|
||||
VOICE_LETTERLEN;
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include "isomap_mod.h"
|
||||
#include "script_mod.h"
|
||||
#include "scene_mod.h"
|
||||
#include "sndres_mod.h"
|
||||
#include "sndres.h"
|
||||
#include "sprite_mod.h"
|
||||
#include "text_mod.h"
|
||||
#include "objectmap_mod.h"
|
||||
@ -132,6 +132,8 @@ static void CF_testfunc(int argc, char *argv[]);
|
||||
|
||||
static R_MAIN_DATA MainData;
|
||||
|
||||
SagaEngine *_vm = NULL;
|
||||
|
||||
SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
|
||||
: Engine(syst) {
|
||||
|
||||
@ -144,8 +146,7 @@ SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
|
||||
|
||||
_mixer->setVolume(ConfMan.getInt("sfx_volume") * ConfMan.getInt("master_volume") / 255);
|
||||
|
||||
// Initialize backend
|
||||
//syst->initSize(320, 240);
|
||||
_vm = this;
|
||||
}
|
||||
|
||||
SagaEngine::~SagaEngine() {
|
||||
@ -210,7 +211,7 @@ void SagaEngine::go() {
|
||||
|
||||
/* Initialize engine modules
|
||||
* \*------------------------------------------------------------- */
|
||||
SND_Init();
|
||||
_snd = new Snd();
|
||||
EVENT_Init();
|
||||
FONT_Init();
|
||||
SPRITE_Init();
|
||||
|
10
saga/saga.h
10
saga/saga.h
@ -24,6 +24,7 @@
|
||||
#ifndef SAGA_H
|
||||
#define SAGA_H
|
||||
|
||||
#include "common/stdafx.h"
|
||||
#include "common/scummsys.h"
|
||||
#include "base/engine.h"
|
||||
#include "base/gameDetector.h"
|
||||
@ -33,6 +34,8 @@
|
||||
|
||||
namespace Saga {
|
||||
|
||||
class Snd;
|
||||
|
||||
#define R_PBOUNDS(n,max) (((n)>=(0))&&((n)<(max)))
|
||||
|
||||
enum SAGAGameId {
|
||||
@ -50,10 +53,13 @@ class SagaEngine:public Engine {
|
||||
|
||||
public:
|
||||
SagaEngine(GameDetector * detector, OSystem * syst);
|
||||
virtual ~ SagaEngine();
|
||||
|
||||
virtual ~SagaEngine();
|
||||
Snd *_snd;
|
||||
};
|
||||
|
||||
// FIXME: Global var. We use it until everything will be turned into objects
|
||||
extern SagaEngine *_vm;
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif
|
||||
|
@ -43,41 +43,36 @@
|
||||
/*
|
||||
* Begin module component
|
||||
\*--------------------------------------------------------------------------*/
|
||||
#include "sndres_mod.h"
|
||||
#include "sndres.h"
|
||||
|
||||
namespace Saga {
|
||||
|
||||
R_SNDRES_MODULE SndModule;
|
||||
|
||||
int SND_Init(void) {
|
||||
Snd::Snd(void) {
|
||||
int result;
|
||||
|
||||
/* Load sound module resource file contexts */
|
||||
result = GAME_GetFileContext(&SndModule.sfx_ctxt, R_GAME_SOUNDFILE, 0);
|
||||
result = GAME_GetFileContext(&_sfx_ctxt, R_GAME_SOUNDFILE, 0);
|
||||
if (result != R_SUCCESS) {
|
||||
return R_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
result = GAME_GetFileContext(&SndModule.voice_ctxt,
|
||||
result = GAME_GetFileContext(&_voice_ctxt,
|
||||
R_GAME_VOICEFILE, 0);
|
||||
if (result != R_SUCCESS) {
|
||||
return R_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Grab sound resource information for the current game */
|
||||
GAME_GetSoundInfo(&SndModule.snd_info);
|
||||
GAME_GetSoundInfo(&_snd_info);
|
||||
|
||||
SndModule.init = 1;
|
||||
|
||||
return R_SUCCESS;
|
||||
_init = 1;
|
||||
}
|
||||
|
||||
int SND_PlayVoice(ulong voice_rn) {
|
||||
int Snd::playVoice(ulong voice_rn) {
|
||||
R_SOUNDBUFFER snd_buffer;
|
||||
int result;
|
||||
|
||||
result = SND_Load(SndModule.voice_ctxt, voice_rn, &snd_buffer);
|
||||
result = load(_voice_ctxt, voice_rn, &snd_buffer);
|
||||
if (result != R_SUCCESS) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
@ -87,7 +82,7 @@ int SND_PlayVoice(ulong voice_rn) {
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int SND_Load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i) {
|
||||
int Snd::load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i) {
|
||||
uchar *snd_res;
|
||||
size_t snd_res_len;
|
||||
|
||||
@ -100,11 +95,11 @@ int SND_Load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
switch (SndModule.snd_info.res_type) {
|
||||
switch (_snd_info.res_type) {
|
||||
case R_GAME_SOUND_PCM:
|
||||
snd_buf_i->s_freq = SndModule.snd_info.freq;
|
||||
snd_buf_i->s_samplebits = SndModule.snd_info.sample_size;
|
||||
snd_buf_i->s_stereo = SndModule.snd_info.stereo;
|
||||
snd_buf_i->s_freq = _snd_info.freq;
|
||||
snd_buf_i->s_samplebits = _snd_info.sample_size;
|
||||
snd_buf_i->s_stereo = _snd_info.stereo;
|
||||
|
||||
snd_buf_i->res_data = snd_res;
|
||||
snd_buf_i->res_len = snd_res_len;
|
||||
@ -117,7 +112,7 @@ int SND_Load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i
|
||||
break;
|
||||
|
||||
case R_GAME_SOUND_VOC:
|
||||
if (LoadVocSound(snd_res, snd_res_len, snd_buf_i) != R_SUCCESS) {
|
||||
if (loadVocSound(snd_res, snd_res_len, snd_buf_i) != R_SUCCESS) {
|
||||
|
||||
RSC_FreeResource(snd_res);
|
||||
|
||||
@ -137,7 +132,7 @@ int SND_Load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int LoadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_buf_i) {
|
||||
int Snd::loadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_buf_i) {
|
||||
R_VOC_HEADER_BLOCK voc_hb;
|
||||
R_VOC_GENBLOCK voc_gb;
|
||||
R_VOC_BLOCK1 voc_b1;
|
||||
@ -197,7 +192,7 @@ int LoadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_bu
|
||||
read_len -= 2;
|
||||
|
||||
if (voc_b1.pack_method != 0) {
|
||||
/* Packed VOC files not supported */
|
||||
debug(0, "Packed VOC files not supported");
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
@ -230,7 +225,7 @@ int LoadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_bu
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int SND_GetVoiceLength(ulong voice_rn) {
|
||||
int Snd::getVoiceLength(ulong voice_rn) {
|
||||
ulong length;
|
||||
|
||||
double ms_f;
|
||||
@ -238,20 +233,20 @@ int SND_GetVoiceLength(ulong voice_rn) {
|
||||
|
||||
int result;
|
||||
|
||||
assert(SndModule.init);
|
||||
assert(_init);
|
||||
|
||||
result = RSC_GetResourceSize(SndModule.voice_ctxt, voice_rn, &length);
|
||||
result = RSC_GetResourceSize(_voice_ctxt, voice_rn, &length);
|
||||
if (result != R_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SndModule.snd_info.res_type == R_GAME_SOUND_PCM) {
|
||||
if (_snd_info.res_type == R_GAME_SOUND_PCM) {
|
||||
ms_f = (double)length /
|
||||
(SndModule.snd_info.sample_size / CHAR_BIT) /
|
||||
(SndModule.snd_info.freq) * 1000.0;
|
||||
(_snd_info.sample_size / CHAR_BIT) /
|
||||
(_snd_info.freq) * 1000.0;
|
||||
|
||||
ms_i = (int)ms_f;
|
||||
} else if (SndModule.snd_info.res_type == R_GAME_SOUND_VOC) {
|
||||
} else if (_snd_info.res_type == R_GAME_SOUND_VOC) {
|
||||
/* Rough hack, fix this to be accurate */
|
||||
ms_f = (double)length / 14705 * 1000.0;
|
||||
ms_i = (int)ms_f;
|
||||
@ -262,7 +257,7 @@ int SND_GetVoiceLength(ulong voice_rn) {
|
||||
return ms_i;
|
||||
}
|
||||
|
||||
int SND_ITEVOC_Resample(long src_freq, long dst_freq, uchar *src_buf,
|
||||
int Snd::ITEVOC_Resample(long src_freq, long dst_freq, uchar *src_buf,
|
||||
size_t src_buf_len, uchar **dst_buf, size_t *dst_buf_len) {
|
||||
uchar *resamp_buf;
|
||||
size_t resamp_len;
|
||||
|
@ -62,17 +62,28 @@ struct R_VOC_BLOCK1 {
|
||||
int pack_method; /* BYTE */
|
||||
};
|
||||
|
||||
struct R_SNDRES_MODULE {
|
||||
int init;
|
||||
class Snd {
|
||||
public:
|
||||
|
||||
R_RSCFILE_CONTEXT *sfx_ctxt;
|
||||
R_RSCFILE_CONTEXT *voice_ctxt;
|
||||
Snd(void);
|
||||
|
||||
R_GAME_SOUNDINFO snd_info;
|
||||
};
|
||||
int loadSound(ulong sound_rn);
|
||||
int playVoice(ulong voice_rn);
|
||||
int getVoiceLength(ulong voice_rn);
|
||||
int ITEVOC_Resample(long src_freq, long dst_freq, uchar *src_buf,
|
||||
size_t src_buf_len, uchar **dst_buf, size_t *dst_buf_len);
|
||||
|
||||
int SND_Load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i);
|
||||
int LoadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_buf_i);
|
||||
private:
|
||||
int load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_buf_i);
|
||||
int loadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_buf_i);
|
||||
|
||||
int _init;
|
||||
|
||||
R_RSCFILE_CONTEXT *_sfx_ctxt;
|
||||
R_RSCFILE_CONTEXT *_voice_ctxt;
|
||||
|
||||
R_GAME_SOUNDINFO _snd_info;
|
||||
};
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
/* ScummVM - Scumm Interpreter
|
||||
* Copyright (C) 2004 The ScummVM project
|
||||
*
|
||||
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
/*
|
||||
Description:
|
||||
|
||||
Sound resource management module - public header
|
||||
|
||||
Notes:
|
||||
*/
|
||||
|
||||
#ifndef SAGA_SNDRES_MOD_H_
|
||||
#define SAGA_SNDRES_MOD_H_
|
||||
|
||||
namespace Saga {
|
||||
|
||||
int SND_Init(void);
|
||||
|
||||
int SND_LoadSound(ulong sound_rn);
|
||||
|
||||
int SND_PlayVoice(ulong voice_rn);
|
||||
|
||||
int SND_GetVoiceLength(ulong voice_rn);
|
||||
|
||||
int
|
||||
SND_ITEVOC_Resample(long src_freq,
|
||||
long dst_freq,
|
||||
uchar * src_buf,
|
||||
size_t src_buf_len, uchar ** dst_buf, size_t * dst_buf_len);
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif /* SAGA_SNDRES_MOD_H_ */
|
Loading…
x
Reference in New Issue
Block a user