annotate libaf/af_sweep.c @ 26697:baaeace9c6a8

MPlayer uses Subversion, not GIT, 10L to me, and thanks to Mizda for spotting this
author gpoirier
date Sun, 11 May 2008 08:54:44 +0000
parents 867ee1c2114b
children b3a38b361fef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25529
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
1 /*
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
2 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
3 *
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
4 * This file is part of MPlayer.
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
5 *
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
7 * it under the terms of the GNU General Public License as published by
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
9 * (at your option) any later version.
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
10 *
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
14 * GNU General Public License for more details.
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
15 *
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
16 * You should have received a copy of the GNU General Public License
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
17 * along with MPlayer; if not, write to the Free Software
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
867ee1c2114b Relicense GPL v2 files as GPL v2+ and add proper license headers.
diego
parents: 24888
diff changeset
19 */
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
20
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
21 #include <stdio.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
22 #include <stdlib.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
23 #include <string.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
24 #include <inttypes.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
25 #include <math.h>
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
26
16982
a9da2db9eb16 Unify include paths by adding -I.. to CFLAGS.
diego
parents: 14245
diff changeset
27 #include "config.h"
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
28 #include "af.h"
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
29
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
30 typedef struct af_sweep_s{
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
31 double x;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
32 double delta;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
33 }af_sweept;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
34
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
35
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
36 // Initialization and runtime control
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
37 static int control(struct af_instance_s* af, int cmd, void* arg)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
38 {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
39 af_sweept* s = (af_sweept*)af->setup;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
40 af_data_t *data= (af_data_t*)arg;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
41
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
42 switch(cmd){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
43 case AF_CONTROL_REINIT:
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
44 af->data->nch = data->nch;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
45 af->data->format = AF_FORMAT_S16_NE;
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
46 af->data->bps = 2;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
47 af->data->rate = data->rate;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
48
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
49 return AF_OK;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
50 case AF_CONTROL_COMMAND_LINE:
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
51 sscanf((char*)arg,"%lf", &s->delta);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
52 return AF_OK;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
53 /* case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
54 af->data->rate = *(int*)arg;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
55 return AF_OK;*/
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
56 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
57 return AF_UNKNOWN;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
58 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
59
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
60 // Deallocate memory
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
61 static void uninit(struct af_instance_s* af)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
62 {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
63 if(af->data)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
64 free(af->data);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
65 if(af->setup){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
66 af_sweept *s = af->setup;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
67 free(s);
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
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
71 // Filter data through filter
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
72 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
73 {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
74 af_sweept *s = af->setup;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
75 int i, j;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
76 int16_t *in = (int16_t*)data->audio;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
77 int chans = data->nch;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
78 int in_len = data->len/(2*chans);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
79
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
80 for(i=0; i<in_len; i++){
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
81 for(j=0; j<chans; j++)
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
82 in[i*chans+j]= 32000*sin(s->x*s->x);
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
83 s->x += s->delta;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
84 if(2*s->x*s->delta >= 3.141592) s->x=0;
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 return data;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
88 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
89
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 16982
diff changeset
90 static int af_open(af_instance_t* af){
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
91 af->control=control;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
92 af->uninit=uninit;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
93 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22746
diff changeset
94 af->mul=1;
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
95 af->data=calloc(1,sizeof(af_data_t));
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
96 af->setup=calloc(1,sizeof(af_sweept));
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
97 return AF_OK;
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
98 }
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
99
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
100 af_info_t af_info_sweep = {
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
101 "sine sweep",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
102 "sweep",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
103 "Michael Niedermayer",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
104 "",
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
105 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
106 af_open
13721
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
107 };
0c2e5c9476df sine sweep generator
michael
parents:
diff changeset
108