5
5
6
6
#include < cstdio>
7
7
8
- #if defined(_MSC_VER)
9
- #if defined(_DEBUG)
10
- #define new new (_NORMAL_BLOCK, __FILE__, __LINE__)
11
- #endif
12
- #endif
13
-
14
8
using namespace dsa ;
15
9
using namespace dsa ::C;
16
10
@@ -87,7 +81,11 @@ COpllDevice::COpllDevice(uint32_t rate, uint32_t nch)
87
81
m_nch = 1 ;
88
82
89
83
for (uint32_t i = 0 ; i < m_nch; i++)
84
+ {
90
85
m_opll[i] = OPLL_new (3579545 , rate);
86
+ memset (m_reg_cache[i],0 ,128 );
87
+ m_rbuf[i].clear ();
88
+ }
91
89
Reset ();
92
90
}
93
91
@@ -344,25 +342,27 @@ void COpllDevice::PercSetVelocity(uint8_t note, uint8_t velo)
344
342
{
345
343
note = perc_table[note];
346
344
if (0 < note)
345
+ {
347
346
m_pi.velocity [note - 1 ] = velo;
348
- _PercUpdateVolume (note);
347
+ _PercUpdateVolume (note);
348
+ }
349
349
}
350
350
351
351
void COpllDevice::_PercUpdateVolume (uint8_t note)
352
352
{
353
353
354
- if (note > 5 )
354
+ if (note < 1 || note > 5 )
355
355
return ;
356
356
357
- int vol = 13 - m_pi.volume / 16 - m_pi.velocity [note] / 16 ;
357
+ int vol = 13 - m_pi.volume / 16 - m_pi.velocity [note- 1 ] / 16 ;
358
358
if (vol < 0 )
359
- m_pi.vcache [note] = 0 ;
359
+ m_pi.vcache [note- 1 ] = 0 ;
360
360
else if (15 < vol)
361
- m_pi.vcache [note] = 15 ;
361
+ m_pi.vcache [note- 1 ] = 15 ;
362
362
else
363
- m_pi.vcache [note] = vol;
363
+ m_pi.vcache [note- 1 ] = vol;
364
364
365
- switch (note)
365
+ switch (note- 1 )
366
366
{
367
367
case 4 : // B.D
368
368
_WriteReg (0x30 + 6 , m_pi.vcache [4 ]);
@@ -389,7 +389,7 @@ void COpllDevice::PercSetProgram(uint8_t bank, uint8_t prog)
389
389
void COpllDevice::PercSetVolume (uint8_t vol)
390
390
{
391
391
m_pi.volume = vol;
392
- for (int i = 0 ; i < 5 ; i++)
392
+ for (int i = 1 ; i < 6 ; i++)
393
393
_PercUpdateVolume (i);
394
394
}
395
395
0 commit comments