summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/sidvoice.h
blob: c2cb00a52258a7853f19596bb98368c8dbebcf23 (plain) (blame)
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
116
117
118
119
120
121
// license:BSD-3-Clause
// copyright-holders:Peter Trauner
#ifndef MAME_SOUND_SIDVOICE_H
#define MAME_SOUND_SIDVOICE_H

#pragma once


/*
  approximation of the sid6581 chip
  this part is for 1 (of the 3) voices of a chip
*/
struct SID6581_t;

struct sidOperator
{
	struct sw_storage
	{
		uint16_t len;
#if defined(DIRECT_FIXPOINT)
		uint32_t stp;
#else
		uint32_t pnt;
		int16_t stp;
#endif
	};

	SID6581_t *sid;
	uint8_t reg[7];
	uint32_t SIDfreq;
	uint16_t SIDpulseWidth;
	uint8_t SIDctrl;
	uint8_t SIDAD, SIDSR;

	sidOperator* carrier;
	sidOperator* modulator;
	int sync;

	uint16_t pulseIndex, newPulseIndex;
	uint16_t curSIDfreq;
	uint16_t curNoiseFreq;

	uint8_t output;//, outputMask;

	char filtVoiceMask;
	int filtEnabled;
	float filtLow, filtRef;
	int8_t filtIO;

	int32_t cycleLenCount;
#if defined(DIRECT_FIXPOINT)
	cpuLword cycleLen, cycleAddLen;
#else
	uint32_t cycleAddLenPnt;
	uint16_t cycleLen, cycleLenPnt;
#endif

	int8_t (*outProc)(sidOperator *);
	void (*waveProc)(sidOperator *);

#if defined(DIRECT_FIXPOINT)
	cpuLword waveStep, waveStepAdd;
#else
	uint16_t waveStep, waveStepAdd;
	uint32_t waveStepPnt, waveStepAddPnt;
#endif
	uint16_t waveStepOld;
	sw_storage wavePre[2];

#if defined(DIRECT_FIXPOINT) && defined(LARGE_NOISE_TABLE)
	cpuLword noiseReg;
#elif defined(DIRECT_FIXPOINT)
	cpuLBword noiseReg;
#else
	uint32_t noiseReg;
#endif
	uint32_t noiseStep, noiseStepAdd;
	uint8_t noiseOutput;
	int noiseIsLocked;

	uint8_t ADSRctrl;
//  int gateOnCtrl, gateOffCtrl;
	uint16_t (*ADSRproc)(sidOperator *);

#ifdef SID_FPUENVE
	float fenveStep, fenveStepAdd;
	uint32_t enveStep;
#elif defined(DIRECT_FIXPOINT)
	cpuLword enveStep, enveStepAdd;
#else
	uint16_t enveStep, enveStepAdd;
	uint32_t enveStepPnt, enveStepAddPnt;
#endif
	uint8_t enveVol, enveSusVol;
	uint16_t enveShortAttackCount;

	void clear();

	void set();
	void set2();
	static int8_t wave_calc_normal(sidOperator *pVoice);

private:
	void wave_calc_cycle_len();
};

typedef int8_t (*ptr2sidFunc)(sidOperator *);
typedef uint16_t (*ptr2sidUwordFunc)(sidOperator *);
typedef void (*ptr2sidVoidFunc)(sidOperator *);

void sidInitWaveformTables(int type);
void sidInitMixerEngine(running_machine &machine);

#if 0
extern ptr2sidVoidFunc sid6581ModeNormalTable[16];
extern ptr2sidVoidFunc sid6581ModeRingTable[16];
extern ptr2sidVoidFunc sid8580ModeNormalTable[16];
extern ptr2sidVoidFunc sid8580ModeRingTable[16];
#endif

#endif // MAME_SOUND_SIDVOICE_H