#include <stdio.h>
#include <stdlib.h>
+extern float current_time;
+
float detune(float base, int coarse, int fine)
{
return base*powf(2.0f, (coarse+(fine/100.0f))/12.0f);
//printf("wave %d, ins=%d (%d, %d)\n", wave, ins, op1, op2);
for (int i=0; i<len; i++) {
float time=(v->pos+i)*invSAMPLE_RATE;
+ float global_time = current_time+i*invSAMPLE_RATE;
switch (ins) {
case CONST:
{
- float value = ((int8) op1/100.0);
+ float value = ((int8) op1/10.0);
v->waves[wave][i] = value;
break;
}
case SINE:
{
- // op1: signed coarse detune, op2: signed fine detune
- float pitch = detune(v->pitch, (int8) op1, (int8) op2);
- v->waves[wave][i] = 0.5f*sinf(pitch*TWOPI*time)+0.5f;
+ // op1: signed coarse detune, op2: use global time
+ float pitch = detune(v->pitch, (int8) op1, 0);
+ if (op2)
+ v->waves[wave][i] = sinf(pitch*TWOPI*global_time);
+ else
+ v->waves[wave][i] = sinf(pitch*TWOPI*time);
break;
}
if (fmodf(time, period) > (period*pw))
v->waves[wave][i] = 1.0f;
else
- v->waves[wave][i] = 0.0f;
+ v->waves[wave][i] = -1.0f;
break;
}
case NOISE:
- v->waves[wave][i] = rand()/(float)RAND_MAX;
+ v->waves[wave][i] = 2.0f*(rand()/(float)RAND_MAX)-1.0f;
break;
case SUM:
+ v->waves[wave][i] = v->waves[wave-op1][i]+v->waves[wave-op2][i];
+ break;
case MUL:
- {
- // op1,2: wave indices to sum/mul
- if (ins == SUM)
- v->waves[wave][i] = 0.5f*(v->waves[op1][i]+v->waves[op2][i]);
- else
- v->waves[wave][i] = v->waves[op1][i]*v->waves[op2][i];
- break;
- }
+ v->waves[wave][i] = v->waves[wave-op1][i]*v->waves[wave-op2][i];
+ break;
case LPF:
case HPF:
{
// TODO: cutoff should be a wave
// op1, op2: cutoff, resonance
- float cutoff = v->waves[op1][i];
+ float cutoff = v->waves[wave-op1][i];
float r = (op2)/5.0f;
//printf("op1=%d, op2=%d, cutoff=%f; r=%f\n", op1, op2, cutoff, r);
//printf("AFTER: input=%f, pole1=%f, pole2=%f, pole3=%f, pole4=%f\n", input, data[0], data[1], data[2], data[3]);
break;
}
+ case SIGMOID:
+ {
+ float f = (float)((int8)op1);
+ float d = ((int8)op2)/10.0f;
+ v->waves[wave][i] = 1.0f - 1.0f/(1.0f+expf(-f*(time-d)));
+ break;
+ }
+
default:
goto end;
}
Song thesong={
{ // begin patterns
- {0x01, 0x00, 0x00, 0x00},
+ {0x01, 0x02, 0x03, 0x00},
}, // end patterns
{ // begin txpose
{-12, 0, 0, 0},
}, // end txpose
{ // begin tracks
- {{45,0,0,0,43,0,0,0,41,0,0,0,40,0,0,0}, 0},
+ {{45,0,0,0,45,0,0,0,45,0,0,0,45,0,0,0}, 0},
}, // end tracks
{ // begin instrument data
- SINE,-80,0,
- SQUARE,0,50,
- LPF,0,6,
- MUL,0,2,
+ SIGMOID,15,0,
+ NOISE,0,30,
+ LPF,2,40,
END,
}, // end instrument data
{ // begin playlist