Mercurial > mplayer.hg
annotate libao2/pl_delay.c @ 3230:697c115d7d79
typo fixes
author | gabucino |
---|---|
date | Fri, 30 Nov 2001 22:18:34 +0000 |
parents | 1648d11fc36c |
children | 4a5d56e89735 |
rev | line source |
---|---|
3107 | 1 /* This is a null audio out plugin it doesnt't really do anything |
2 useful but serves an example of how audio plugins work. It delays | |
3 the output signal by the nuber of samples set by aop_delay n | |
4 where n is the number of bytes. | |
5 */ | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
6 #define PLUGIN |
3107 | 7 |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 | |
11 #include "audio_out.h" | |
12 #include "audio_plugin.h" | |
13 #include "audio_plugin_internal.h" | |
14 #include "afmt.h" | |
15 | |
16 static ao_info_t info = | |
17 { | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
18 "Delay audio plugin", |
3107 | 19 "delay", |
20 "Anders", | |
21 "" | |
22 }; | |
23 | |
24 LIBAO_PLUGIN_EXTERN(delay) | |
25 | |
26 // local data | |
27 typedef struct pl_delay_s | |
28 { | |
29 void* data; // local audio data block | |
30 void* delay; // data block used for delaying audio signal | |
31 int len; // local buffer length | |
32 int rate; // local data rate | |
33 int channels; // local number of channels | |
34 int format; // local format | |
35 | |
36 } pl_delay_t; | |
37 | |
38 static pl_delay_t pl_delay={NULL,NULL,0,0,0,0}; | |
39 | |
40 // to set/get/query special features/parameters | |
41 static int control(int cmd,int arg){ | |
42 switch(cmd){ | |
43 case AOCONTROL_PLUGIN_SET_LEN: | |
44 if(pl_delay.data) | |
45 uninit(); | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
46 pl_delay.len = ao_plugin_data.len; |
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
47 pl_delay.data=(void*)malloc(ao_plugin_data.len); |
3107 | 48 return CONTROL_OK; |
49 } | |
50 return -1; | |
51 } | |
52 | |
53 // open & setup audio device | |
54 // return: 1=success 0=fail | |
55 static int init(){ | |
56 int i=0; | |
57 float time_delay; // The number of tsamples this plugin delays the output data | |
58 /* if the output format of any of the below parameters differs from | |
59 what is give it should be changed. See ao_plugin init() */ | |
60 pl_delay.rate=ao_plugin_data.rate; | |
61 pl_delay.channels=ao_plugin_data.channels+1; //0=mono 1=stereo | |
62 pl_delay.format=ao_plugin_data.format; | |
63 | |
64 // Tell ao_plugin how much this plugin adds to the overall time delay | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
65 time_delay=-1*(float)ao_plugin_cfg.pl_delay_len/((float)pl_delay.channels*(float)pl_delay.rate); |
3107 | 66 if(pl_delay.format != AFMT_U8 && pl_delay.format != AFMT_S8) |
67 time_delay/=2; | |
68 ao_plugin_data.delay_fix+=time_delay; | |
69 | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
70 pl_delay.delay=(void*)malloc(ao_plugin_cfg.pl_delay_len); |
3107 | 71 if(!pl_delay.delay) |
72 return 0; | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
73 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++) |
3107 | 74 ((char*)pl_delay.delay)[i]=0; |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
75 printf("[pl_delay] Output sound delayed by %i bytes\n",ao_plugin_cfg.pl_delay_len); |
3107 | 76 return 1; |
77 } | |
78 | |
79 // close plugin | |
80 static void uninit(){ | |
81 if(pl_delay.delay) | |
82 free(pl_delay.delay); | |
83 if(pl_delay.data) | |
84 free(pl_delay.data); | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
85 ao_plugin_cfg.pl_delay_len=0; |
3107 | 86 } |
87 | |
88 // empty buffers | |
89 static void reset(){ | |
90 int i = 0; | |
91 for(i=0;i<pl_delay.len;i++) | |
92 ((char*)pl_delay.data)[i]=0; | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
93 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++) |
3107 | 94 ((char*)pl_delay.delay)[i]=0; |
95 } | |
96 | |
97 // processes 'ao_plugin_data.len' bytes of 'data' | |
98 // called for every block of data | |
99 static int play(){ | |
100 int i=0; | |
101 int j=0; | |
102 int k=0; | |
103 // Copy end of prev block to begining of buffer | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
104 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++,j++) |
3107 | 105 ((char*)pl_delay.data)[j]=((char*)pl_delay.delay)[i]; |
106 // Copy current block except end | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
107 for(i=0;i<ao_plugin_data.len-ao_plugin_cfg.pl_delay_len;i++,j++,k++) |
3107 | 108 ((char*)pl_delay.data)[j]=((char*)ao_plugin_data.data)[k]; |
109 // Save away end of current block for next call | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
110 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++,k++) |
3107 | 111 ((char*)pl_delay.delay)[i]=((char*)ao_plugin_data.data)[k]; |
112 // Set output data block | |
113 ao_plugin_data.data=pl_delay.data; | |
114 return 1; | |
115 } | |
116 | |
117 | |
118 |