UltraSPARC T1 (Niagara) support, patch by Derek E. Lewis /dlewis (gobble) solnetworks...
[mplayer/glamo.git] / libaf / af_sweep.c
blob11cfc54d84a47729c9ebcb64cc533d582aac719c
1 // Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
2 // #inlcude <GPL_v2.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <inttypes.h>
8 #include <math.h>
10 #include "config.h"
11 #include "af.h"
13 typedef struct af_sweep_s{
14 double x;
15 double delta;
16 }af_sweept;
19 // Initialization and runtime control
20 static int control(struct af_instance_s* af, int cmd, void* arg)
22 af_sweept* s = (af_sweept*)af->setup;
23 af_data_t *data= (af_data_t*)arg;
25 switch(cmd){
26 case AF_CONTROL_REINIT:
27 af->data->nch = data->nch;
28 af->data->format = AF_FORMAT_S16_NE;
29 af->data->bps = 2;
30 af->data->rate = data->rate;
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;*/
40 return AF_UNKNOWN;
43 // Deallocate memory
44 static void uninit(struct af_instance_s* af)
46 if(af->data)
47 free(af->data);
48 if(af->setup){
49 af_sweept *s = af->setup;
50 free(s);
54 // Filter data through filter
55 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
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);
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;
70 return data;
73 static int open(af_instance_t* af){
74 af->control=control;
75 af->uninit=uninit;
76 af->play=play;
77 af->mul.n=1;
78 af->mul.d=1;
79 af->data=calloc(1,sizeof(af_data_t));
80 af->setup=calloc(1,sizeof(af_sweept));
81 return AF_OK;
84 af_info_t af_info_sweep = {
85 "sine sweep",
86 "sweep",
87 "Michael Niedermayer",
88 "",
89 AF_FLAGS_REENTRANT,
90 open