[Scummvm-cvs-logs] SF.net SVN: scummvm:[41461] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Fri Jun 12 09:55:44 CEST 2009


Revision: 41461
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41461&view=rev
Author:   peres001
Date:     2009-06-12 07:55:44 +0000 (Fri, 12 Jun 2009)

Log Message:
-----------
Cleanup of sound code.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/disk_ns.cpp
    scummvm/trunk/engines/parallaction/sound.h
    scummvm/trunk/engines/parallaction/sound_br.cpp
    scummvm/trunk/engines/parallaction/sound_ns.cpp

Modified: scummvm/trunk/engines/parallaction/disk_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk_ns.cpp	2009-06-12 07:18:01 UTC (rev 41460)
+++ scummvm/trunk/engines/parallaction/disk_ns.cpp	2009-06-12 07:55:44 UTC (rev 41461)
@@ -29,12 +29,6 @@
 #include "parallaction/parallaction.h"
 
 
-namespace Audio {
-	class AudioStream;
-
-	AudioStream *make8SVXStream(Common::ReadStream &input);
-}
-
 namespace Parallaction {
 
 

Modified: scummvm/trunk/engines/parallaction/sound.h
===================================================================
--- scummvm/trunk/engines/parallaction/sound.h	2009-06-12 07:18:01 UTC (rev 41460)
+++ scummvm/trunk/engines/parallaction/sound.h	2009-06-12 07:55:44 UTC (rev 41461)
@@ -84,6 +84,14 @@
 	SC_PAUSE
 };
 
+struct Channel {
+	Audio::AudioStream *stream;
+	Audio::SoundHandle	handle;
+	uint32				volume;
+};
+
+
+
 class SoundMan_ns : public SoundManImpl {
 public:
 	enum {
@@ -148,13 +156,7 @@
 	Audio::AudioStream *_musicStream;
 	Audio::SoundHandle	_musicHandle;
 
-	struct Channel {
-		Audio::Voice8Header	header;
-		int8				*data;
-		uint32				dataSize;
-		bool				dispose;
-		Audio::SoundHandle	handle;
-	} _channels[NUM_SFX_CHANNELS];
+	Channel _channels[NUM_SFX_CHANNELS];
 
 	Audio::AudioStream *loadChannelData(const char *filename, Channel *ch, bool looping);
 
@@ -191,18 +193,12 @@
 	bool	_musicEnabled;
 	bool	_sfxEnabled;
 
+	Channel _channels[NUM_SFX_CHANNELS];
+
 	virtual void playMusic() = 0;
 	virtual void stopMusic() = 0;
 	virtual void pause(bool p) = 0;
 
-	struct Channel {
-		Audio::Voice8Header	header;
-		int8				*data;
-		uint32				dataSize;
-		bool				dispose;
-		Audio::SoundHandle	handle;
-	} _channels[NUM_SFX_CHANNELS];
-
 public:
 	SoundMan_br(Parallaction_br *vm);
 	~SoundMan_br();

Modified: scummvm/trunk/engines/parallaction/sound_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/sound_br.cpp	2009-06-12 07:18:01 UTC (rev 41460)
+++ scummvm/trunk/engines/parallaction/sound_br.cpp	2009-06-12 07:55:44 UTC (rev 41461)
@@ -404,25 +404,26 @@
 Audio::AudioStream *DosSoundMan_br::loadChannelData(const char *filename, Channel *ch, bool looping) {
 	Common::SeekableReadStream *stream = _vm->_disk->loadSound(filename);
 
-	ch->dataSize = stream->size();
-	ch->data = (int8*)malloc(ch->dataSize);
-	if (stream->read(ch->data, ch->dataSize) != ch->dataSize)
+	uint32 dataSize = stream->size();
+	int8 *data = (int8*)malloc(dataSize);
+	if (stream->read(data, dataSize) != dataSize)
 		error("DosSoundMan_br::loadChannelData: Read failed");
 
-	ch->dispose = true;
 	delete stream;
 
 	// TODO: Confirm sound rate
-	ch->header.samplesPerSec = 11025;
+	int rate = 11025;
 
-	uint32 loopStart = 0, loopEnd = 0, flags = Audio::Mixer::FLAG_UNSIGNED;
+	uint32 loopStart = 0, loopEnd = 0;
+	uint32 flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
+
 	if (looping) {
-		loopEnd = ch->dataSize;
+		loopEnd = dataSize;
 		flags |= Audio::Mixer::FLAG_LOOP;
 	}
 
-	// Create the input stream
-	return Audio::makeLinearInputStream((byte *)ch->data, ch->dataSize, ch->header.samplesPerSec, flags, loopStart, loopEnd);
+	ch->stream = Audio::makeLinearInputStream((byte *)data, dataSize, rate, flags, loopStart, loopEnd);
+	return ch->stream;
 }
 
 void DosSoundMan_br::playSfx(const char *filename, uint channel, bool looping, int volume) {
@@ -474,26 +475,21 @@
 	Audio::AudioStream *input = 0;
 
 	if (_vm->getFeatures() & GF_DEMO) {
-		ch->dataSize = stream->size();
-		ch->data = (int8*)malloc(ch->dataSize);
-		if (stream->read(ch->data, ch->dataSize) != ch->dataSize)
+		uint32 dataSize = stream->size();
+		int8 *data = (int8*)malloc(dataSize);
+		if (stream->read(data, dataSize) != dataSize)
 			error("DosSoundMan_br::loadChannelData: Read failed");
 
 		// TODO: Confirm sound rate
-		ch->header.samplesPerSec = 11025;
-
-		uint32 loopStart = 0, loopEnd = 0, flags = 0;
-		if (looping) {
-			loopEnd = ch->header.oneShotHiSamples + ch->header.repeatHiSamples;
-			flags = Audio::Mixer::FLAG_LOOP;
-		}
-
-		input = Audio::makeLinearInputStream((byte *)ch->data, ch->dataSize, ch->header.samplesPerSec, flags, loopStart, loopEnd);
+		int rate = 11025;
+		input = Audio::makeLinearInputStream((byte *)data, dataSize, rate, Audio::Mixer::FLAG_AUTOFREE, 0, 0);
 	} else {
 		input = Audio::make8SVXStream(*stream, looping);
-		delete stream;
 	}
 
+	delete stream;
+
+	ch->stream = input;
 	return input;
 }
 
@@ -515,7 +511,7 @@
 	Audio::AudioStream *input = loadChannelData(filename, ch, looping);
 
 	if (volume == -1) {
-		volume = ch->header.volume;
+		volume = ch->volume;
 	}
 
 	_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &ch->handle, input, -1, volume);
@@ -560,15 +556,6 @@
 SoundMan_br::SoundMan_br(Parallaction_br *vm) : _vm(vm) {
 	_mixer = _vm->_mixer;
 
-	_channels[0].data = 0;
-	_channels[0].dispose = false;
-	_channels[1].data = 0;
-	_channels[1].dispose = false;
-	_channels[2].data = 0;
-	_channels[2].dispose = false;
-	_channels[3].data = 0;
-	_channels[3].dispose = false;
-
 	_musicEnabled = true;
 	_sfxEnabled = true;
 }
@@ -595,12 +582,9 @@
 		return;
 	}
 
-	if (_channels[channel].dispose) {
-		debugC(1, kDebugAudio, "SoundMan_br::stopSfx(%i)", channel);
-		_mixer->stopHandle(_channels[channel].handle);
-		free(_channels[channel].data);
-		_channels[channel].data = 0;
-	}
+	debugC(1, kDebugAudio, "SoundMan_br::stopSfx(%i)", channel);
+	_mixer->stopHandle(_channels[channel].handle);
+	_channels[channel].stream = 0;
 }
 
 void SoundMan_br::execute(int command, const char *parm) {

Modified: scummvm/trunk/engines/parallaction/sound_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/sound_ns.cpp	2009-06-12 07:18:01 UTC (rev 41460)
+++ scummvm/trunk/engines/parallaction/sound_ns.cpp	2009-06-12 07:55:44 UTC (rev 41461)
@@ -335,14 +335,6 @@
 
 AmigaSoundMan_ns::AmigaSoundMan_ns(Parallaction_ns *vm) : SoundMan_ns(vm) {
 	_musicStream = 0;
-	_channels[0].data = 0;
-	_channels[0].dispose = false;
-	_channels[1].data = 0;
-	_channels[1].dispose = false;
-	_channels[2].data = 0;
-	_channels[2].dispose = false;
-	_channels[3].data = 0;
-	_channels[3].dispose = false;
 }
 
 AmigaSoundMan_ns::~AmigaSoundMan_ns() {
@@ -364,34 +356,25 @@
 	Audio::AudioStream *input = 0;
 
 	if (!scumm_stricmp("beep", filename)) {
-		ch->header.oneShotHiSamples = 0;
-		ch->header.repeatHiSamples = 0;
-		ch->header.samplesPerHiCycle = 0;
-		ch->header.samplesPerSec = 11934;
-		ch->header.volume = 160;
-		ch->data = (int8*)malloc(AMIGABEEP_SIZE * NUM_REPEATS);
-		int8* odata = ch->data;
+		// TODO: make a permanent stream out of this
+		uint32 dataSize = AMIGABEEP_SIZE * NUM_REPEATS;
+		int8 *data = (int8*)malloc(dataSize);
+		int8 *odata = data;
 		for (uint i = 0; i < NUM_REPEATS; i++) {
 			memcpy(odata, res_amigaBeep, AMIGABEEP_SIZE);
 			odata += AMIGABEEP_SIZE;
 		}
-		ch->dataSize = AMIGABEEP_SIZE * NUM_REPEATS;
-		ch->dispose = true;
-
-		uint32 loopStart = 0, loopEnd = 0, flags = 0;
-		if (looping) {
-			loopEnd = ch->header.oneShotHiSamples + ch->header.repeatHiSamples;
-			flags = Audio::Mixer::FLAG_LOOP;
-		}
-
-		input = Audio::makeLinearInputStream((byte *)ch->data, ch->dataSize, ch->header.samplesPerSec, flags, loopStart, loopEnd);
+		int rate = 11934;
+		ch->volume = 160;
+		input = Audio::makeLinearInputStream((byte *)data, dataSize, rate, Audio::Mixer::FLAG_AUTOFREE, 0, 0);
 	} else {
 		Common::SeekableReadStream *stream = _vm->_disk->loadSound(filename);
 		input = Audio::make8SVXStream(*stream, looping);
-		ch->dispose = true;
 		delete stream;
 	}
 
+	ch->stream = input;
+
 	return input;
 }
 
@@ -409,7 +392,7 @@
 	Audio::AudioStream *input = loadChannelData(filename, ch, looping);
 
 	if (volume == -1) {
-		volume = ch->header.volume;
+		volume = ch->volume;
 	}
 
 	_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &ch->handle, input, -1, volume);
@@ -421,12 +404,9 @@
 		return;
 	}
 
-	if (_channels[channel].dispose) {
-		debugC(1, kDebugAudio, "AmigaSoundMan_ns::stopSfx(%i)", channel);
-		_mixer->stopHandle(_channels[channel].handle);
-		free(_channels[channel].data);
-		_channels[channel].data = 0;
-	}
+	debugC(1, kDebugAudio, "AmigaSoundMan_ns::stopSfx(%i)", channel);
+	_mixer->stopHandle(_channels[channel].handle);
+	_channels[channel].stream = 0;
 }
 
 void AmigaSoundMan_ns::playMusic() {


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