Browse code

[NCSF] Apply channel modulation fix from fincs

Naram Qashat authored on 2020/07/06 20:54:59
Showing 1 changed files
... ...
@@ -509,25 +509,18 @@ void Channel::Update()
509 509
 		}
510 510
 
511 511
 		// Get the current modulation parameter
512
-		modParam = Cnv_Sine(this->modCounter >> 8) * this->modRange * this->modDepth;
512
+		modParam = Cnv_Sine(this->modCounter >> 8) * this->modRange * this->modDepth; // 7.14
513 513
 
514
-		if (!this->modType)
515
-			modParam = static_cast<int64_t>(modParam * 60) >> 14;
514
+		if (this->modType == 1)
515
+			modParam = static_cast<int64_t>(modParam * 60) >> 14; // vol: adjust range to 6dB = 60cB (no fractional bits)
516 516
 		else
517
-			// This ugly formula whose exact meaning and workings I cannot figure out is used for volume/pan modulation.
518
-			modParam = ((modParam & ~0xFC000000) >> 8) | ((((modParam < 0 ? -1 : 0) << 6) | (static_cast<uint32_t>(modParam) >> 26)) << 18);
517
+			modParam >>= 8; // tmr/pan: adjust to 7.6
519 518
 
520 519
 		// Update the modulation variables
521
-
522
-		uint16_t speed = static_cast<uint16_t>(this->modSpeed) << 6;
523
-		uint16_t counter = (this->modCounter + speed) >> 8;
524
-
525
-		while (counter >= 0x80)
526
-			counter -= 0x80;
527
-
528
-		this->modCounter += speed;
529
-		this->modCounter &= 0xFF;
530
-		this->modCounter |= counter << 8;
520
+		uint32_t counter = this->modCounter + (this->modSpeed << 6);
521
+		while (counter >= 0x8000)
522
+			counter -= 0x8000;
523
+		this->modCounter += counter;
531 524
 	}
532 525
 
533 526
 	if (bTmrNeedUpdate)