Mercurial > mplayer.hg
annotate libao2/pl_delay.c @ 4037:2ec3b5e24955
portable problem solution. Should be generated in the future from pci.ids
author | nick |
---|---|
date | Mon, 07 Jan 2002 17:38:40 +0000 |
parents | 4a5d56e89735 |
children | 0a95c5074c50 |
rev | line source |
---|---|
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
1 /* Audio out plugin it doesnt't really do anything useful but serves |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
2 an example of how audio plugins work. It delays the output signal |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
3 by the nuber of samples set by delay=n where n is the number of |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
4 bytes. |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
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 } pl_delay_t; | |
36 | |
37 static pl_delay_t pl_delay={NULL,NULL,0,0,0,0}; | |
38 | |
39 // to set/get/query special features/parameters | |
40 static int control(int cmd,int arg){ | |
41 switch(cmd){ | |
42 case AOCONTROL_PLUGIN_SET_LEN: | |
43 if(pl_delay.data) | |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
44 free(pl_delay.data); |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
45 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
|
46 pl_delay.data=(void*)malloc(ao_plugin_data.len); |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
47 if(!pl_delay.data) |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
48 return CONTROL_ERROR; |
3107 | 49 return CONTROL_OK; |
50 } | |
51 return -1; | |
52 } | |
53 | |
54 // open & setup audio device | |
55 // return: 1=success 0=fail | |
56 static int init(){ | |
57 int i=0; | |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
58 float time_delay; // The time in [s] this plugin delays the output data |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
59 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
60 /* If the output format of any of the below parameters differs from |
3107 | 61 what is give it should be changed. See ao_plugin init() */ |
62 pl_delay.rate=ao_plugin_data.rate; | |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
63 pl_delay.channels=ao_plugin_data.channels; //1=mono 2=stereo |
3107 | 64 pl_delay.format=ao_plugin_data.format; |
65 | |
66 // 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
|
67 time_delay=-1*(float)ao_plugin_cfg.pl_delay_len/((float)pl_delay.channels*(float)pl_delay.rate); |
3107 | 68 if(pl_delay.format != AFMT_U8 && pl_delay.format != AFMT_S8) |
69 time_delay/=2; | |
70 ao_plugin_data.delay_fix+=time_delay; | |
71 | |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
72 // Create buffer for the delayed data |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
73 pl_delay.delay=(void*)malloc(ao_plugin_cfg.pl_delay_len); |
3107 | 74 if(!pl_delay.delay) |
75 return 0; | |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
76 memset(pl_delay.delay, 0, ao_plugin_cfg.pl_delay_len); |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
77 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
78 // Print some cool remark of what the plugin does |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
79 printf("[pl_delay] Output sound delayed by %i bytes\n",ao_plugin_cfg.pl_delay_len); |
3107 | 80 return 1; |
81 } | |
82 | |
83 // close plugin | |
84 static void uninit(){ | |
85 if(pl_delay.delay) | |
86 free(pl_delay.delay); | |
87 if(pl_delay.data) | |
88 free(pl_delay.data); | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
89 ao_plugin_cfg.pl_delay_len=0; |
3107 | 90 } |
91 | |
92 // empty buffers | |
93 static void reset(){ | |
94 int i = 0; | |
95 for(i=0;i<pl_delay.len;i++) | |
96 ((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
|
97 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++) |
3107 | 98 ((char*)pl_delay.delay)[i]=0; |
99 } | |
100 | |
101 // processes 'ao_plugin_data.len' bytes of 'data' | |
102 // called for every block of data | |
103 static int play(){ | |
104 int i=0; | |
105 int j=0; | |
106 int k=0; | |
107 // 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
|
108 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++,j++) |
3107 | 109 ((char*)pl_delay.data)[j]=((char*)pl_delay.delay)[i]; |
110 // Copy current block except end | |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
111 for(i=0;i<ao_plugin_data.len-ao_plugin_cfg.pl_delay_len;i++,j++,k++) |
3107 | 112 ((char*)pl_delay.data)[j]=((char*)ao_plugin_data.data)[k]; |
113 // 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
|
114 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++,k++) |
3107 | 115 ((char*)pl_delay.delay)[i]=((char*)ao_plugin_data.data)[k]; |
116 // Set output data block | |
117 ao_plugin_data.data=pl_delay.data; | |
118 return 1; | |
119 } | |
120 | |
121 | |
122 | |
3307
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
123 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
124 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
125 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
126 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
127 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
128 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
129 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
130 |
4a5d56e89735
correced memory deallocation bug and erors in comments
anders
parents:
3194
diff
changeset
|
131 |