Voices are played

svn-id: r13668
This commit is contained in:
Eugene Sandulenko 2004-04-29 01:24:18 +00:00
parent 4c889000f2
commit d7835da8c7
6 changed files with 53 additions and 20 deletions

View File

@ -103,19 +103,6 @@ struct R_SURFACE {
void *impl_src;
};
struct R_SOUNDBUFFER {
const uchar *res_data;
size_t res_len;
long s_freq;
int s_samplebits;
int s_stereo;
int s_signed;
const uchar *s_buf;
size_t s_buf_len;
};
#define R_RGB_RED 0x00FF0000UL
#define R_RGB_GREEN 0x0000FF00UL
#define R_RGB_BLUE 0x000000FFUL

View File

@ -253,7 +253,7 @@ void SagaEngine::go() {
}
/* Initialize system specific sound */
_sound = new Sound(MainData.sound_enabled);
_sound = new Sound(this, _mixer, MainData.sound_enabled);
if (!MainData.sound_enabled) {
R_printf(R_STDOUT, "Sound disabled.\n");
}

View File

@ -75,6 +75,8 @@ int SndRes::playVoice(ulong voice_rn) {
R_SOUNDBUFFER snd_buffer;
int result;
debug(0, "SndRes::playVoice(%ld)", voice_rn);
result = load(_voice_ctxt, voice_rn, &snd_buffer);
if (result != R_SUCCESS) {
return R_FAILURE;
@ -135,7 +137,7 @@ int SndRes::load(R_RSCFILE_CONTEXT *snd_ctxt, ulong snd_rn, R_SOUNDBUFFER *snd_b
return R_SUCCESS;
}
int SndRes::loadVocSound(const uchar *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_buf_i) {
int SndRes::loadVocSound(byte *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;

View File

@ -33,6 +33,7 @@
#include "rscfile_mod.h"
#include "game_mod.h"
#include "sound.h"
namespace Saga {
@ -78,7 +79,7 @@ class SndRes {
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 loadVocSound(byte *snd_res, size_t snd_res_len, R_SOUNDBUFFER *snd_buf_i);
int _init;

View File

@ -31,13 +31,16 @@
#include "sound.h"
#include "game_mod.h"
#include "sound/mixer.h"
namespace Saga {
/*
* Begin module component
\*--------------------------------------------------------------------------*/
Sound::Sound(int enabled) {
Sound::Sound(SagaEngine *vm, SoundMixer *mixer, int enabled) :
_vm(vm), _mixer(mixer) {
int result;
/* Load sound module resource file contexts */
@ -52,7 +55,7 @@ Sound::Sound(int enabled) {
}
/* Grab sound resource information for the current game */
//GAME_GetSoundInfo(&SoundModule.snd_info);
GAME_GetSoundInfo(&_snd_info);
_soundInitialized = 1;
return;
@ -112,12 +115,21 @@ int Sound::stop(int channel) {
}
int Sound::playVoice(R_SOUNDBUFFER *buf) {
(void)buf;
byte flags;
int game_id = GAME_GetGame();
if (!_soundInitialized) {
return R_FAILURE;
}
if((game_id == R_GAME_ITE_DISK) || (game_id == R_GAME_ITE_DEMO)) {
flags = SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE;
} else {
flags = SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS |
SoundMixer::FLAG_LITTLE_ENDIAN;
}
_mixer->playRaw(&_voiceHandle, buf->res_data, buf->res_len, buf->s_freq, flags);
return R_SUCCESS;
}
@ -126,6 +138,8 @@ int Sound::pauseVoice(void) {
return R_FAILURE;
}
_mixer->pauseHandle(_voiceHandle, true);
return R_SUCCESS;
}
@ -134,6 +148,8 @@ int Sound::resumeVoice(void) {
return R_FAILURE;
}
_mixer->pauseHandle(_voiceHandle, false);
return R_SUCCESS;
}
@ -142,6 +158,8 @@ int Sound::stopVoice(void) {
return R_FAILURE;
}
_mixer->stopHandle(_voiceHandle);
return R_SUCCESS;
}

View File

@ -32,13 +32,29 @@
#define SAGA_SOUND_H_
#include "rscfile_mod.h"
#include "game_mod.h"
#include "sound/mixer.h"
namespace Saga {
struct R_SOUNDBUFFER {
byte *res_data;
uint32 res_len;
uint s_freq;
int s_samplebits;
int s_stereo;
int s_signed;
const uchar *s_buf;
size_t s_buf_len;
};
class Sound {
public:
Sound(int enabled);
Sound(SagaEngine *vm, SoundMixer *mixer, int enabled);
~Sound(void);
int play(int sound_rn, int channel);
@ -55,9 +71,18 @@ class Sound {
int _soundInitialized;
R_GAME_SOUNDINFO _snd_info;
R_RSCFILE_CONTEXT *_soundContext;
R_RSCFILE_CONTEXT *_voiceContext;
SagaEngine *_vm;
SoundMixer *_mixer;
PlayingSoundHandle _effectHandle;
PlayingSoundHandle _voiceHandle;
PlayingSoundHandle _musictHandle;
};
} // End of namespace Saga