aboutsummaryrefslogtreecommitdiff
path: root/backends/midi/mt32/partial.h
blob: e3af4ad5a92ea11b95f85775421dd472bbbbadad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2004 The ScummVM project
 * Based on Tristan's conversion of Canadacow's code
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#ifndef CPARTIALMT32_H
#define CPARTIALMT32_H

#include "backends/midi/mt32/structures.h"

// Class definition of MT-32 partials.  32 in all.
class CPartialMT32 {
private:
	int useMix;
	int partNum;

	int pN;




	int16 myBuffer[2048];
	// For temporary output of paired buffer
	int16 pairBuffer[2048];

	void mixBuffers(int16 * buf1, int16 * buf2, int len);
	void mixBuffersRingMix(int16 * buf1, int16 * buf2, int len);
	void mixBuffersRing(int16 * buf1, int16 * buf2, int len);
	void mixBuffersStereo(int16 * buf1, int16 * buf2, int16 * outBuf, int len);


public:
	patchCache *tcache;
	patchCache cachebackup[4];

	//FILE *fp;
	//FILE *fp2;

	dpoly::partialStatus *partCache;

	CPartialMT32 *tibrePair;
	bool isActive;
	bool alreadyOutputed;
	int ownerChan;
	int64 age;
	int timbreNum;
	dpoly *tmppoly;

	CPartialMT32(int partialNum) {

		isActive = false;		
		pN = partialNum;

		/*
		sprintf(buffer, "partial%d.raw",pN);
		fp = fopen(buffer,"wb");

		sprintf(buffer, "partial%dx.raw",pN);
		fp2 = fopen(buffer,"wb");
		*/

		
	};
	
	void startPartial(dpoly *usePoly, patchCache *useCache, dpoly::partialStatus * usePart, CPartialMT32 * pairPart, int mixType, int num, int ownChan, int timNum) {

		//LOG_MSG("Starting partial %d for %d", num, ownChan);
		tmppoly = usePoly;
		tcache = useCache;
		partCache = usePart;
		tibrePair = pairPart;
		isActive = true;
		useMix = mixType;
		partNum = num;
		age = 0;
		ownerChan = ownChan;
		alreadyOutputed = false;
		timbreNum = timNum;
		memset(usePart->history,0,sizeof(usePart->history));

	}

	void stopPartial(void) { isActive = false; }

	
	// Returns true only if data written to buffer
	// This function (unline the one below it) returns processed stereo samples
	// made from combining this single partial with its pair, if it has one.
	bool produceOutput(int16 * partialBuf, long length);

	// This function produces mono sample output of the specific partial
	void generateSamples(int16 * partialBuf, long length);

};


#endif