new gen_tri
This commit is contained in:
parent
4d064b0dcf
commit
ecc89a5a62
58
synth.c
58
synth.c
@ -217,9 +217,10 @@ void synth_recalc(Synth*synth)
|
||||
float duty=synth->knobs[oscillator_duty[cur_osc]].value;
|
||||
bool mix=cur_osc>0&&synth->knobs[oscillator_vol[cur_osc-1]].value>0;
|
||||
if(fr==0.0)break;
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_tri(synth->channel[synth->current_channel].buffer[0],amp,fr,mix,SY_BUFFERSIZE,synth->samplerate,duty,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
for(size_t i=0;i<SY_BUFFERSIZE;i+=SY_BSIZE)
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_tri(synth->channel[synth->current_channel].buffer[0]+i,amp,fr,mix,SY_BSIZE,synth->samplerate,duty,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
}
|
||||
|
||||
// Sawtooth
|
||||
@ -232,9 +233,10 @@ void synth_recalc(Synth*synth)
|
||||
float duty=synth->knobs[oscillator_duty[cur_osc]].value;
|
||||
bool mix=cur_osc>0&&synth->knobs[oscillator_vol[cur_osc-1]].value>0;
|
||||
if(fr==0.0)break;
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_saw(synth->channel[synth->current_channel].buffer[0],amp,fr,mix,SY_BUFFERSIZE,synth->samplerate,duty,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
for(size_t i=0;i<SY_BUFFERSIZE;i+=SY_BSIZE)
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_saw(synth->channel[synth->current_channel].buffer[0]+i,amp,fr,mix,SY_BSIZE,synth->samplerate,duty,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
}
|
||||
|
||||
// Pulse
|
||||
@ -251,9 +253,10 @@ void synth_recalc(Synth*synth)
|
||||
synth->knobs[K_LFO2_FREQ].value>0)
|
||||
duty_buf=synth->lfo2_buffer;
|
||||
if(fr==0.0)break;
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_pul(synth->channel[synth->current_channel].buffer[0],amp,fr,mix,SY_BUFFERSIZE,synth->samplerate,duty,duty_buf,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
for(size_t i=0;i<SY_BUFFERSIZE;i+=SY_BSIZE)
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_pul(synth->channel[synth->current_channel].buffer[0]+i,amp,fr,mix,SY_BSIZE,synth->samplerate,duty,duty_buf,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
}
|
||||
|
||||
// Noise
|
||||
@ -264,9 +267,10 @@ void synth_recalc(Synth*synth)
|
||||
float fr=(synth->knobs[K_FREQ].value/synth->knobs[K_FREQ].maxval)*MAXFREQ;
|
||||
fr+=SEMITONE(fr,synth->knobs[K_DET].value);
|
||||
if(fr==0.0)break;
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_nse(synth->channel[synth->current_channel].buffer[0],amp,fr,mix,SY_BUFFERSIZE,synth->samplerate,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
for(size_t i=0;i<SY_BUFFERSIZE;i+=SY_BSIZE)
|
||||
synth->channel[synth->current_channel].offset=
|
||||
gen_nse(synth->channel[synth->current_channel].buffer[0]+i,amp,fr,mix,SY_BSIZE,synth->samplerate,
|
||||
synth->channel[synth->current_channel].offset);
|
||||
}
|
||||
|
||||
}
|
||||
@ -432,35 +436,15 @@ size_t gen_tri(
|
||||
)
|
||||
{
|
||||
float sig=0;
|
||||
float inc=(freq/(float)samplerate*amplitude);
|
||||
size_t cyclelen=samplerate/freq*4.0;
|
||||
size_t points[3]={0,cyclelen/4,cyclelen/4*3};
|
||||
size_t phase_offset=phase*cyclelen;
|
||||
size_t i=offset%(size_t)(cyclelen*2.0);
|
||||
|
||||
for(;i<count;++i)
|
||||
size_t i=offset%(size_t)cyclelen;
|
||||
for(size_t j=0;j<count;++j,++i)
|
||||
{
|
||||
size_t pos=i%(cyclelen*samplerate);
|
||||
|
||||
if(freq==0.0)break;
|
||||
|
||||
if((pos+phase_offset)%cyclelen==points[0])
|
||||
sig=0.0;
|
||||
else if((pos+phase_offset)%cyclelen==points[1])
|
||||
sig=amplitude;
|
||||
else if((pos+phase_offset)%cyclelen<points[1])
|
||||
sig+=inc;
|
||||
else if((pos+phase_offset)%cyclelen==points[2])
|
||||
sig=-amplitude;
|
||||
else if((pos+phase_offset)%cyclelen<points[2])
|
||||
sig-=inc;
|
||||
else
|
||||
sig+=inc;
|
||||
|
||||
if(!mix)buffer[i]=0;
|
||||
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
||||
sig=(2.0*fabs(2.0*((float)(i+phase_offset)/cyclelen-floor((float)(i+phase_offset)/(float)cyclelen+0.5)))-1)*amplitude;
|
||||
if(!mix)buffer[j]=0;
|
||||
buffer[j]=(buffer[j]+sig)/(mix?2.0:1.0);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user