Browse code

[NCSF] Applied sinc modification from kode54:

Sinc mode should not scale the window, just the sinc pulse.

Naram Qashat authored on 2014/10/27 04:15:11
Showing 2 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Channel structures
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-23
4
+ * Last modification on 2014-10-27
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -44,6 +44,7 @@ TempSndReg::TempSndReg() : CR(0), SOURCE(nullptr), TIMER(0), REPEAT_POINT(0), LE
44 44
 
45 45
 bool Channel::initializedLUTs = false;
46 46
 double Channel::sinc_lut[Channel::SINC_SAMPLES + 1];
47
+double Channel::window_lut[Channel::SINC_SAMPLES + 1];
47 48
 
48 49
 #ifndef M_PI
49 50
 static const double M_PI = 3.14159265358979323846;
... ...
@@ -65,7 +66,8 @@ Channel::Channel() : chnId(-1), tempReg(), state(CS_NONE), trackId(-1), prio(0),
65 66
 		for (unsigned i = 0; i <= SINC_SAMPLES; ++i, x += dx)
66 67
 		{
67 68
 			double y = x / SINC_WIDTH;
68
-			this->sinc_lut[i] = std::abs(x) < SINC_WIDTH ? sinc(x) * (0.40897 + 0.5 * std::cos(M_PI * y) + 0.09103 * std::cos(2 * M_PI * y)) : 0.0;
69
+			this->sinc_lut[i] = std::abs(x) < SINC_WIDTH ? sinc(x) : 0.0;
70
+			this->window_lut[i] = 0.40897 + 0.5 * std::cos(M_PI * y) + 0.09103 * std::cos(2 * M_PI * y);
69 71
 		}
70 72
 		this->initializedLUTs = true;
71 73
 	}
... ...
@@ -625,10 +627,12 @@ int32_t Channel::Interpolate()
625 627
 		int i = SINC_WIDTH, shift = static_cast<int>(std::floor(ratio * SINC_RESOLUTION));
626 628
 		int step = this->reg.sampleIncrease > 1.0 ? static_cast<int>(SINC_RESOLUTION / this->reg.sampleIncrease) : SINC_RESOLUTION;
627 629
 		int shift_adj = shift * step / SINC_RESOLUTION;
630
+		int window_step = SINC_RESOLUTION;
628 631
 		for (; i >= -static_cast<int>(SINC_WIDTH - 1); --i)
629 632
 		{
630 633
 			int pos = i * step;
631
-			kernel_sum += kernel[i + SINC_WIDTH - 1] = this->sinc_lut[std::abs(shift_adj - pos)];
634
+			int window_pos = i * window_step;
635
+			kernel_sum += kernel[i + SINC_WIDTH - 1] = this->sinc_lut[std::abs(shift_adj - pos)] * this->window_lut[std::abs(shift - window_pos)];
632 636
 		}
633 637
 		double sum = 0.0;
634 638
 		for (i = 0; i < static_cast<int>(SINC_WIDTH * 2); ++i)
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Channel structures
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-17
4
+ * Last modification on 2014-10-27
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -220,6 +220,7 @@ struct Channel
220 220
 	static const unsigned SINC_WIDTH = 8;
221 221
 	static const unsigned SINC_SAMPLES = SINC_RESOLUTION * SINC_WIDTH;
222 222
 	static double sinc_lut[SINC_SAMPLES + 1];
223
+	static double window_lut[SINC_SAMPLES + 1];
223 224
 
224 225
 	RingBuffer<SINC_WIDTH * 2> ringBuffer;
225 226