3 various software synths and samples
5 Copyright (C) 2009 Evan Rinehart
7 This software comes with no warranty.
8 1. This software can be used for any purpose, good or evil.
9 2. Modifications must retain this license, at least in spirit.
15 #include <audio.h> /* to have SAMPLE_RATE */
19 instrument
make_cool() {
28 float note2step(int note
){
29 /* critical formula for tuning */
30 /* delta(omega*t) == wave increment */
31 /* == 2 pi f / samp_rate */
32 /* == 2pi f_0 2^(note/12) / samp_rate */
33 return 440*PI2
*pow(2, note
/12.0)/SAMPLE_RATE
;
42 void foo_mix(void* data
, float out
[], int count
){
43 struct foo
* foo
= data
;
46 if(foo
->on
== 0) return;
48 for(i
=0; i
<count
; i
++){
49 out
[i
] += sin(foo
->t
);
57 void foo_control(void* data
, int type
, int val1
, int val2
, int val
){
58 struct foo
* foo
= data
;
61 foo
->step
= note2step(val1
);
65 if(foo
->step
== note2step(val1
)){
72 void foo_cleanup(void* data
){ free(data
); }
74 instrument
make_foo(){
77 ins
.control
= foo_control
;
78 ins
.cleanup
= foo_cleanup
;
79 ins
.data
= malloc(sizeof(struct foo
));
83 instrument
load_instrument(enum instrument_name name
){
85 case ORG_FOO
: return make_foo();
86 case ORG_COOL
: return make_cool();
87 default: return make_foo();