comparison libao2/pl_delay.c @ 3194:1648d11fc36c

commandline configuration of audio plugins now through struct, format conversion plugin added
author anders
date Thu, 29 Nov 2001 12:44:06 +0000
parents ef2287ccc42b
children 4a5d56e89735
comparison
equal deleted inserted replaced
3193:53a6d2fc1498 3194:1648d11fc36c
1 /* This is a null audio out plugin it doesnt't really do anything 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 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 3 the output signal by the nuber of samples set by aop_delay n
4 where n is the number of bytes. 4 where n is the number of bytes.
5 */ 5 */
6 #define PLUGIN
6 7
7 #include <stdio.h> 8 #include <stdio.h>
8 #include <stdlib.h> 9 #include <stdlib.h>
9 10
10 #include "audio_out.h" 11 #include "audio_out.h"
12 #include "audio_plugin_internal.h" 13 #include "audio_plugin_internal.h"
13 #include "afmt.h" 14 #include "afmt.h"
14 15
15 static ao_info_t info = 16 static ao_info_t info =
16 { 17 {
17 "Null audio plugin", 18 "Delay audio plugin",
18 "delay", 19 "delay",
19 "Anders", 20 "Anders",
20 "" 21 ""
21 }; 22 };
22 23
34 35
35 } pl_delay_t; 36 } pl_delay_t;
36 37
37 static pl_delay_t pl_delay={NULL,NULL,0,0,0,0}; 38 static pl_delay_t pl_delay={NULL,NULL,0,0,0,0};
38 39
39 // global data
40 int pl_delay_len=0; // number of samples to delay sound output set from cmd line
41
42 // to set/get/query special features/parameters 40 // to set/get/query special features/parameters
43 static int control(int cmd,int arg){ 41 static int control(int cmd,int arg){
44 switch(cmd){ 42 switch(cmd){
45 case AOCONTROL_PLUGIN_SET_LEN: 43 case AOCONTROL_PLUGIN_SET_LEN:
46 if(pl_delay.data) 44 if(pl_delay.data)
47 uninit(); 45 uninit();
48 pl_delay.len = arg; 46 pl_delay.len = ao_plugin_data.len;
49 pl_delay.data=(void*)malloc(arg); 47 pl_delay.data=(void*)malloc(ao_plugin_data.len);
50 return CONTROL_OK; 48 return CONTROL_OK;
51 } 49 }
52 return -1; 50 return -1;
53 } 51 }
54 52
62 pl_delay.rate=ao_plugin_data.rate; 60 pl_delay.rate=ao_plugin_data.rate;
63 pl_delay.channels=ao_plugin_data.channels+1; //0=mono 1=stereo 61 pl_delay.channels=ao_plugin_data.channels+1; //0=mono 1=stereo
64 pl_delay.format=ao_plugin_data.format; 62 pl_delay.format=ao_plugin_data.format;
65 63
66 // Tell ao_plugin how much this plugin adds to the overall time delay 64 // Tell ao_plugin how much this plugin adds to the overall time delay
67 time_delay=-1*(float)pl_delay_len/((float)pl_delay.channels*(float)pl_delay.rate); 65 time_delay=-1*(float)ao_plugin_cfg.pl_delay_len/((float)pl_delay.channels*(float)pl_delay.rate);
68 if(pl_delay.format != AFMT_U8 && pl_delay.format != AFMT_S8) 66 if(pl_delay.format != AFMT_U8 && pl_delay.format != AFMT_S8)
69 time_delay/=2; 67 time_delay/=2;
70 ao_plugin_data.delay_fix+=time_delay; 68 ao_plugin_data.delay_fix+=time_delay;
71 69
72 pl_delay.delay=(void*)malloc(pl_delay_len); 70 pl_delay.delay=(void*)malloc(ao_plugin_cfg.pl_delay_len);
73 if(!pl_delay.delay) 71 if(!pl_delay.delay)
74 return 0; 72 return 0;
75 for(i=0;i<pl_delay_len;i++) 73 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++)
76 ((char*)pl_delay.delay)[i]=0; 74 ((char*)pl_delay.delay)[i]=0;
77 printf("[pl_delay] Output sound delayed by %i bytes\n",pl_delay_len); 75 printf("[pl_delay] Output sound delayed by %i bytes\n",ao_plugin_cfg.pl_delay_len);
78 return 1; 76 return 1;
79 } 77 }
80 78
81 // close plugin 79 // close plugin
82 static void uninit(){ 80 static void uninit(){
83 if(pl_delay.delay) 81 if(pl_delay.delay)
84 free(pl_delay.delay); 82 free(pl_delay.delay);
85 if(pl_delay.data) 83 if(pl_delay.data)
86 free(pl_delay.data); 84 free(pl_delay.data);
87 pl_delay_len=0; 85 ao_plugin_cfg.pl_delay_len=0;
88 } 86 }
89 87
90 // empty buffers 88 // empty buffers
91 static void reset(){ 89 static void reset(){
92 int i = 0; 90 int i = 0;
93 for(i=0;i<pl_delay.len;i++) 91 for(i=0;i<pl_delay.len;i++)
94 ((char*)pl_delay.data)[i]=0; 92 ((char*)pl_delay.data)[i]=0;
95 for(i=0;i<pl_delay_len;i++) 93 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++)
96 ((char*)pl_delay.delay)[i]=0; 94 ((char*)pl_delay.delay)[i]=0;
97 } 95 }
98 96
99 // processes 'ao_plugin_data.len' bytes of 'data' 97 // processes 'ao_plugin_data.len' bytes of 'data'
100 // called for every block of data 98 // called for every block of data
101 static int play(){ 99 static int play(){
102 int i=0; 100 int i=0;
103 int j=0; 101 int j=0;
104 int k=0; 102 int k=0;
105 // Copy end of prev block to begining of buffer 103 // Copy end of prev block to begining of buffer
106 for(i=0;i<pl_delay_len;i++,j++) 104 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++,j++)
107 ((char*)pl_delay.data)[j]=((char*)pl_delay.delay)[i]; 105 ((char*)pl_delay.data)[j]=((char*)pl_delay.delay)[i];
108 // Copy current block except end 106 // Copy current block except end
109 for(i=0;i<ao_plugin_data.len-pl_delay_len;i++,j++,k++) 107 for(i=0;i<ao_plugin_data.len-ao_plugin_cfg.pl_delay_len;i++,j++,k++)
110 ((char*)pl_delay.data)[j]=((char*)ao_plugin_data.data)[k]; 108 ((char*)pl_delay.data)[j]=((char*)ao_plugin_data.data)[k];
111 // Save away end of current block for next call 109 // Save away end of current block for next call
112 for(i=0;i<pl_delay_len;i++,k++) 110 for(i=0;i<ao_plugin_cfg.pl_delay_len;i++,k++)
113 ((char*)pl_delay.delay)[i]=((char*)ao_plugin_data.data)[k]; 111 ((char*)pl_delay.delay)[i]=((char*)ao_plugin_data.data)[k];
114 // Set output data block 112 // Set output data block
115 ao_plugin_data.data=pl_delay.data; 113 ao_plugin_data.data=pl_delay.data;
116 return 1; 114 return 1;
117 } 115 }