[Scummvm-cvs-logs] SF.net SVN: scummvm: [32861] scummvm/branches/gsoc2008-tfmx/sound/mods

marwanhilmi at users.sourceforge.net marwanhilmi at users.sourceforge.net
Tue Jul 1 02:28:38 CEST 2008


Revision: 32861
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32861&view=rev
Author:   marwanhilmi
Date:     2008-06-30 17:28:38 -0700 (Mon, 30 Jun 2008)

Log Message:
-----------
TFMX class. Members + functions still need to be revised as things progress.
Load() implemented. Basic readTrackstep() implemented with work in progress.

Added Paths:
-----------
    scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.cpp
    scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.h

Added: scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.cpp
===================================================================
--- scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.cpp	2008-07-01 00:28:38 UTC (rev 32861)
@@ -0,0 +1,202 @@
+/* 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 "sound/mods/tfmx.h"
+#include "sound/mods/paula.h"
+
+namespace Audio {
+
+Tfmx::Tfmx(bool stereo, int rate, int interruptFreq)
+	: Paula(stereo, rate, interruptFreq) {
+	//blank now
+}
+
+Tfmx::~Tfmx() {
+	if (_data)
+		delete[] _data;
+}
+
+void Tfmx::load() {
+	// FIXME: temporary loader - just creates seekablereadstream from c:\mk.mdat
+	Common::SeekableReadStream *stream = NULL;
+	Common::File myfile;
+	myfile.addDefaultDirectory("C:");
+	myfile.open("mk.mdat");
+	stream = myfile.readStream(myfile.size());
+	myfile.close();
+	//FIXME: end temporary loader. normally the seekablereadstream will be function parameter
+
+	_dataSize = stream->size();
+	_data = new uint8[_dataSize];
+	stream->seek(0);
+	stream->read(_data, _dataSize);
+
+	Common::MemoryReadStream dataStream(_data, _dataSize);
+	//should implement a check here to read header and ensure TFMXness
+
+	dataStream.seek(256);
+	// TODO: should be able to put in one loop??
+	//will also later to modify to dynamically scale arrays for smaller TFMX files
+	//in the case of Monkey Island, it uses 22/32 songs, and 128/128 for patterns/macros
+	for (int i = 0; i < 32; i++) {
+		_songs[i].startPosition = dataStream.readUint16BE();
+	}
+	for (int i = 0; i < 32; i++) {
+		_songs[i].endPosition = dataStream.readUint16BE(); 
+	}
+	for (int i = 0; i < 32; i++) {
+		_songs[i].tempoValue = dataStream.readUint16BE();
+	}
+	
+	//read table positions specified at $01D0 in file (packed module)
+	dataStream.skip(16);
+	_trackTableOffset = dataStream.readUint32BE();
+	_patternTableOffset = dataStream.readUint32BE();
+	_macroTableOffset = dataStream.readUint32BE();
+	
+	//unpacked module specification
+	if (!_trackTableOffset) 
+		_trackTableOffset = 2048;    //$800 position
+	if (!_patternTableOffset)
+		_patternTableOffset = 1024; //$400 position
+	if (!_macroTableOffset)
+		_macroTableOffset = 1536;   //$600 position
+
+	//skip to positon of pointer tables
+	dataStream.seek(_patternTableOffset, SEEK_SET);
+	for (int i = 0; i < 128; i++) {
+		_patternPointers[i] = dataStream.readUint32BE();
+	}
+	dataStream.seek(_macroTableOffset, SEEK_SET);
+	for (int i = 0; i < 128; i++) {
+		_macroPointers[i] = dataStream.readUint32BE();
+	}
+	
+	//trackstep read test
+	readTrackstep( 0 );
+}
+bool Tfmx::load(Common::SeekableReadStream &stream) {
+	return true;
+}
+bool Tfmx::play() {
+	return true;
+}
+void Tfmx::loadSongs() {
+}
+void Tfmx::readTrackstep(uint8 songNumber) {
+	if (songNumber >= 32) {
+		//TODO: error, not a valid index
+	}
+
+	uint32 startPosition;   //offset into file from start for trackstart
+	uint32 endPosition;     //offset into file from start for trackend
+	int32 numCommands;		//number of 1 word track commands
+	int32 numSteps;         //number of tracksteps; not yet useful
+	startPosition = (_songs[songNumber].startPosition * 16) + _trackTableOffset;
+	//the file specifies the start position of the last line, so you need to add 16
+	//to get to the actual position where the track ends
+	endPosition = (_songs[songNumber].endPosition * 16) + _trackTableOffset + 16;
+	numCommands = (endPosition - startPosition) / 2;
+	numSteps = numCommands / 8;
+
+	Common::MemoryReadStream dataStream(_data, _dataSize);
+	Common::SeekableSubReadStream trackSubStream(&dataStream, startPosition, endPosition);
+
+	//read entire track by each 1 word command
+	//can then read to determine if it is a pattern or a command
+	//temporary solution - will need to organize by the 8-track per trackstep structure
+	uint16 *tracks;
+	tracks = new uint16[numCommands];
+	for (int i = 0; i < numCommands; i++) {
+		tracks[i] = trackSubStream.readUint16BE();
+	}
+	//you can now read track[] command by command. Maybe trackSubStream can be deleted?
+	
+	//start track reading
+	//need to implement tempo/timing system here
+	for (int i = 0; i < numCommands; i++) {
+
+		//flag for trackstep function is only found at the start of each line (every 8th tracks[] )
+		if (i == 0 || i % 8 == 0 && tracks[i] == 61438) {
+			//trackstep functions
+			switch (tracks[i+1]) {
+			case 0: // EFFE0000 Stop player
+				stopPlayer();
+				break;
+			case 1: //EFFE0001 Play a selection
+				//uint16 selectionPosition = tracks[i+2]; 
+				//uint16 selectionLoops = tracks[i+3];    
+				playSelection(); //TODO: will accept selectionPosition & selectionLoops as parameters
+				break;
+			case 2: //EFFE002 Set the tempo
+				//uint16 tempoDivisor = tracks[i+2];    
+				//uint16 tempoBPM = tracks[i+3];        
+				setTempo(); //TODO: will accept tempoDivisor & tempoBPM as parameters
+				break;
+			case 3: //EFFE0003 Function??? Not used in MI. Flagged as multimode/7 channel setting in other players
+				break;
+			case 4: //EFFE0004 Volume slide
+				//uint16 volumeDivisor = tracks[i+2];    
+				//uint16 volumeTarget = tracks[i+3];     
+				volumeSlide(); //TODO: will accept volumeDivisor & volumeTarget as parameters
+				break;
+			default: //Non-existant command
+				//TODO: error
+				break;
+			}		
+			i += 7; //skips to end of line, loop then terminates and moves to i += 8, the start of next line
+		} else {
+			//it is a pattern, readPattern for tracks[]
+			
+			//each track[] is 16 bits; first 8 bits is pattern number, second 8 bits is transpose number
+			//could just skip the masking for patternNumber and shift it 8 bits to the right
+			uint8 patternNumber = (tracks[i] & 0xFF00) >> 8;
+			uint8 patternTranspose = (tracks[i] & 0x00FF);
+			readPattern(patternNumber);
+		}
+	}
+}
+void Tfmx::readPattern(uint8 patternNumber) {
+	//TODO: setup lookup routine which reads pattern number and then finds corresponding address
+	//maybe a stream containing the pattern should be created in same way it was done in readTrackstep()
+}
+void Tfmx::readNote(Note _aNote) {
+}
+void Tfmx::readMacro(int _macroNumber) {
+}
+void Tfmx::stopPlayer() {
+}
+void Tfmx::playSelection() {
+}
+void Tfmx::setTempo() {
+}
+void Tfmx::volumeSlide() {
+}
+void Tfmx::interrupt() {
+}
+
+
+} // End of namespace Audio
+


Property changes on: scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.h
===================================================================
--- scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.h	2008-07-01 00:28:38 UTC (rev 32861)
@@ -0,0 +1,102 @@
+/* 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$
+ *
+ */
+
+#ifndef SOUND_MODS_TFMX_H
+#define SOUND_MODS_TFMX_H
+
+#include "common/stream.h"
+#include "common/file.h"
+#include "sound/mods/paula.h"
+
+namespace Audio {
+
+class Tfmx : public Paula {
+public:
+		//constructor with appropiate default values and initialization
+		Tfmx(bool stereo = false, int rate = 44100, int interruptFreq = 0);
+		~Tfmx();
+
+		//temporary loader function, will be moved to one below
+		void load();
+		//load function loads file from stream, performs checks, initializes some variables
+		bool load(Common::SeekableReadStream &stream);
+		
+		//generic function to start playback
+		bool play();
+		
+protected:
+		byte *_data;      //buffer
+		uint32 _dataSize; //buffer size
+
+		uint32 _trackTableOffset;
+		uint32 _patternTableOffset;
+		uint32 _macroTableOffset;
+
+		uint32 _patternPointers[128];
+		uint32 _macroPointers[128]; 
+
+		struct Note {
+			uint8 noteValue;
+			uint8 macroNumber;
+			uint8 volume;
+			uint8 channelNumber;
+			uint8 wait;
+		};
+
+		struct Song {
+			uint16 startPosition;
+			uint16 endPosition;
+			uint16 tempoValue;
+		}_songs[32];
+
+		struct Channel {
+			//empty 
+			uint8 crap;
+		}_channels[4];
+
+		//functions used in playback (in order by relationship)
+		void loadSongs();
+		void readTrackstep(uint8 songNumber);
+		void readPattern(uint8 patternNumber);
+		void readNote(Note _aNote);
+		void readMacro(int _macroNumber);
+		//trackstep functions
+		void stopPlayer();
+		void playSelection();
+		void setTempo();
+		void volumeSlide();
+
+		//pattern functions + macro functions will either be handled as discrete functions
+		//or handled directly in the readX functions.
+		//F0 -> FF pattern commands
+		//00 -> 29 macro commands
+
+		//PAULA Interrupt override
+		virtual void interrupt();
+
+};//End of TFMX class
+} // End of namespace Audio
+
+#endif


Property changes on: scummvm/branches/gsoc2008-tfmx/sound/mods/tfmx.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native


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