ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
sound.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) by Fred Klaus *
3  * development@fkweb.de *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef CPC_SOUND_H
21 #define CPC_SOUND_H
22 
23 #include "psg.h"
24 #include "config.h"
25 #include "types.h"
26 
27 namespace cpcx
28 {
29 
31  class Sound final
32  {
33 
34  public:
35  Sound(Psg* psg=0);
37 
38  typedef void (Sound::*Synthesizer)(void);
39  typedef void (Sound::*CaseEnvType)(void);
40 
41  void init(Psg* psg=0);
42 
43  void setSynthesizer(Synthesizer syn) {mSynthesizer=syn;}
44  Synthesizer synthesizer() {return mSynthesizer;}
45 
46  inline void setMixerRegister(tUBYTE value);
47  inline void setAmplA(tUBYTE value);
48  inline void setAmplB(tUBYTE value);
49  inline void setAmplC(tUBYTE value);
50  void caseEnvType0_3__9();
51  void caseEnvType4_7__15();
52  void caseEnvType8();
53  void caseEnvType10();
54  void caseEnvType11();
55  void caseEnvType12();
56  void caseEnvType13();
57  void caseEnvType14();
58  inline void setEnvelopeRegister(tUBYTE value);
59  inline void setAYRegister(int num, tUBYTE value);
60  inline void synthesizerLogicQ();
61  inline void synthesizerMixerQ();
62  void synthesizerStereo16();
63  void synthesizerStereo8();
64  void synthesizerMixerQMono();
65  void synthesizerMono16();
66  void synthesizerMono8();
67  void calculateLevelTables();
68  void resetAYChipEmulation();
69  void initAYCounterVars();
70  void initAY();
71 
72  tUBYTE* buffer() const {return mSndBuffer;}
73  tUBYTE* bufferEnd() const {return mSndBufferEnd;}
74  tUBYTE* stream() const {return mSndStream;}
75 
76  void setBuffer (tUBYTE* ptr) {mSndBuffer=ptr;}
77  void setBufferEnd(tUBYTE* ptr) {mSndBufferEnd=ptr;}
78  void setStream (tUBYTE* ptr) {mSndStream=ptr;}
79 
80  tDWORD freqTable(int num) const {return mFreqTable[num];}
81 
82  void setEnabled(bool value) {mSndEnabled=value;}
83  void setPlaybackRate(uint value) {mSndPlaybackRate=value;}
84  void setBits(uint value) {mSndBits=value;}
85  void setStereo(uint value) {mSndStereo=value;}
86  void setVolume(uint value) {mSndVolume=value;}
87  void setDevice(uint value) {mSndDevice=value;}
88  void setBufferSize(uint value) {mSndBufferSize=value;}
89  void setBufferPtr(tUBYTE* ptr) {mSndBufferPtr=ptr;}
91  void setBufferPtrW(tWORD ptr) {*(tWORD*)mSndBufferPtr=ptr;}
93 
94  void setBufferFull(bool bf) {mBufferFull=bf;}
95  bool bufferFull() const {return mBufferFull;}
96 
97  bool enabled() const {return mSndEnabled;}
99  uint bits() const {return mSndBits;}
100  uint stereo() const {return mSndStereo;}
101  uint volume() const {return mSndVolume;}
102  uint device() const {return mSndDevice;}
103  uint bufferSize() const {return mSndBufferSize;}
104  tUBYTE* bufferPtr() const {return mSndBufferPtr;}
105 
106 
107  const tINT64 & cycleCountInitBoth() const {return mCycleCountInit.both;}
108  uint cycleCountInitLow() const {return mCycleCountInit.s.low;}
109  uint cycleCountInitHigh() const {return mCycleCountInit.s.high;}
110 
111  const tINT64 & cycleCountBoth() const {return mCycleCount.both;}
112  uint cycleCountLow() const {return mCycleCount.s.low;}
113  uint cycleCountHigh() const {return mCycleCount.s.high;}
114 
115  void setCycleCountInitBoth(const tINT64 & value) {mCycleCountInit.both=value;}
116  void setCycleCountBoth(const tINT64 & value) {mCycleCount.both=value;}
117  void setCycleCountLow (uint value) {mCycleCount.s.low =value;}
118  void setCycleCountHigh(uint value) {mCycleCount.s.high=value;}
119 
120  private:
122 
123  Synthesizer mSynthesizer;
124 
133  // **############################***********
134  // **############################***********
135  // TODO change and init this !!!!!
136  // **############################***********
141  // **############################***********
142  // **############################***********
143  // **############################***********
144 
146 
147  union
148  {
149  struct S
150  {
153  } s;
155  } mCycleCount;
156 
157  union
158  {
159  struct S
160  {
161  uint low;
162  uint high;
163  } s;
164  tINT64 both;
165  } mCycleCountInit;
166 
167  //tDWORD mLoopCount[2];
169 
171 
172  union LoopCount
173  {
174  struct S
175  {
176  tDWORD low;
177  tDWORD high;
178  } s;
179  tINT64 both;
180  } mLoopCount;
181 
182  union TCounter
183  {
184  struct S
185  {
186  tWORD low;
187  tWORD high;
188  } s;
189  tDWORD both;
190  };
192 
193  union
194  {
195  struct S
196  {
199  } s;
201  } mNoise;
202 
203  union
204  {
205  struct S
206  {
209  } s;
210  tINT64 both;
212 
214 
215  int mLevelPP[256];
216 
217  static const tUWORD mAmplitudesAY[16];
218  static const tDWORD mFreqTable[5];
219 
220  bool mTonEnA;
221  bool mTonEnB;
222  bool mTonEnC;
223  bool mNoiseEnA;
224  bool mNoiseEnB;
225  bool mNoiseEnC;
229 
233 
234  int mLevelAR[32];
235  int mLevelAL[32];
236  int mLevelBR[32];
237  int mLevelBL[32];
238  int mLevelCR[32];
239  int mLevelCL[32];
240 
248 
249  int mPreAmp;
253 
254  };
255 
256 
257  inline void Sound::setAYRegister(int num, tUBYTE value)
258  {
259  switch(num)
260  {
261  case 13:
262  setEnvelopeRegister(value & 15);
263  break;
264  case 1:
265  case 3:
266  case 5:
267  mPsg->setRegisterAY(num, value & 15);
268  break;
269  case 6:
270  mPsg->setNoise(value & 31);
271  break;
272  case 7:
273  setMixerRegister(value & 63);
274  break;
275  case 8:
276  setAmplA(value & 31);
277  break;
278  case 9:
279  setAmplB(value & 31);
280  break;
281  case 10:
282  setAmplC(value & 31);
283  break;
284  case 0:
285  case 2:
286  case 4:
287  case 11:
288  case 12:
289  mPsg->setRegisterAY(num, value);
290  break;
291  }
292  }
293 
295  {
296  mEnvelopeCounter.s.high = 0;
297  mPsg->setFirstPeriod(true);
298  if (!(value & 4))
299  {
300  mPsg->setAmplitudeEnv(32);
301  }
302  else
303  {
304  mPsg->setAmplitudeEnv(-1);
305  }
306  mPsg->setEnvType(value);
307  switch (value)
308  {
309  case 0:
310  case 1:
311  case 2:
312  case 3:
313  case 9:
315  break;
316  case 4:
317  case 5:
318  case 6:
319  case 7:
320  case 15:
322  break;
323  case 8:
325  break;
326  case 10:
328  break;
329  case 11:
331  break;
332  case 12:
334  break;
335  case 13:
337  break;
338  case 14:
340  break;
341  }
342  }
343 
344  inline void Sound::setMixerRegister(tUBYTE value)
345  {
346  mPsg->setMixer(value);
347  mTonEnA = value & 1 ? false : true;
348  mNoiseEnA = value & 8 ? false : true;
349  mTonEnB = value & 2 ? false : true;
350  mNoiseEnB = value & 16 ? false : true;
351  mTonEnC = value & 4 ? false : true;
352  mNoiseEnC = value & 32 ? false : true;
353  }
354 
355 
356 
357  inline void Sound::setAmplA(tUBYTE value)
358  {
359  mPsg->setAmplitudeA(value);
360  mEnvelopeEnA = value & 16 ? false : true;
361  }
362 
363 
364 
365  inline void Sound::setAmplB(tUBYTE value)
366  {
367  mPsg->setAmplitudeB(value);
368  mEnvelopeEnB = value & 16 ? false : true;
369  }
370 
371 
372 
373  inline void Sound::setAmplC(tUBYTE value)
374  {
375  mPsg->setAmplitudeC(value);
376  mEnvelopeEnC = value & 16 ? false : true;
377  }
378 
379 } // namespace cpcx
380 
381 #endif // CPC_SOUND_H
int mLevelBR[32]
Definition: sound.h:236
TCounter mTonCounterB
Definition: sound.h:191
tUBYTE * mSndBufferEnd
Definition: sound.h:138
tUBYTE mTonB
Definition: sound.h:231
uint stereo() const
Definition: sound.h:100
bool mEnvelopeEnC
Definition: sound.h:228
void synthesizerStereo8()
Definition: sound.cpp:481
TCounter mTonCounterA
Definition: sound.h:191
tUBYTE * mSndStream
Definition: sound.h:139
bool mNoiseEnA
Definition: sound.h:223
union cpcx::Sound::@3 mEnvelopeCounter
void initAYCounterVars()
Definition: sound.cpp:762
tUBYTE mIndexCR
Definition: sound.h:247
void caseEnvType11()
Definition: sound.cpp:156
Definition: psg.h:32
void setCycleCountHigh(uint value)
Definition: sound.h:118
void setStream(tUBYTE *ptr)
Definition: sound.h:78
void synthesizerLogicQ()
Definition: sound.cpp:298
int mLevelTape
Definition: sound.h:241
uint cycleCountInitHigh() const
Definition: sound.h:109
void synthesizerMono16()
Definition: sound.cpp:612
tUBYTE mIndexBL
Definition: sound.h:244
void synthesizerMixerQ()
Definition: sound.cpp:339
TCounter mTonCounterC
Definition: sound.h:191
union cpcx::Sound::LoopCount mLoopCount
void setAmplitudeB(tUBYTE value)
Definition: psg.h:87
void setBufferPtrU(tUBYTE ptr)
Definition: sound.h:92
Namespace for all CPC components.
Definition: colours.cpp:22
uint mSndDevice
Definition: sound.h:130
uint mSndStereo
Definition: sound.h:128
tINT64 * mLoopCount64
Definition: sound.h:168
uint mSndBits
Definition: sound.h:127
tUBYTE mIndexAL
Definition: sound.h:242
const tINT64 & cycleCountInitBoth() const
Definition: sound.h:107
void setVolume(uint value)
Definition: sound.h:86
tINT64 mLoopCountInit
Definition: sound.h:170
void setAYRegister(int num, tUBYTE value)
Definition: sound.h:257
uint playbackRate() const
Definition: sound.h:98
uint device() const
Definition: sound.h:102
bool mTonEnA
Definition: sound.h:220
void synthesizerStereo16()
Definition: sound.cpp:455
union cpcx::Sound::@2 mNoise
The sound chip of the CPC.
Definition: sound.h:31
int64_t tINT64
Definition: types.h:64
void setCycleCountBoth(const tINT64 &value)
Definition: sound.h:116
void setFirstPeriod(bool value)
Definition: psg.h:96
Synthesizer mSynthesizer
Definition: sound.h:123
void setMixerRegister(tUBYTE value)
Definition: sound.h:344
bool bufferFull() const
Definition: sound.h:95
int mPreAmpMax
Definition: sound.h:250
bool mNoiseEnC
Definition: sound.h:225
int mLevelPP[256]
Definition: sound.h:215
void initAY()
Definition: sound.cpp:774
tUBYTE * mSndBuffer
Definition: sound.h:137
void synthesizerMixerQMono()
Definition: sound.cpp:506
static const tDWORD mFreqTable[5]
Definition: sound.h:218
void setBits(uint value)
Definition: sound.h:84
uint cycleCountLow() const
Definition: sound.h:112
void caseEnvType10()
Definition: sound.cpp:134
void setAmplitudeC(tUBYTE value)
Definition: psg.h:88
tDWORD seed
Definition: sound.h:200
bool mTonEnB
Definition: sound.h:221
void setBufferFull(bool bf)
Definition: sound.h:94
void init(Psg *psg=0)
Definition: sound.cpp:42
int mLeftChan
Definition: sound.h:251
bool mTonEnC
Definition: sound.h:222
void setRegisterAY(int num, tUBYTE val)
Definition: psg.h:76
void caseEnvType4_7__15()
Definition: sound.cpp:116
void caseEnvType8()
Definition: sound.cpp:129
tWORD val
Definition: sound.h:198
tUBYTE mTonA
Definition: sound.h:230
uint cycleCountHigh() const
Definition: sound.h:113
void setNoise(tUBYTE value)
Definition: psg.h:84
bool mSndEnabled
Definition: sound.h:125
bool mEnvelopeEnA
Definition: sound.h:226
tDWORD high
Definition: sound.h:208
void setBufferSize(uint value)
Definition: sound.h:88
int mLevelAR[32]
Definition: sound.h:234
uint mSndBufferSize
Definition: sound.h:131
int mLevelCR[32]
Definition: sound.h:238
void setAmplitudeA(tUBYTE value)
Definition: psg.h:86
tUBYTE * bufferPtr() const
Definition: sound.h:104
static const tUWORD mAmplitudesAY[16]
Definition: sound.h:217
void setCycleCountInitBoth(const tINT64 &value)
Definition: sound.h:115
void setAmplA(tUBYTE value)
Definition: sound.h:357
void setCycleCountLow(uint value)
Definition: sound.h:117
Sound(Psg *psg=0)
Definition: sound.cpp:37
tUBYTE mIndexBR
Definition: sound.h:245
Psg * mPsg
Definition: sound.h:121
bool mBufferFull
Definition: sound.h:145
int mPreAmp
Definition: sound.h:249
uint mSndVolume
Definition: sound.h:129
void setBufferEnd(tUBYTE *ptr)
Definition: sound.h:77
int mLevelBL[32]
Definition: sound.h:237
tUBYTE * stream() const
Definition: sound.h:74
void setPlaybackRate(uint value)
Definition: sound.h:83
tDWORD freqTable(int num) const
Definition: sound.h:80
tUBYTE mTapeLevel
Definition: sound.h:140
void setEnvType(tUBYTE value)
Definition: psg.h:91
int mLevelCL[32]
Definition: sound.h:239
void setBufferPtrDW(tDWORD ptr)
Definition: sound.h:90
uint high
Definition: sound.h:152
tUBYTE * mSndBufferPtr
Definition: sound.h:132
tUBYTE * bufferEnd() const
Definition: sound.h:73
#define ROLAND_DEFAULT
Definition: compspec.h:46
tWORD low
Definition: sound.h:197
uint8_t tUBYTE
Definition: types.h:74
unsigned int uint
Definition: types.h:121
void setAmplC(tUBYTE value)
Definition: sound.h:373
tUBYTE mIndexAR
Definition: sound.h:243
uint bufferSize() const
Definition: sound.h:103
void setStereo(uint value)
Definition: sound.h:85
uint low
Definition: sound.h:151
void synthesizerMono8()
Definition: sound.cpp:634
int mRightChan
Definition: sound.h:252
void setAmplitudeEnv(int value)
Definition: psg.h:95
void setEnvelopeRegister(tUBYTE value)
Definition: sound.h:294
tDWORD low
Definition: sound.h:207
void caseEnvType14()
Definition: sound.cpp:187
void resetAYChipEmulation()
Definition: sound.cpp:747
uint bits() const
Definition: sound.h:99
bool enabled() const
Definition: sound.h:97
void caseEnvType12()
Definition: sound.cpp:169
void caseEnvType0_3__9()
Definition: sound.cpp:104
const tINT64 & cycleCountBoth() const
Definition: sound.h:111
uint volume() const
Definition: sound.h:101
void caseEnvType13()
Definition: sound.cpp:174
uint16_t tUWORD
Definition: types.h:80
int16_t tWORD
Definition: types.h:46
tINT64 both
Definition: sound.h:154
Synthesizer synthesizer()
Definition: sound.h:44
tUBYTE mIndexCL
Definition: sound.h:246
tUBYTE * buffer() const
Definition: sound.h:72
tUBYTE mTonC
Definition: sound.h:232
CaseEnvType mCaseEnvType
Definition: sound.h:213
uint cycleCountInitLow() const
Definition: sound.h:108
bool mEnvelopeEnB
Definition: sound.h:227
void setMixer(tUBYTE value)
Definition: psg.h:85
struct cpcx::Sound::@0::S s
void setSynthesizer(Synthesizer syn)
Definition: sound.h:43
uint mSndPlaybackRate
Definition: sound.h:126
void calculateLevelTables()
Definition: sound.cpp:657
bool mNoiseEnB
Definition: sound.h:224
void setBufferPtrW(tWORD ptr)
Definition: sound.h:91
~Sound() ROLAND_DEFAULT typedef void(Sound typedef void(Sound::* CaseEnvType)(void)
Definition: sound.h:39
void setBufferPtr(tUBYTE *ptr)
Definition: sound.h:89
void setBuffer(tUBYTE *ptr)
Definition: sound.h:76
int32_t tDWORD
Definition: types.h:52
union cpcx::Sound::@1 mCycleCountInit
void setAmplB(tUBYTE value)
Definition: sound.h:365
TCounter mNoiseCounter
Definition: sound.h:191
void setDevice(uint value)
Definition: sound.h:87
union cpcx::Sound::@0 mCycleCount
int mLevelAL[32]
Definition: sound.h:235
void setEnabled(bool value)
Definition: sound.h:82