[Scummvm-cvs-logs] SF.net SVN: scummvm:[39115] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Mar 4 08:31:31 CET 2009


Revision: 39115
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39115&view=rev
Author:   fingolfin
Date:     2009-03-04 07:31:31 +0000 (Wed, 04 Mar 2009)

Log Message:
-----------
SCI: Replaced sfx_iterator_make_feed and associated code by Audio::makeLinearInputStream

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/module.mk
    scummvm/trunk/engines/sci/sfx/core.cpp
    scummvm/trunk/engines/sci/sfx/iterator.cpp
    scummvm/trunk/engines/sci/sfx/iterator.h
    scummvm/trunk/engines/sci/sfx/iterator_internal.h

Removed Paths:
-------------
    scummvm/trunk/engines/sci/sfx/pcm-iterator.cpp

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-04 07:31:31 UTC (rev 39115)
@@ -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 @@
 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 @@
 	}
 
 	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");
 

Modified: scummvm/trunk/engines/sci/module.mk
===================================================================
--- scummvm/trunk/engines/sci/module.mk	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/module.mk	2009-03-04 07:31:31 UTC (rev 39115)
@@ -68,7 +68,6 @@
 	sfx/core.o \
 	sfx/iterator.o \
 	sfx/mixer.o \
-	sfx/pcm-iterator.o \
 	sfx/songlib.o \
 	sfx/device/devices.o \
 	sfx/player/players.o \

Modified: scummvm/trunk/engines/sci/sfx/core.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.cpp	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/sfx/core.cpp	2009-03-04 07:31:31 UTC (rev 39115)
@@ -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 @@
 	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;
 		}
 	}

Modified: scummvm/trunk/engines/sci/sfx/iterator.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator.cpp	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/sfx/iterator.cpp	2009-03-04 07:31:31 UTC (rev 39115)
@@ -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 @@
 	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,16 +967,13 @@
 }
 
 
-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;
 
 		free(sample);
@@ -995,9 +1014,8 @@
 
 			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 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 @@
 
 	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 @@
 	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 @@
 	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 @@
 
 		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 @@
 
 		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;

Modified: scummvm/trunk/engines/sci/sfx/iterator.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator.h	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/sfx/iterator.h	2009-03-04 07:31:31 UTC (rev 39115)
@@ -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 @@
 	** 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
 	*/
 

Modified: scummvm/trunk/engines/sci/sfx/iterator_internal.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator_internal.h	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/sfx/iterator_internal.h	2009-03-04 07:31:31 UTC (rev 39115)
@@ -208,17 +208,6 @@
 	} 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

Deleted: scummvm/trunk/engines/sci/sfx/pcm-iterator.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/pcm-iterator.cpp	2009-03-04 07:22:29 UTC (rev 39114)
+++ scummvm/trunk/engines/sci/sfx/pcm-iterator.cpp	2009-03-04 07:31:31 UTC (rev 39115)
@@ -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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list