diff options
author | Max Horn | 2004-12-11 23:36:17 +0000 |
---|---|---|
committer | Max Horn | 2004-12-11 23:36:17 +0000 |
commit | e1f6101140f3243caf407a7be934a02cc44c1a57 (patch) | |
tree | 1a8399cda52b70a01b473a42f8f3432ce62898a5 | |
parent | 3891c0fa39c35f84b6eea3ad5001125806160938 (diff) | |
download | scummvm-rg350-e1f6101140f3243caf407a7be934a02cc44c1a57.tar.gz scummvm-rg350-e1f6101140f3243caf407a7be934a02cc44c1a57.tar.bz2 scummvm-rg350-e1f6101140f3243caf407a7be934a02cc44c1a57.zip |
use loadVOCFromStream
svn-id: r16036
-rw-r--r-- | saga/sndres.cpp | 90 | ||||
-rw-r--r-- | saga/sndres.h | 29 |
2 files changed, 15 insertions, 104 deletions
diff --git a/saga/sndres.cpp b/saga/sndres.cpp index 5c7b583123..da94ec664e 100644 --- a/saga/sndres.cpp +++ b/saga/sndres.cpp @@ -33,6 +33,8 @@ #include "common/file.h" +#include "sound/voc.h" + namespace Saga { SndRes::SndRes(SagaEngine *vm) : _vm(vm) { @@ -173,88 +175,26 @@ int SndRes::load(RSCFILE_CONTEXT *snd_ctxt, uint32 snd_rn, SOUNDBUFFER *snd_buf_ } int SndRes::loadVocSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i) { - VOC_HEADER_BLOCK voc_hb; - VOC_GENBLOCK voc_gb; - VOC_BLOCK1 voc_b1; - byte *data; - - long byte_rate; - size_t i; - - if (snd_res_len < VOC_HEADER_BLOCK_LEN) { - return FAILURE; - } - MemoryReadStream readS(snd_res, snd_res_len); + byte *data; + int rate; + int len; - for (i = 0; i < VOC_FILE_DESC_LEN; i++) - voc_hb.ft_desc[i] = readS.readByte(); - - if (memcmp(voc_hb.ft_desc, VOC_FILE_DESC, VOC_FILE_DESC_LEN) != 0) { - /* Voc file desc string not found */ - return FAILURE; - } - - voc_hb.db_offset = readS.readUint16LE(); - voc_hb.voc_version = readS.readUint16LE(); - voc_hb.voc_fileid = readS.readUint16LE(); + data = loadVOCFromStream(readS, len, rate); - if ((int32)(snd_res_len - readS.pos()) < (int32)(voc_hb.db_offset + VOC_GENBLOCK_LEN)) { + if (!data) { return FAILURE; } - while (readS.pos() < voc_hb.db_offset) - readS.readByte(); - - for (;;) { - /* Read generic block header */ - if (snd_res_len - readS.pos() < VOC_GENBLOCK_LEN) { - return FAILURE; - } - - voc_gb.block_id = readS.readByte(); - if (voc_gb.block_id == 0) { - return FAILURE; - } - - voc_gb.block_len = readS.readUint24LE(); - - /* Process block */ - switch (voc_gb.block_id) { - case 1: /* Sound data block */ - voc_b1.time_constant = readS.readByte(); - voc_b1.pack_method = readS.readByte(); - - if (voc_b1.pack_method != 0) { - debug(0, "Packed VOC files not supported"); - return FAILURE; - } - - byte_rate = VOC_TIME_BASE / (VOC_TIME_CBASE - (voc_b1.time_constant << 8)); - - snd_buf_i->s_stereo = 0; - snd_buf_i->s_samplebits = 8; - snd_buf_i->s_freq = byte_rate; - snd_buf_i->s_buf_len = snd_res_len - readS.pos() - 1; /* -1 for end block */ - - data = (byte *)malloc(snd_buf_i->s_buf_len); - if (!data) { - return FAILURE; - } - - readS.read(data, snd_buf_i->s_buf_len); - - snd_buf_i->s_buf = data; - snd_buf_i->s_signed = 0; - return SUCCESS; - default: - for (i = 0; i < voc_gb.block_len; i++) - readS.readByte(); - break; - } - } - + snd_buf_i->s_freq = rate; + snd_buf_i->s_samplebits = 8; + snd_buf_i->s_stereo = 0; + snd_buf_i->s_signed = 0; + snd_buf_i->s_buf = data; + snd_buf_i->s_buf_len = len; + return SUCCESS; + } int SndRes::loadWavSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i) { diff --git a/saga/sndres.h b/saga/sndres.h index b5bdd65c48..30c5dd1a7a 100644 --- a/saga/sndres.h +++ b/saga/sndres.h @@ -32,35 +32,6 @@ namespace Saga { -#define VOC_TIME_BASE 256000000L -#define VOC_TIME_CBASE 65536L - -#define VOC_FILE_DESC_LEN 20 -#define VOC_FILE_DESC "Creative Voice File\x1A" - -struct VOC_HEADER_BLOCK { - char ft_desc[20]; // BYTE [20] - uint16 db_offset; // WORD - uint16 voc_version;// WORD - uint16 voc_fileid; // WORD -}; - -#define VOC_HEADER_BLOCK_LEN 26 - -struct VOC_GENBLOCK { - int block_id; // BYTE - uint32 block_len; // BYTE[3] -}; - -#define VOC_GENBLOCK_LEN 4 - -struct VOC_BLOCK1 { - int block_id; // BYTE - uint32 block_len; // BYTE[3] - uint16 time_constant; // BYTE - int pack_method; // BYTE -}; - class SndRes { public: |