diff options
author | Max Horn | 2009-03-04 07:31:31 +0000 |
---|---|---|
committer | Max Horn | 2009-03-04 07:31:31 +0000 |
commit | e783859d5c58546b05649c1eb92c6bdbf66b5bb2 (patch) | |
tree | a626fe0fe27bf2709785d87bb9dbe10d11870a43 /engines | |
parent | edc6cc642a92116d3183b072e5a684e1e1410f37 (diff) | |
download | scummvm-rg350-e783859d5c58546b05649c1eb92c6bdbf66b5bb2.tar.gz scummvm-rg350-e783859d5c58546b05649c1eb92c6bdbf66b5bb2.tar.bz2 scummvm-rg350-e783859d5c58546b05649c1eb92c6bdbf66b5bb2.zip |
SCI: Replaced sfx_iterator_make_feed and associated code by Audio::makeLinearInputStream
svn-id: r39115
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 8 | ||||
-rw-r--r-- | engines/sci/module.mk | 1 | ||||
-rw-r--r-- | engines/sci/sfx/core.cpp | 8 | ||||
-rw-r--r-- | engines/sci/sfx/iterator.cpp | 66 | ||||
-rw-r--r-- | engines/sci/sfx/iterator.h | 8 | ||||
-rw-r--r-- | engines/sci/sfx/iterator_internal.h | 11 | ||||
-rw-r--r-- | engines/sci/sfx/pcm-iterator.cpp | 106 |
7 files changed, 59 insertions, 149 deletions
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 71ed439c07..965712ab68 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -41,6 +41,8 @@ #include "common/util.h" #include "common/savefile.h" +#include "sound/audiostream.h" + namespace Sci { extern int debug_sleeptime_factor; @@ -2411,7 +2413,7 @@ int c_simkey(EngineState *s) { static int c_is_sample(EngineState *s) { Resource *song = s->resmgr->findResource(kResourceTypeSound, cmd_params[0].val, 0); song_iterator_t *songit; - sfx_pcm_feed_t *data; + Audio::AudioStream *data; if (!song) { sciprintf("Not a sound resource.\n"); @@ -2426,9 +2428,11 @@ static int c_is_sample(EngineState *s) { } if ((data = songit->get_pcm_feed(songit))) { +/* sciprintf("\nIs sample (encoding %dHz/%s/%04x).\n", data->conf.rate, (data->conf.stereo) ? ((data->conf.stereo == SFX_PCM_STEREO_LR) ? "stereo-LR" : "stereo-RL") : "mono", data->conf.format); - data->destroy(data); +*/ + delete data; } else sciprintf("Valid song, but not a sample.\n"); diff --git a/engines/sci/module.mk b/engines/sci/module.mk index bbc9171cb8..b78844814a 100644 --- a/engines/sci/module.mk +++ b/engines/sci/module.mk @@ -68,7 +68,6 @@ MODULE_OBJS = \ sfx/core.o \ sfx/iterator.o \ sfx/mixer.o \ - sfx/pcm-iterator.o \ sfx/songlib.o \ sfx/device/devices.o \ sfx/player/players.o \ diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 617c5b49bf..bef2b1b8b8 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -33,6 +33,8 @@ #include "common/system.h" #include "common/timer.h" + +#include "sound/audiostream.h" #include "sound/mixer.h" namespace Sci { @@ -341,10 +343,10 @@ int sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) { fprintf(stderr, "[sfx-core] Playing PCM: %08lx\n", handle); #endif if (g_system->getMixer()->isReady()) { - sfx_pcm_feed_t *newfeed = it->get_pcm_feed(it); + Audio::AudioStream *newfeed = it->get_pcm_feed(it); if (newfeed) { - newfeed->debug_nr = (int) handle; - mixer_subscribe(newfeed); +// newfeed->debug_nr = (int) handle; + g_system->getMixer()->playInputStream(Audio::Mixer::kSFXSoundType, 0, newfeed); return 1; } } diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp index b67f8c90dd..5ced70260e 100644 --- a/engines/sci/sfx/iterator.cpp +++ b/engines/sci/sfx/iterator.cpp @@ -31,6 +31,9 @@ #include "sci/tools.h" #include "sci/sci_memory.h" +#include "sound/audiostream.h" +#include "sound/mixer.h" + namespace Sci { static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0, @@ -530,20 +533,39 @@ static int _sci0_get_pcm_data(sci0_song_iterator_t *self, return 0; } -static sfx_pcm_feed_t *_sci0_check_pcm(sci0_song_iterator_t *self) { - sfx_pcm_config_t format; +static Audio::AudioStream *makeStream(byte *data, int size, sfx_pcm_config_t conf) { + printf("Playing PCM data of size %d, rate %d\n", size, conf.rate); + + // Duplicate the data + byte *sound = (byte *)malloc(size); + memcpy(sound, data + SCI0_PCM_DATA_OFFSET, size); + + // Convert stream format flags + int flags = Audio::Mixer::FLAG_AUTOFREE; + if (conf.format == SFX_PCM_FORMAT_U8) + flags |= Audio::Mixer::FLAG_UNSIGNED; + else if (conf.format == SFX_PCM_FORMAT_S16_NATIVE) { + flags |= Audio::Mixer::FLAG_16BITS; +#ifndef SCUMM_BIG_ENDIAN + flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; +#endif + } + if (conf.stereo) + flags |= Audio::Mixer::FLAG_STEREO; + + return Audio::makeLinearInputStream(sound, size, conf.rate, flags, 0, 0); +} + +static Audio::AudioStream *_sci0_check_pcm(sci0_song_iterator_t *self) { + sfx_pcm_config_t conf; int offset; unsigned int size; - if (_sci0_get_pcm_data(self, &format, &offset, &size)) + if (_sci0_get_pcm_data(self, &conf, &offset, &size)) return NULL; - self->channel.state - = SI_STATE_FINISHED; /* Don't play both PCM and music */ + self->channel.state = SI_STATE_FINISHED; /* Don't play both PCM and music */ - return sfx_iterator_make_feed(self->data, - offset + SCI0_PCM_DATA_OFFSET, - size, - format); + return makeStream(self->data + offset + SCI0_PCM_DATA_OFFSET, size, conf); } static song_iterator_t *_sci0_handle_message(sci0_song_iterator_t *self, song_iterator_message_t msg) { @@ -945,15 +967,12 @@ static inline int _sci1_command_index(sci1_song_iterator_t *self) { } -static sfx_pcm_feed_t *_sci1_get_pcm(sci1_song_iterator_t *self) { +static Audio::AudioStream *_sci1_get_pcm(sci1_song_iterator_t *self) { if (self->next_sample && self->next_sample->delta <= 0) { sci1_sample_t *sample = self->next_sample; - sfx_pcm_feed_t *feed - = sfx_iterator_make_feed(self->data, - sample->data - self->data, - sample->size, - sample->format); + + Audio::AudioStream *feed = makeStream(sample->data, sample->size, sample->format); self->next_sample = self->next_sample->next; @@ -995,9 +1014,8 @@ static int _sci1_process_next_command(sci1_song_iterator_t *self, if (self->next_sample->announced) { /* Already announced; let's discard it */ - sfx_pcm_feed_t *feed - = _sci1_get_pcm(self); - feed->destroy(feed); + Audio::AudioStream *feed = _sci1_get_pcm(self); + delete feed; } else { int delay = self->next_sample->delta; @@ -1310,7 +1328,7 @@ static int _ff_read_next_command(fast_forward_song_iterator_t *self, } } -static sfx_pcm_feed_t *_ff_check_pcm(fast_forward_song_iterator_t *self) { +static Audio::AudioStream *_ff_check_pcm(fast_forward_song_iterator_t *self) { return self->delegate->get_pcm_feed(self->delegate); } @@ -1382,7 +1400,7 @@ song_iterator_t *new_fast_forward_iterator(song_iterator_t *capsit, int delta) { it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) _ff_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + it->get_pcm_feed = (Audio::AudioStream * (*)(song_iterator_t *)) _ff_check_pcm; it->handle_message = (song_iterator_t * (*)(song_iterator_t *, song_iterator_message_t)) @@ -1534,7 +1552,7 @@ static int _tee_read_next_command(tee_song_iterator_t *it, unsigned char *buf, return it->children[retid].retval; } -static sfx_pcm_feed_t *_tee_check_pcm(tee_song_iterator_t *it) { +static Audio::AudioStream *_tee_check_pcm(tee_song_iterator_t *it) { static int pcm_masks[2] = {TEE_LEFT_PCM, TEE_RIGHT_PCM}; int i; @@ -1712,7 +1730,7 @@ song_iterator_t *songit_new_tee(song_iterator_t *left, song_iterator_t *right, i it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) _tee_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + it->get_pcm_feed = (Audio::AudioStream * (*)(song_iterator_t *)) _tee_check_pcm; it->handle_message = (song_iterator_t * (*)(song_iterator_t *, @@ -1814,7 +1832,7 @@ song_iterator_t *songit_new(unsigned char *data, unsigned int size, int type, so it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) _sci0_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + it->get_pcm_feed = (Audio::AudioStream * (*)(song_iterator_t *)) _sci0_check_pcm; it->handle_message = (song_iterator_t * (*)(song_iterator_t *, song_iterator_message_t)) _sci0_handle_message; @@ -1835,7 +1853,7 @@ song_iterator_t *songit_new(unsigned char *data, unsigned int size, int type, so it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) _sci1_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + it->get_pcm_feed = (Audio::AudioStream * (*)(song_iterator_t *)) _sci1_get_pcm; it->handle_message = (song_iterator_t * (*)(song_iterator_t *, song_iterator_message_t)) _sci1_handle_message; diff --git a/engines/sci/sfx/iterator.h b/engines/sci/sfx/iterator.h index 6fe6a36118..e954f1397c 100644 --- a/engines/sci/sfx/iterator.h +++ b/engines/sci/sfx/iterator.h @@ -30,6 +30,10 @@ #include "sci/sfx/sfx_pcm.h" +namespace Audio { + class AudioStream; +} + namespace Sci { #define SI_FINISHED -1 /* Song finished playing */ @@ -135,10 +139,10 @@ struct song_iterator_t { ** PCM, but this must be done before any subsequent calls to next(). */ - sfx_pcm_feed_t * (*get_pcm_feed)(song_iterator_t *self); + Audio::AudioStream * (*get_pcm_feed)(song_iterator_t *self); /* Checks for the presence of a pcm sample ** Parameters: (song_iterator_t *) self - ** Returns : (sfx_pcm_feed_t *) NULL if no PCM data was found, a + ** Returns : (Audio::AudioStream *) NULL if no PCM data was found, a ** PCM feed otherwise */ diff --git a/engines/sci/sfx/iterator_internal.h b/engines/sci/sfx/iterator_internal.h index d89c97b12e..74a881e046 100644 --- a/engines/sci/sfx/iterator_internal.h +++ b/engines/sci/sfx/iterator_internal.h @@ -208,17 +208,6 @@ struct tee_song_iterator_t : public song_iterator_t { } children[2]; }; - -sfx_pcm_feed_t *sfx_iterator_make_feed(byte *base_data, int offset, - int size, sfx_pcm_config_t conf); -/* Generates a feed for a song iterator -** Parameters: (byte *) base_data: A refcounted memory chunk containing -** (among other things) PCM data -** (int) offset; Offset into base_data -** (int) size: Number of bytes to consider -** (pcm_data_internal_t) conf: PCM encoding -*/ - } // End of namespace Sci #endif // SCI_SFX_SFX_ITERATOR_INTERNAL diff --git a/engines/sci/sfx/pcm-iterator.cpp b/engines/sci/sfx/pcm-iterator.cpp deleted file mode 100644 index ff9f051a89..0000000000 --- a/engines/sci/sfx/pcm-iterator.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * 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. - * - * 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$ - * - */ - -#include "sci/sfx/iterator.h" -#include "sci/tools.h" /* for BREAKPOINT */ -#include "sci/sci_memory.h" - -namespace Sci { - -#define D ((pcm_data_internal_t *)self->internal) - -static int pi_poll(sfx_pcm_feed_t *self, byte *dest, int size); -static void pi_destroy(sfx_pcm_feed_t *self); - -struct pcm_data_internal_t { - byte *base_data; - byte *data; - int frames_left; -}; - - -static sfx_pcm_feed_t pcm_it_prototype = { - pi_poll, - pi_destroy, - NULL, /* No timestamp getter */ - NULL, /* Internal data goes here */ - {0, 0, 0}, /* Must fill in configuration */ - "song-iterator", - 0, /* Ideally the resource number should go here */ - 0 /* The mixer computes this for us */ -}; - - -sfx_pcm_feed_t *sfx_iterator_make_feed(byte *base_data, int offset, int size, sfx_pcm_config_t conf) { - sfx_pcm_feed_t *feed; - pcm_data_internal_t *idat; - byte *data = base_data + offset; - - if (!data) { - /* Now this is silly; why'd you call this function in the first place? */ - return NULL; - } - sci_refcount_incref(base_data); - - idat = (pcm_data_internal_t*)sci_malloc(sizeof(pcm_data_internal_t)); - idat->base_data = base_data; - idat->data = data; - idat->frames_left = size; - feed = (sfx_pcm_feed_t*)sci_malloc(sizeof(sfx_pcm_feed_t)); - *feed = pcm_it_prototype; - feed->internal = idat; - feed->conf = conf; - - return feed; -} - - -static int pi_poll(sfx_pcm_feed_t *self, byte *dest, int size) { - int data_len; - - if (size >= D->frames_left) - size = D->frames_left; - - D->frames_left -= size; - - data_len = size * self->frame_size; - - memcpy(dest, D->data, data_len); -#if 0 - memset(dest, 0xff, data_len); -#endif - - D->data += data_len; - - return size; -} - -static void pi_destroy(sfx_pcm_feed_t *self) { - sci_refcount_decref(D->base_data); - free(D); - free(self); -} - -} // End of namespace Sci |