generators: return offset
This commit is contained in:
parent
c6265be5cb
commit
79efcf3bbe
34
synth.c
34
synth.c
@ -357,7 +357,7 @@ void synth_new(Synth*s)
|
||||
s->nchannels=SY_NCHANNELS;
|
||||
}
|
||||
|
||||
void gen_sin(
|
||||
size_t gen_sin(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -371,15 +371,17 @@ void gen_sin(
|
||||
float sig=0;
|
||||
size_t cyclelen=samplerate/freq*4.0;
|
||||
size_t phase_offset=phase*cyclelen;
|
||||
for(size_t i=offset;i<count;++i)
|
||||
size_t i=offset;
|
||||
for(;i<count;++i)
|
||||
{
|
||||
size_t pos=i%(cyclelen*samplerate);
|
||||
sig=sin((2.0L*M_PI)/(cyclelen)*(pos+phase_offset))*amplitude;
|
||||
buffer[pos]=(buffer[pos]+sig)/(mix?2.0:1.0);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void gen_tri(
|
||||
size_t gen_tri(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -395,8 +397,9 @@ void gen_tri(
|
||||
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;
|
||||
|
||||
for(size_t i=offset;i<count;++i)
|
||||
for(;i<count;++i)
|
||||
{
|
||||
size_t pos=i%(cyclelen*samplerate);
|
||||
|
||||
@ -417,9 +420,11 @@ void gen_tri(
|
||||
|
||||
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void gen_saw(
|
||||
size_t gen_saw(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -435,8 +440,9 @@ void gen_saw(
|
||||
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;
|
||||
|
||||
for(size_t i=offset;i<count;++i)
|
||||
for(;i<count;++i)
|
||||
{
|
||||
size_t pos=i%(cyclelen*samplerate);
|
||||
|
||||
@ -457,9 +463,11 @@ void gen_saw(
|
||||
|
||||
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void gen_pul(
|
||||
size_t gen_pul(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -472,7 +480,8 @@ void gen_pul(
|
||||
)
|
||||
{
|
||||
float sig=0;
|
||||
for(size_t i=offset;i<count;++i)
|
||||
size_t i=offset;
|
||||
for(;i<count;++i)
|
||||
{
|
||||
size_t cyclelen=samplerate/freq*4.0;
|
||||
size_t pos=i%(cyclelen*samplerate);
|
||||
@ -499,9 +508,11 @@ void gen_pul(
|
||||
|
||||
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void gen_nse(
|
||||
size_t gen_nse(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -512,11 +523,14 @@ void gen_nse(
|
||||
)
|
||||
{
|
||||
float sig=0;
|
||||
size_t i=offset;
|
||||
samplerate=samplerate; // Inhibit unused variable warning
|
||||
freq=freq; // Inhibit unused variable warning
|
||||
for(size_t i=offset;i<count;++i)
|
||||
for(;i<count;++i)
|
||||
{
|
||||
sig=(fmod(frand(),1.0)-fmod(frand(),1.0))*amplitude;
|
||||
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
10
synth.h
10
synth.h
@ -54,7 +54,7 @@ typedef struct Note
|
||||
void synth_recalc(Synth*synth);
|
||||
void synth_new(Synth*s);
|
||||
|
||||
void gen_sin(
|
||||
size_t gen_sin(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -65,7 +65,7 @@ void gen_sin(
|
||||
size_t offset
|
||||
);
|
||||
|
||||
void gen_tri(
|
||||
size_t gen_tri(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -76,7 +76,7 @@ void gen_tri(
|
||||
size_t offset
|
||||
);
|
||||
|
||||
void gen_saw(
|
||||
size_t gen_saw(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -87,7 +87,7 @@ void gen_saw(
|
||||
size_t offset
|
||||
);
|
||||
|
||||
void gen_pul(
|
||||
size_t gen_pul(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
@ -99,7 +99,7 @@ void gen_pul(
|
||||
size_t offset
|
||||
);
|
||||
|
||||
void gen_nse(
|
||||
size_t gen_nse(
|
||||
float*buffer,
|
||||
float amplitude,
|
||||
float freq,
|
||||
|
Loading…
Reference in New Issue
Block a user