annotate libaf/af_sweep.c @ 19024:4733c3e4f353

Update with latest changes and make diff apply cleanly.
author diego
date Wed, 12 Jul 2006 14:00:04 +0000
parents a9da2db9eb16
children fd6f824ef894
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
1 // Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
2 // #inlcude <GPL_v2.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
3
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
4 #include <stdio.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
5 #include <stdlib.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
6 #include <string.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
7 #include <inttypes.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
8 #include <math.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
9
16982
a9da2db9eb16 Unify include paths by adding -I.. to CFLAGS.
diego
parents: 14245
diff changeset
10 #include "config.h"
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
11 #include "af.h"
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
12
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
13 typedef struct af_sweep_s{
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
14 double x;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
15 double delta;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
16 }af_sweept;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
17
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
18
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
19 // Initialization and runtime control
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
20 static int control(struct af_instance_s* af, int cmd, void* arg)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
21 {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
22 af_sweept* s = (af_sweept*)af->setup;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
23 af_data_t *data= (af_data_t*)arg;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
24
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
25 switch(cmd){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
26 case AF_CONTROL_REINIT:
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
27 af->data->nch = data->nch;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
28 af->data->format = AF_FORMAT_S16_NE;
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
29 af->data->bps = 2;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
30 af->data->rate = data->rate;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
31
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
32 return AF_OK;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
33 case AF_CONTROL_COMMAND_LINE:
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
34 sscanf((char*)arg,"%lf", &s->delta);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
35 return AF_OK;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
36 /* case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
37 af->data->rate = *(int*)arg;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
38 return AF_OK;*/
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
39 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
40 return AF_UNKNOWN;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
41 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
42
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
43 // Deallocate memory
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
44 static void uninit(struct af_instance_s* af)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
45 {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
46 if(af->data)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
47 free(af->data);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
48 if(af->setup){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
49 af_sweept *s = af->setup;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
50 free(s);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
51 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
52 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
53
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
54 // Filter data through filter
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
55 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
56 {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
57 af_sweept *s = af->setup;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
58 int i, j;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
59 int16_t *in = (int16_t*)data->audio;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
60 int chans = data->nch;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
61 int in_len = data->len/(2*chans);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
62
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
63 for(i=0; i<in_len; i++){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
64 for(j=0; j<chans; j++)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
65 in[i*chans+j]= 32000*sin(s->x*s->x);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
66 s->x += s->delta;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
67 if(2*s->x*s->delta >= 3.141592) s->x=0;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
68 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
69
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
70 return data;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
71 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
72
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
73 static int open(af_instance_t* af){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
74 af->control=control;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
75 af->uninit=uninit;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
76 af->play=play;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
77 af->mul.n=1;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
78 af->mul.d=1;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
79 af->data=calloc(1,sizeof(af_data_t));
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
80 af->setup=calloc(1,sizeof(af_sweept));
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
81 return AF_OK;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
82 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
83
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
84 af_info_t af_info_sweep = {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
85 "sine sweep",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
86 "sweep",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
87 "Michael Niedermayer",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
88 "",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
89 AF_FLAGS_REENTRANT,
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
90 open
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
91 };
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
92