uint8 op2 = v->ins[iPC++];
//printf("wave %d, ins=%d (%d, %d)\n", wave, ins, op1, op2);
for (int i=0; i<len; i++) {
+ float pitch = detune(v->pitch, (int8) op1, 0);
float time=(v->pos+i)*invSAMPLE_RATE;
//float global_time = current_time+i*invSAMPLE_RATE;
switch (ins) {
case CONST:
{
// op1: integer part, op2: decimal part * 100
- float value = ((int8) op1) + ((int8) op2/100.0);
+ float value = ((int8) op1) + ((int8) op2/100.0f);
v->waves[wave][i] = value;
break;
}
case SINE:
{
// op1: signed coarse detune, op2: phase (0-255)
- float pitch = detune(v->pitch, (int8) op1, 0);
v->waves[wave][i] = sinf(pitch*TWOPI*time+op2*PI/255.0f);
//if (op2)
// v->waves[wave][i] = sinf(pitch*TWOPI*global_time);
case SQUARE:
{
// op1: signed coarse detune, op2: pulse width (%)
- float pitch = detune(v->pitch, (int8) op1, 0);
float pw = op2/100.0f;
float period = 1.0f/pitch;
- if (fmodf(time, period) > (period*pw))
+ if (fmodf(time, period) < (period*pw))
v->waves[wave][i] = 1.0f;
else
v->waves[wave][i] = -1.0f;
break;
}
+ case TRIANGLE:
+ {
+ float pw = op2/100.0f;
+ float period = 1.0f/pitch; // wave period (in seconds)
+ float half_period = pw*period;
+ float t = fmodf(time,period);
+ if (t < half_period)
+ v->waves[wave][i] = 2.0f*(t/half_period)-1.0f;
+ else {
+ t-=half_period;
+ v->waves[wave][i] = 1.0f-2.0f*t/(period-half_period);
+ }
+ break;
+ }
case NOISE:
v->waves[wave][i] = noise();
break;
v->waves[wave][i] = 1.0f - 1.0f/(1.0f+expf(-f*(time-d)));
break;
}
-
- /*
- case DELAY:
- {
- // op1: delay (ms), op2: volume (%)
- uint32 delay = op1*SAMPLE_RATE/1000.0f;
- float *data = (float*)(v->data[wave]+4);
- int *p = (int*)(v->data[wave]);
- v->waves[wave][i] = (op2/100.0f)*data[*p];
- // circular buffer
- data[*p] = v->waves[wave-1][i];
- *p = (*p + 1)%delay;
- break;
- }
- */
+ /*
+
+ case DELAY:
+ {
+ // op1: delay (ms), op2: volume (%)
+ uint32 delay = op1*SAMPLE_RATE/1000.0f;
+ float *data = (float*)(v->data[wave]+4);
+ int *p = (int*)(v->data[wave]);
+ v->waves[wave][i] = (op2/100.0f)*data[*p];
+ // circular buffer
+ data[*p] = v->waves[wave-1][i];
+ *p = (*p + 1)%delay;
+ break;
+ }
+ */
default:
goto end;
}
{0x05, 0x07, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 12 - bongo+bass1+piano
{0x05, 0x07, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 13 - bongo+bass1+piano
{0x05, 0x07, 0x06, 0x06, 0x06, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody5
- {0x05, 0x07, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody5
+ {0x05, 0x07, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody6
+ {0x05, 0x07, 0x06, 0x06, 0x06, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 11 - bongo+piano+bass1+melody7
}, // end patterns
{ // begin txpose
{-15, 0, 0, 0, 0}, // wind1
{24,6,7,11,16}, // bongo+bass1+piano
{24,9,7,11,14,25,}, // bongo+piano+bass1+melody5
{24,9,7,11,14,25,}, // bongo+piano+bass1+melody6
+ {24,6,7,11,16,25,}, // bongo+piano+bass1+melody6
}, // end txpose
{ // begin tracks
{{0,0,0,0,0,0,0,0,0,0,0,0}, 0},
{{0,0,0,0,0,0,0,0,0,0,0,0x6e}, 143}, // a
{{0x6b,0,0x69,0,0,0x67,0,0,0,0,0,0}, 115}, // b
{{0,0,0,0,0,0,0,0,0,0,0,0x6e}, 171}, // c
- {{0x6e,0,0,0,0,0x6c,0x6b,0,0x6c,0,0,0x6e}, 115}, // d
+ {{0x6e,0,0,0,0,0x6c,0x6b,0,0x6c,0,0,0x6e}, 171}, // d
{{0x6f,0,0,0x6e,0,0,0x6c,0,0,0x6a,0,0}, 115}, // e - melody 5
{{0x67,0,0,0x65,0,0x63,0,0,0,0,0,0}, 115}, // f - melody 6
+ {{0x6c,0,0,0x60,0,0x60,0,0,0x62,0x63,0,0}, 115}, // 10 - melody 7
}, // end tracks
{ // begin instrument data
- // 0 (bongo)
+ // 0 (bongo)
SIGMOID,10,1,
- SQUARE,0,20,
+ SINE,0,20,
LPF,2,40,
MUL,3,0,
- CONST,10,0,
+ CONST,8,0,
MUL,2,0,
ENDI,
// 19 (wind)
CONST,0,30,
CONST,0,10,
SIGMOID,10,1,
- SQUARE,0,15,
+ TRIANGLE,0,15,
SQUARE,12,10,
SQUARE,-12,20,
SUM,2,0,
ENDI,
// 93 (bass)
SIGMOID, 8,3,
- SINE,-20,20,
+ TRIANGLE,-20,1,
SINE,-8,10,
SUM,2,0,
+ LPF,4,0,
CONST,0,80,
MUL,2,0,
- MUL,6,0,
+ MUL,7,0,
ENDI,
// 115 (lead)
CONST,0,30,
// 171 (pad)
CONST,0,80,
SIGMOID, 1,14,
- SINE,-8,0,
+ TRIANGLE,-8,50,
CONST,0,5,
MUL,2,0,
MUL,4,0,
}, // end instrument data
{ // begin playlist
- 0,1,2,1,3,3,3,3,4,5,6,7,4,5,6,7,8,9,10,11,8,9,10,11,12,12,13,13,12,12,13,13,14,15,14,15,255,
+ 0,1,2,1,3,3,3,3,4,5,6,7,4,5,6,7,8,9,10,11,8,9,10,11,12,12,13,13,12,12,13,13,14,15,16,13,14,15,16,13,14,15,16,13,14,15,16,13,255,
}, // end playlist
};