[Scummvm-cvs-logs] CVS: scummvm/backends/midi adlib.cpp,1.58,1.59 ym2612.cpp,1.24,1.25

Max Horn fingolfin at users.sourceforge.net
Mon Oct 11 15:23:04 CEST 2004


Update of /cvsroot/scummvm/scummvm/backends/midi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15562

Modified Files:
	adlib.cpp ym2612.cpp 
Log Message:
Make use of the new setupPremix variant (i.e. use an AudioStream subclass instead of a premix proc)

Index: adlib.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/adlib.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- adlib.cpp	22 Aug 2004 13:27:32 -0000	1.58
+++ adlib.cpp	11 Oct 2004 22:19:21 -0000	1.59
@@ -19,6 +19,7 @@
  */
 
 #include "stdafx.h"
+#include "sound/audiostream.h"
 #include "sound/mididrv.h"
 #include "sound/fmopl.h"
 #include "sound/mixer.h"
@@ -543,7 +544,7 @@
 //
 ////////////////////////////////////////
 
-class MidiDriver_ADLIB : public MidiDriver {
+class MidiDriver_ADLIB : public AudioStream, public MidiDriver {
 	friend class AdlibPart;
 	friend class AdlibPercussionChannel;
 
@@ -567,6 +568,20 @@
 	MidiChannel *allocateChannel();
 	MidiChannel *getPercussionChannel() { return &_percussion; } // Percussion partially supported
 
+	// AudioStream API
+	int readBuffer(int16 *buffer, const int numSamples) {
+		memset(buffer, 0, 2 * numSamples);	// FIXME
+		generate_samples(buffer, numSamples);
+		return numSamples;
+	}
+	int16 read() {
+		error("ProcInputStream::read not supported");
+	}
+	bool isStereo() const { return false; }
+	bool endOfData() const { return false; }
+	
+	int getRate() const { return _mixer->getOutputRate(); }
+
 private:
 	bool _isOpen;
 	bool _game_SmallHeader;
@@ -624,8 +639,6 @@
 	static void struct10_setup(Struct10 * s10);
 	static int random_nr(int a);
 	void mc_key_on(AdlibVoice *voice, AdlibInstrument *instr, byte note, byte velocity);
-
-	static void premix_proc(void *param, int16 *buf, uint len);
 };
 
 // MidiChannel method implementations
@@ -859,7 +872,7 @@
 
 	_samples_per_tick = (_mixer->getOutputRate() << FIXP_SHIFT) / BASE_FREQ;
 
-	_mixer->setupPremix(premix_proc, this);
+	_mixer->setupPremix(this);
 
 	return 0;
 }
@@ -875,7 +888,7 @@
 	}
 
 	// Detach the premix callback handler
-	_mixer->setupPremix(0, 0);
+	_mixer->setupPremix(0);
 
 	// Turn off the OPL emulation
 //	YM3812Shutdown();
@@ -989,10 +1002,6 @@
 
 // All the code brought over from IMuseAdlib
 
-void MidiDriver_ADLIB::premix_proc(void *param, int16 *buf, uint len) {
-	((MidiDriver_ADLIB *) param)->generate_samples(buf, len);
-}
-
 void MidiDriver_ADLIB::adlib_write(byte port, byte value) {
 	if (_adlib_reg_cache[port] == value)
 		return;
@@ -1007,9 +1016,6 @@
 void MidiDriver_ADLIB::generate_samples(int16 *data, int len) {
 	int step;
 
-	int16 *origData = data;
-	uint origLen = len;
-
 	do {
 		step = len;
 		if (step > (_next_tick >> FIXP_SHIFT))
@@ -1026,11 +1032,6 @@
 		data += step;
 		len -= step;
 	} while (len);
-
-	// Convert mono data to stereo
-	for (int i = (origLen - 1); i >= 0; i--) {
-		origData[2 * i] = origData[2 * i + 1] = origData[i];
-	}
 }
 
 void MidiDriver_ADLIB::reset_tick() {

Index: ym2612.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/ym2612.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- ym2612.cpp	6 Oct 2004 10:14:31 -0000	1.24
+++ ym2612.cpp	11 Oct 2004 22:19:22 -0000	1.25
@@ -24,6 +24,7 @@
 
 #include "stdafx.h"
 #include "common/util.h"
+#include "sound/audiostream.h"
 #include "sound/mididrv.h"
 #include "sound/mixer.h"
 
@@ -157,7 +158,7 @@
 	void sysEx_customInstrument(uint32 type, byte *instr);
 };
 
-class MidiDriver_YM2612 : public MidiDriver {
+class MidiDriver_YM2612 : public AudioStream, public MidiDriver {
 protected:
 	MidiChannel_YM2612 *_channel[16];
 
@@ -178,7 +179,6 @@
 	void rate(uint16 r);
 
 	void generate_samples(int16 *buf, int len);
-	static void premix_proc(void *param, int16 *buf, uint len);
 
 public:
 	MidiDriver_YM2612(SoundMixer *mixer);
@@ -198,6 +198,21 @@
 
 	MidiChannel *allocateChannel() { return 0; }
 	MidiChannel *getPercussionChannel() { return 0; }
+
+
+	// AudioStream API
+	int readBuffer(int16 *buffer, const int numSamples) {
+		memset(buffer, 0, 2 * numSamples);	// FIXME
+		generate_samples(buffer, numSamples / 2);
+		return numSamples;
+	}
+	int16 read() {
+		error("ProcInputStream::read not supported");
+	}
+	bool isStereo() const { return true; }
+	bool endOfData() const { return false; }
+	
+	int getRate() const { return _mixer->getOutputRate(); }
 };
 
 ////////////////////////////////////////
@@ -754,7 +769,7 @@
 int MidiDriver_YM2612::open() {
 	if (_isOpen)
 		return MERR_ALREADY_OPEN;
-	_mixer->setupPremix(premix_proc, this);
+	_mixer->setupPremix(this);
 	_isOpen = true;
 	return 0;
 }
@@ -765,7 +780,7 @@
 	_isOpen = false;
 
 	// Detach the premix callback handler
-	_mixer->setupPremix(0, 0);
+	_mixer->setupPremix(0);
 }
 
 void MidiDriver_YM2612::setTimerCallback(void *timer_param, Timer::TimerProc timer_proc) {
@@ -822,10 +837,6 @@
 	_channel[msg[1]]->sysEx_customInstrument('EUP ', &msg[2]);
 }
 
-void MidiDriver_YM2612::premix_proc(void *param, int16 *buf, uint len) {
-	((MidiDriver_YM2612 *) param)->generate_samples(buf, len);
-}
-
 void MidiDriver_YM2612::generate_samples(int16 *data, int len) {
 	int step;
 





More information about the Scummvm-git-logs mailing list