annotate libao2/pl_delay.c @ 7365:822923446b66

Removed authors and maintainers section, now in txt format.
author diego
date Tue, 10 Sep 2002 21:56:05 +0000
parents 2eec40929570
children c4434bdf6e51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
7
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
8 #include <stdio.h>
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
9 #include <stdlib.h>
6237
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 4374
diff changeset
10 #include <string.h>
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
11
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
12 #include "audio_out.h"
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
13 #include "audio_plugin.h"
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
14 #include "audio_plugin_internal.h"
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
15 #include "afmt.h"
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
16
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
17 static ao_info_t info =
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
18 {
3194
1648d11fc36c commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents: 3107
diff changeset
19 "Delay audio plugin",
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
20 "delay",
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
21 "Anders",
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
22 ""
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
23 };
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
24
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
25 LIBAO_PLUGIN_EXTERN(delay)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
26
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
27 // local data
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
28 typedef struct pl_delay_s
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
29 {
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
30 void* data; // local audio data block
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
31 void* delay; // data block used for delaying audio signal
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
32 int len; // local buffer length
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
33 int rate; // local data rate
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
34 int channels; // local number of channels
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
35 int format; // local format
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
36 } pl_delay_t;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
37
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
38 static pl_delay_t pl_delay={NULL,NULL,0,0,0,0};
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
39
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
40 // to set/get/query special features/parameters
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
41 static int control(int cmd,int arg){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
42 switch(cmd){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
43 case AOCONTROL_PLUGIN_SET_LEN:
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
44 if(pl_delay.data)
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
45 free(pl_delay.data);
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);
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
48 if(!pl_delay.data)
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
49 return CONTROL_ERROR;
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
50 return CONTROL_OK;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
51 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
52 return -1;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
53 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
54
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
55 // open & setup audio device
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
56 // return: 1=success 0=fail
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
57 static int init(){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
58 int i=0;
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
59 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
60
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
61 /* If the output format of any of the below parameters differs from
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
62 what is give it should be changed. See ao_plugin init() */
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
63 pl_delay.rate=ao_plugin_data.rate;
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
64 pl_delay.channels=ao_plugin_data.channels; //1=mono 2=stereo
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
65 pl_delay.format=ao_plugin_data.format;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
66
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
67 // 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
68 time_delay=-1*(float)ao_plugin_cfg.pl_delay_len/((float)pl_delay.channels*(float)pl_delay.rate);
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
69 if(pl_delay.format != AFMT_U8 && pl_delay.format != AFMT_S8)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
70 time_delay/=2;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
71 ao_plugin_data.delay_fix+=time_delay;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
72
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
73 // 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
74 pl_delay.delay=(void*)malloc(ao_plugin_cfg.pl_delay_len);
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
75 if(!pl_delay.delay)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
76 return 0;
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
77 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
78
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
79 // 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
80 printf("[pl_delay] Output sound delayed by %i bytes\n",ao_plugin_cfg.pl_delay_len);
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
81 return 1;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
82 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
83
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
84 // close plugin
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
85 static void uninit(){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
86 if(pl_delay.delay)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
87 free(pl_delay.delay);
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
88 if(pl_delay.data)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
89 free(pl_delay.data);
3194
1648d11fc36c commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents: 3107
diff changeset
90 ao_plugin_cfg.pl_delay_len=0;
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
91 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
92
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
93 // empty buffers
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
94 static void reset(){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
95 int i = 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
96 for(i=0;i<pl_delay.len;i++)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
97 ((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
98 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++)
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
99 ((char*)pl_delay.delay)[i]=0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
100 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
101
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
102 // processes 'ao_plugin_data.len' bytes of 'data'
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
103 // called for every block of data
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
104 static int play(){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
105 // Copy end of prev block to begining of buffer
4374
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
106 memcpy(pl_delay.data,pl_delay.delay,ao_plugin_cfg.pl_delay_len);
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
107 // Copy current block except end
4374
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
108 memcpy(pl_delay.data+ao_plugin_cfg.pl_delay_len,
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
109 ao_plugin_data.data,
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
110 ao_plugin_data.len-ao_plugin_cfg.pl_delay_len);
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
111 // Save away end of current block for next call
4374
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
112 memcpy(pl_delay.delay,
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
113 ao_plugin_data.data+ao_plugin_data.len-ao_plugin_cfg.pl_delay_len,
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 3307
diff changeset
114 ao_plugin_cfg.pl_delay_len);
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
115 // Set output data block
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
116 ao_plugin_data.data=pl_delay.data;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
117 return 1;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
118 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
119
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
120
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents:
diff changeset
121
3307
4a5d56e89735 correced memory deallocation bug and erors in comments
anders
parents: 3194
diff changeset
122
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