Mercurial > mplayer.hg
comparison libaf/af_sweep.c @ 13721:0c2e5c9476df
sine sweep generator
author | michael |
---|---|
date | Thu, 21 Oct 2004 12:10:55 +0000 |
parents | |
children | 3c56b18bbb0c |
comparison
equal
deleted
inserted
replaced
13720:821f464b4d90 | 13721:0c2e5c9476df |
---|---|
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 | |
10 #include "../config.h" | |
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 if(data->format != (AF_FORMAT_SI | AF_FORMAT_NE)) | |
28 return AF_ERROR; | |
29 | |
30 af->data->nch = data->nch; | |
31 af->data->format = AF_FORMAT_SI | AF_FORMAT_NE; | |
32 af->data->bps = 2; | |
33 af->data->rate = data->rate; | |
34 | |
35 return AF_OK; | |
36 case AF_CONTROL_COMMAND_LINE: | |
37 sscanf((char*)arg,"%lf", &s->delta); | |
38 return AF_OK; | |
39 /* case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET: | |
40 af->data->rate = *(int*)arg; | |
41 return AF_OK;*/ | |
42 } | |
43 return AF_UNKNOWN; | |
44 } | |
45 | |
46 // Deallocate memory | |
47 static void uninit(struct af_instance_s* af) | |
48 { | |
49 if(af->data) | |
50 free(af->data); | |
51 if(af->setup){ | |
52 af_sweept *s = af->setup; | |
53 free(s); | |
54 } | |
55 } | |
56 | |
57 // Filter data through filter | |
58 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
59 { | |
60 af_sweept *s = af->setup; | |
61 int i, j; | |
62 int16_t *in = (int16_t*)data->audio; | |
63 int chans = data->nch; | |
64 int in_len = data->len/(2*chans); | |
65 | |
66 for(i=0; i<in_len; i++){ | |
67 for(j=0; j<chans; j++) | |
68 in[i*chans+j]= 32000*sin(s->x*s->x); | |
69 s->x += s->delta; | |
70 if(2*s->x*s->delta >= 3.141592) s->x=0; | |
71 } | |
72 | |
73 return data; | |
74 } | |
75 | |
76 static int open(af_instance_t* af){ | |
77 af->control=control; | |
78 af->uninit=uninit; | |
79 af->play=play; | |
80 af->mul.n=1; | |
81 af->mul.d=1; | |
82 af->data=calloc(1,sizeof(af_data_t)); | |
83 af->setup=calloc(1,sizeof(af_sweept)); | |
84 return AF_OK; | |
85 } | |
86 | |
87 af_info_t af_info_sweep = { | |
88 "sine sweep", | |
89 "sweep", | |
90 "Michael Niedermayer", | |
91 "", | |
92 AF_FLAGS_REENTRANT, | |
93 open | |
94 }; | |
95 |