annotate libaf/af_sweep.c @ 13915:c012194ba7d7

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