fix duty cycle offset
This commit is contained in:
parent
20ae092592
commit
5ee050e0c4
1
TODO
1
TODO
@ -2,3 +2,4 @@ LFO
|
|||||||
Pitch envelope
|
Pitch envelope
|
||||||
Filter envelope
|
Filter envelope
|
||||||
Polyphony
|
Polyphony
|
||||||
|
Sequencer
|
||||||
|
BIN
data/bg.png
BIN
data/bg.png
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 15 KiB |
53
knob.h
53
knob.h
@ -4,38 +4,29 @@
|
|||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
|
|
||||||
#define K_AMP 0
|
// Knob indexes
|
||||||
#define K_FREQ 1
|
enum
|
||||||
#define K_OSC1_VOL 2
|
{
|
||||||
#define K_OSC1_WAVEF 3
|
K_AMP, K_FREQ, K_DET, K_LIM,
|
||||||
#define K_OSC1_PHASE 4
|
K_AENV_ATK, K_AENV_REL,
|
||||||
#define K_OSC1_DET 22
|
K_OSC1_VOL, K_OSC1_WAVEF, K_OSC1_PHASE, K_OSC1_DET,
|
||||||
#define K_OSC2_VOL 5
|
K_OSC2_VOL, K_OSC2_WAVEF, K_OSC2_PHASE, K_OSC2_DET,
|
||||||
#define K_OSC2_WAVEF 6
|
K_OSC3_VOL, K_OSC3_WAVEF, K_OSC3_PHASE, K_OSC3_DET,
|
||||||
#define K_OSC2_PHASE 7
|
K_OSC4_VOL, K_OSC4_WAVEF, K_OSC4_PHASE, K_OSC4_DET,
|
||||||
#define K_OSC2_DET 23
|
K_HP, K_LP,
|
||||||
#define K_OSC3_VOL 8
|
K_FENV_ATK, K_FENV_REL,
|
||||||
#define K_OSC3_WAVEF 9
|
K_LFO1_VOL,
|
||||||
#define K_OSC3_PHASE 10
|
};
|
||||||
#define K_OSC3_DET 24
|
|
||||||
#define K_OSC4_VOL 11
|
|
||||||
#define K_OSC4_WAVEF 12
|
|
||||||
#define K_OSC4_PHASE 13
|
|
||||||
#define K_OSC4_DET 25
|
|
||||||
#define K_HP 14
|
|
||||||
#define K_LP 15
|
|
||||||
#define K_AENV_ATK 16
|
|
||||||
#define K_AENV_REL 17
|
|
||||||
#define K_FENV_ATK 18
|
|
||||||
#define K_FENV_REL 19
|
|
||||||
#define K_DET 20
|
|
||||||
#define K_LIM 21
|
|
||||||
|
|
||||||
#define K_FMT_PERC 0 // Percent
|
// Knob value display formats
|
||||||
#define K_FMT_FLOAT 1
|
enum
|
||||||
#define K_FMT_WAV 2
|
{
|
||||||
#define K_FMT_FREQ 3
|
K_FMT_PERC,
|
||||||
#define K_FMT_HEX 4
|
K_FMT_FLOAT,
|
||||||
|
K_FMT_WAV,
|
||||||
|
K_FMT_FREQ,
|
||||||
|
K_FMT_HEX,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct Knob
|
typedef struct Knob
|
||||||
{
|
{
|
||||||
|
51
main.c
51
main.c
@ -107,48 +107,50 @@ int main(void)
|
|||||||
|
|
||||||
// Create knobs
|
// Create knobs
|
||||||
{
|
{
|
||||||
uint32_t x=0+12;
|
const uint32_t cell_w=153,cell_h=75;
|
||||||
uint32_t y=164;
|
const uint32_t cell_padx=16,cell_pady=18;
|
||||||
|
uint32_t x=0+cell_padx;
|
||||||
|
uint32_t y=cell_h+cell_pady;
|
||||||
#define knob_space 32
|
#define knob_space 32
|
||||||
create_knob(knobs+K_OSC1_VOL,"",x,y);++total_knobs;
|
create_knob(knobs+K_OSC1_VOL,"",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC1_WAVEF,"",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC1_WAVEF,"",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC1_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC1_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC1_DET,"Fine",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC1_DET,"Fine",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=152+12;
|
x=cell_w+cell_padx;
|
||||||
create_knob(knobs+K_OSC2_VOL,"",x,y);++total_knobs;
|
create_knob(knobs+K_OSC2_VOL,"",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC2_WAVEF,"",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC2_WAVEF,"",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC2_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC2_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC2_DET,"Fine",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC2_DET,"Fine",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=152*2+12;
|
x=cell_w*2+cell_padx;
|
||||||
create_knob(knobs+K_OSC3_VOL,"",x,y);++total_knobs;
|
create_knob(knobs+K_OSC3_VOL,"",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC3_WAVEF,"",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC3_WAVEF,"",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC3_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC3_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC3_DET,"Fine",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC3_DET,"Fine",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=152*3+12;
|
x=cell_w*3+cell_padx;
|
||||||
create_knob(knobs+K_OSC4_VOL,"",x,y);++total_knobs;
|
create_knob(knobs+K_OSC4_VOL,"",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC4_WAVEF,"",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC4_WAVEF,"",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC4_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC4_PHASE,"Phs",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_OSC4_DET,"Fine",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_OSC4_DET,"Fine",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=0+12;
|
x=0+cell_padx;
|
||||||
y=148+90;
|
y+=75;
|
||||||
create_knob(knobs+K_AMP,"Amp",x,y);++total_knobs;
|
create_knob(knobs+K_AMP,"Amp",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_LIM,"Lim",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_LIM,"Lim",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_DET,"Fine",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_DET,"Fine",x+=knob_space,y);++total_knobs;
|
||||||
create_knob(knobs+K_FREQ,"",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_FREQ,"",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=152*1+12;
|
x=cell_w*1+cell_padx;
|
||||||
create_knob(knobs+K_AENV_ATK,"A",x,y);++total_knobs;
|
create_knob(knobs+K_AENV_ATK,"A",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_AENV_REL,"R",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_AENV_REL,"R",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=152*2+12;
|
x=cell_w*2+cell_padx;
|
||||||
create_knob(knobs+K_LP,"LP",x,y);++total_knobs;
|
create_knob(knobs+K_LP,"LP",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_HP,"HP",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_HP,"HP",x+=knob_space,y);++total_knobs;
|
||||||
|
|
||||||
x=152*3+12;
|
x=cell_w*3+cell_padx;
|
||||||
create_knob(knobs+K_FENV_ATK,"A",x,y);++total_knobs;
|
create_knob(knobs+K_FENV_ATK,"A",x,y);++total_knobs;
|
||||||
create_knob(knobs+K_FENV_REL,"R",x+=knob_space,y);++total_knobs;
|
create_knob(knobs+K_FENV_REL,"R",x+=knob_space,y);++total_knobs;
|
||||||
#undef knob_space
|
#undef knob_space
|
||||||
@ -604,21 +606,24 @@ int main(void)
|
|||||||
render_image(r,tex_bg,0,0,640,480);
|
render_image(r,tex_bg,0,0,640,480);
|
||||||
|
|
||||||
// Draw waveform
|
// Draw waveform
|
||||||
SDL_SetRenderDrawColor(r,86,86,86,86);
|
|
||||||
SDL_RenderDrawLine(r,0,70,640,70);
|
|
||||||
SDL_SetRenderDrawColor(r,255,0,0,0);
|
|
||||||
for(size_t i=1;i<SONGSIZE;++i)
|
|
||||||
{
|
{
|
||||||
float y1=MIN(synth.channel[0][i-1],1.0);
|
const uint32_t wf_x=0,wf_y=0,wf_w=153,wf_h=75;
|
||||||
float y2=MIN(synth.channel[0][i],1.0);
|
SDL_SetRenderDrawColor(r,86,86,86,86);
|
||||||
SDL_RenderDrawLine(r,
|
SDL_RenderDrawLine(r,wf_x,wf_y+wf_h/2,wf_w,wf_h/2);
|
||||||
((float)i-1)/SONGSIZE*640,MIN(70-y1*70,140),
|
SDL_SetRenderDrawColor(r,255,0,0,0);
|
||||||
((float)i)/SONGSIZE*640,MIN(70-y2*70,140)
|
for(size_t i=1;i<SONGSIZE;++i)
|
||||||
);
|
{
|
||||||
|
float y1=MIN(synth.channel[0][i-1],1.0);
|
||||||
|
float y2=MIN(synth.channel[0][i],1.0);
|
||||||
|
SDL_RenderDrawLine(r,
|
||||||
|
wf_x+((float)i-1)/SONGSIZE*wf_w,wf_y+MIN(wf_h/2-y1*wf_h,wf_h),
|
||||||
|
wf_x+((float)i)/SONGSIZE*wf_w,wf_y+MIN(wf_h/2-y2*wf_h,wf_h)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/* SDL_SetRenderDrawColor(r,255,255,255,255); */
|
||||||
|
/* SDL_RenderDrawLine(r,0,0,640,0); */
|
||||||
|
/* SDL_RenderDrawLine(r,0,80*2,640,80*2); */
|
||||||
}
|
}
|
||||||
/* SDL_SetRenderDrawColor(r,255,255,255,255); */
|
|
||||||
/* SDL_RenderDrawLine(r,0,0,640,0); */
|
|
||||||
/* SDL_RenderDrawLine(r,0,80*2,640,80*2); */
|
|
||||||
|
|
||||||
// Spectrum analyzer?
|
// Spectrum analyzer?
|
||||||
/* { */
|
/* { */
|
||||||
|
4
synth.c
4
synth.c
@ -136,9 +136,9 @@ void gen_pul(
|
|||||||
if(freq==0.0)break;
|
if(freq==0.0)break;
|
||||||
|
|
||||||
if(i%cyclelen==points[0])
|
if(i%cyclelen==points[0])
|
||||||
sig=-amplitude;
|
sig=-amplitude*(1.0-phase);
|
||||||
else if(i%cyclelen==points[1])
|
else if(i%cyclelen==points[1])
|
||||||
sig=amplitude;
|
sig=amplitude*phase;
|
||||||
|
|
||||||
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
buffer[i]=(buffer[i]+sig)/(mix?2.0:1.0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user