12 #define M_PI 3.14159265358979323846
15 /***** silly_effect (it's a ring modulator right now, but may change) *****/
21 static int silly_effect_process(struct effect
*ef
, void **buf
, long n_samples
)
32 for (i
= 0; i
< n_samples
; ++i
){
33 bufp
[i
* 2] *= cos((i
* 2 * M_PI
) / 441.0);
34 bufp
[i
* 2 + 1] *= cos((i
* 2 * M_PI
) / 441.0);
39 static void silly_effect_destroy(struct effect
*ef
)
44 static const struct effect_vtab silly_effect_vtab
= {
49 struct effect
*silly_effect_create(void)
51 struct silly_effect
*se
;
52 se
= malloc(sizeof *se
);
56 se
->e
.vtab
= &silly_effect_vtab
;
60 void silly_effect_free(struct effect
*e
)
65 ///// wavefile_source /////
67 struct wavefile_source
{
73 static int wavefile_source_process(struct effect
*ef
, void **buf
, long n_samples
)
75 struct wavefile_source
*wfs
= (struct wavefile_source
*) ef
;
80 *buf
= malloc(8 * n_samples
); // XXXX!
85 rbuf
= malloc(n_samples
* 4); // XXX!
87 wavefile_read_at(&wfs
->wf
, wfs
->pos
, rbuf
, n_samples
);
89 for (i
= n_samples
* 2; i
; --i
){
90 *fbuf
= *rbuf_p
/ 32768.0;
96 wfs
->pos
+= n_samples
;
100 static void wavefile_source_destroy(struct effect
*ef
)
102 // struct wavefile_source *wfs = (struct wavefile_source *) ef;
103 // wavefile_destroy(&wfs->wf);
107 static const struct effect_vtab wavefile_source_vtab
= {
108 wavefile_source_process
,
109 wavefile_source_destroy
,
112 struct effect
*wavefile_source_create(const char *filename
)
114 struct wavefile_source
*wfs
;
115 wfs
= malloc(sizeof *wfs
);
119 wfs
->e
.vtab
= &wavefile_source_vtab
;
121 if (wavefile_open(&wfs
->wf
, filename
)){
128 ///// play_sink /////
135 static int play_sink_process(struct effect
*ef
, void **buf
, long n_samples
)
137 struct play_sink
*ps
= (struct play_sink
*) ef
;
138 short *wbuf
, *wbuf_p
;
142 // we're not a source
145 wbuf
= malloc(n_samples
* 4); // XXXX!!
148 for (i
= n_samples
* 2; i
; --i
){
149 *wbuf_p
= (short) (*fbuf
* 32768.0);
153 soundout_write(&ps
->so
, wbuf
, n_samples
* 4); // XXX!
158 static void play_sink_destroy(struct effect
*ef
)
160 // struct play_sink *ps = (struct play_sink *) ef;
161 // soundout_destroy(&ps->so);
165 static const struct effect_vtab play_sink_vtab
= {
170 struct effect
*play_sink_create(const struct aformat
*fmt
)
172 struct play_sink
*ps
;
173 ps
= malloc(sizeof *ps
);
177 if (soundout_open(&ps
->so
, fmt
) != 0){
181 ps
->e
.vtab
= &play_sink_vtab
;
185 ///// distortion /////
192 static pure
inline int mult_clamp16(int a
, int b
)
197 } else if (c
< -0x7FFF){
203 static int distortion_process(struct effect
*restrict ef
, void **buf
, long n_samples
)
205 struct distortion
*dist
= (struct distortion
*) ef
;
206 int i
, c
, chan_average
;
207 float *restrict pbuf
;
209 // struct distortion *dist = (struct distortion *) ef;
211 // we're not a source
217 for (i
= n_samples
; i
; --i
){
218 for (c
= 0; c
< 2; ++c
){
219 rms
+= powf(pbuf
[c
], 2);
223 rms
= sqrtf(rms
/ (n_samples
* 2));
227 for (i
= n_samples
; i
; --i
){
228 for (c
= 0; c
< 2; ++c
){
236 static void distortion_destroy(struct effect
*ef
)
238 // struct distortion *dist = (struct distortion *) ef;
239 // soundout_destroy(&dist->so);
243 static const struct effect_vtab distortion_vtab
= {
248 struct effect
*distortion_create(void)
250 struct distortion
*dist
;
251 dist
= malloc(sizeof *dist
);
255 dist
->level
= 0x7FFF;
256 dist
->e
.vtab
= &distortion_vtab
;