Mercurial > mplayer.hg
annotate libaf/af_sweep.c @ 24902:c1660ecae8c4
100% cosmetics: reformatted with tabs and symmetric braces and removed useless braces and trailing tabs
author | nicodvb |
---|---|
date | Fri, 02 Nov 2007 11:43:03 +0000 |
parents | b2402b4f0afa |
children | 867ee1c2114b |
rev | line source |
---|---|
13721 | 1 // Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
2 // #inlcude <GPL_v2.h> | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 #include <inttypes.h> | |
8 #include <math.h> | |
9 | |
16982 | 10 #include "config.h" |
13721 | 11 #include "af.h" |
12 | |
13 typedef struct af_sweep_s{ | |
14 double x; | |
15 double delta; | |
16 }af_sweept; | |
17 | |
18 | |
19 // Initialization and runtime control | |
20 static int control(struct af_instance_s* af, int cmd, void* arg) | |
21 { | |
22 af_sweept* s = (af_sweept*)af->setup; | |
23 af_data_t *data= (af_data_t*)arg; | |
24 | |
25 switch(cmd){ | |
26 case AF_CONTROL_REINIT: | |
27 af->data->nch = data->nch; | |
14245 | 28 af->data->format = AF_FORMAT_S16_NE; |
13721 | 29 af->data->bps = 2; |
30 af->data->rate = data->rate; | |
31 | |
32 return AF_OK; | |
33 case AF_CONTROL_COMMAND_LINE: | |
34 sscanf((char*)arg,"%lf", &s->delta); | |
35 return AF_OK; | |
36 /* case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET: | |
37 af->data->rate = *(int*)arg; | |
38 return AF_OK;*/ | |
39 } | |
40 return AF_UNKNOWN; | |
41 } | |
42 | |
43 // Deallocate memory | |
44 static void uninit(struct af_instance_s* af) | |
45 { | |
46 if(af->data) | |
47 free(af->data); | |
48 if(af->setup){ | |
49 af_sweept *s = af->setup; | |
50 free(s); | |
51 } | |
52 } | |
53 | |
54 // Filter data through filter | |
55 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
56 { | |
57 af_sweept *s = af->setup; | |
58 int i, j; | |
59 int16_t *in = (int16_t*)data->audio; | |
60 int chans = data->nch; | |
61 int in_len = data->len/(2*chans); | |
62 | |
63 for(i=0; i<in_len; i++){ | |
64 for(j=0; j<chans; j++) | |
65 in[i*chans+j]= 32000*sin(s->x*s->x); | |
66 s->x += s->delta; | |
67 if(2*s->x*s->delta >= 3.141592) s->x=0; | |
68 } | |
69 | |
70 return data; | |
71 } | |
72 | |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
16982
diff
changeset
|
73 static int af_open(af_instance_t* af){ |
13721 | 74 af->control=control; |
75 af->uninit=uninit; | |
76 af->play=play; | |
24888 | 77 af->mul=1; |
13721 | 78 af->data=calloc(1,sizeof(af_data_t)); |
79 af->setup=calloc(1,sizeof(af_sweept)); | |
80 return AF_OK; | |
81 } | |
82 | |
83 af_info_t af_info_sweep = { | |
84 "sine sweep", | |
85 "sweep", | |
86 "Michael Niedermayer", | |
87 "", | |
88 AF_FLAGS_REENTRANT, | |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
16982
diff
changeset
|
89 af_open |
13721 | 90 }; |
91 |