Mercurial > mplayer.hg
annotate libao2/ao_dxr3.c @ 3755:b805040d6645
release todo
author | arpi |
---|---|
date | Wed, 26 Dec 2001 02:42:44 +0000 |
parents | 1e0052d8c532 |
children | 6e7df97bd120 |
rev | line source |
---|---|
2645 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
2770 | 3 |
2921 | 4 #include <linux/em8300.h> |
2770 | 5 #include <sys/ioctl.h> |
2645 | 6 #include <unistd.h> |
2770 | 7 #include <sys/time.h> |
2645 | 8 #include <sys/types.h> |
2770 | 9 #include <sys/stat.h> |
10 #include <fcntl.h> | |
2645 | 11 |
12 #include "../config.h" | |
13 | |
14 #include "afmt.h" | |
15 | |
16 #include "audio_out.h" | |
17 #include "audio_out_internal.h" | |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
18 #include "audio_plugin.h" |
2645 | 19 |
3186 | 20 void perror( const char *s ); |
21 #include <errno.h> | |
22 int sys_nerr; | |
2770 | 23 extern int verbose; |
2645 | 24 |
25 static ao_info_t info = | |
26 { | |
27 "DXR3/H+ audio out", | |
28 "dxr3", | |
29 "David Holm <dholm@iname.com>", | |
30 "" | |
31 }; | |
32 | |
33 LIBAO_EXTERN(dxr3) | |
34 | |
2770 | 35 static audio_buf_info dxr3_buf_info; |
2921 | 36 static int fd_control = 0, fd_audio = 0; |
3662 | 37 static int need_conversion = 0; |
2770 | 38 |
2645 | 39 // to set/get/query special features/parameters |
40 static int control(int cmd,int arg) | |
41 { | |
42 switch(cmd) | |
43 { | |
44 case AOCONTROL_QUERY_FORMAT: | |
45 return CONTROL_TRUE; | |
46 case AOCONTROL_GET_VOLUME: | |
47 case AOCONTROL_SET_VOLUME: | |
2770 | 48 return CONTROL_OK; |
49 return CONTROL_ERROR; | |
2645 | 50 } |
2770 | 51 return CONTROL_UNKNOWN; |
2645 | 52 } |
53 | |
54 // open & setup audio device | |
55 // return: 1=success 0=fail | |
56 static int init(int rate,int channels,int format,int flags) | |
57 { | |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
58 int ioval; |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
59 ao_plugin_data.rate = rate; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
60 ao_plugin_data.channels = channels; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
61 ao_plugin_data.format = format; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
62 ao_plugin_data.sz_mult = 1; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
63 ao_plugin_data.sz_fix = 0; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
64 ao_plugin_data.delay_mult = 1; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
65 ao_plugin_data.delay_fix = 0; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
66 ao_plugin_cfg.pl_format_type = format; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
67 ao_plugin_cfg.pl_resample_fout = rate; |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
68 fd_audio = open( "/dev/em8300_ma", O_WRONLY ); |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
69 if( fd_audio < 0 ) |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
70 { |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
71 printf("AO: [dxr3] Can't open audio device /dev/em8300_ma -> nosound\n"); |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
72 return 0; |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
73 } |
2770 | 74 |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
75 fd_control = open( "/dev/em8300", O_WRONLY ); |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
76 if( fd_control < 0 ) |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
77 { |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
78 printf("AO: [dxr3] Can't open em8300 control /dev/em8300\n"); |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
79 return 0; |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
80 } |
3186 | 81 |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
82 ioctl(fd_audio, SNDCTL_DSP_RESET, NULL); |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
83 |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
84 ao_data.format = format; |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
85 if( ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_data.format) < 0 ) |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
86 printf( "AO: [dxr3] Unable to set audio format\n" ); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
87 if(format != ao_data.format) |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
88 { |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
89 need_conversion |= 0x1; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
90 ao_data.format = AFMT_S16_LE; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
91 ao_plugin_data.format = format; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
92 ao_plugin_cfg.pl_format_type = ao_data.format; |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
93 } |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
94 |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
95 ao_data.channels=channels; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
96 if(format != AFMT_AC3) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
97 if(channels>2) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
98 if( ioctl (fd_audio, SNDCTL_DSP_CHANNELS, &ao_data.channels) < 0 ) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
99 printf( "AO: [dxr3] Unable to set number of channels\n" ); |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
100 else |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
101 { |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
102 int c = channels-1; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
103 if( ioctl(fd_audio,SNDCTL_DSP_STEREO,&c) < 0) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
104 printf( "AO: [dxr3] Unable to set number of channels for AC3\n" ); |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
105 } |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
106 |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
107 ao_data.bps = channels*rate; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
108 if(format != AFMT_U8 && format != AFMT_S8) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
109 ao_data.bps*=2; |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
110 ao_data.samplerate=rate; |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
111 if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate) < 0 ) |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
112 { |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
113 printf( "AO: [dxr3] Unable to set samplerate\n" ); |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
114 return 0; |
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
115 } |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
116 if( rate != ao_data.samplerate ) |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
117 { |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
118 need_conversion |= 0x2; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
119 ao_plugin_data.rate = rate; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
120 ao_plugin_cfg.pl_resample_fout = ao_data.samplerate; |
3328
67bcfb9749df
Tried fixing a bug relating to users with digital audio output (I'm unable to test if this works myself since I don't have a decoder)
mswitch
parents:
3231
diff
changeset
|
121 } |
2770 | 122 |
2968 | 123 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 ) |
124 { | |
2770 | 125 int r=0; |
2968 | 126 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"); |
127 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 ) | |
128 { | |
3186 | 129 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_data.outburst ); |
2968 | 130 } |
131 else | |
132 { | |
3186 | 133 ao_data.outburst=r; |
134 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); | |
2770 | 135 } |
2968 | 136 } |
137 else | |
138 { | |
139 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n", | |
140 dxr3_buf_info.fragments+1, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes); | |
3218
8ba06b63f873
Fix green borders -> black borders, patch from D. Holm, also small fix to dxr3 ao.
atmos4
parents:
3201
diff
changeset
|
141 ao_data.buffersize=(dxr3_buf_info.bytes/2); |
3186 | 142 ao_data.outburst=dxr3_buf_info.fragsize; |
2770 | 143 } |
2645 | 144 |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
145 if(need_conversion) |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
146 { |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
147 |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
148 if(need_conversion & 0x1) |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
149 { |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
150 if(!audio_plugin_format.init()) |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
151 return 0; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
152 ao_plugin_data.len = ao_data.buffersize*2; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
153 audio_plugin_format.control(AOCONTROL_PLUGIN_SET_LEN,0); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
154 } |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
155 if(need_conversion & 0x2) |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
156 { |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
157 if(!audio_plugin_resample.init()) |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
158 return 0; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
159 ao_plugin_data.len = ao_data.buffersize*2; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
160 audio_plugin_resample.control(AOCONTROL_PLUGIN_SET_LEN,0); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
161 } |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
162 } |
2921 | 163 ioval = EM8300_PLAYMODE_PLAY; |
2968 | 164 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) |
165 printf( "AO: [dxr3] Unable to set playmode\n" ); | |
2921 | 166 close( fd_control ); |
2770 | 167 |
168 return 1; | |
2645 | 169 } |
170 | |
171 // close audio device | |
172 static void uninit() | |
173 { | |
2968 | 174 printf( "AO: [dxr3] Uninitializing\n" ); |
175 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 ) | |
176 printf( "AO: [dxr3] Unable to reset device\n" ); | |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
177 if(need_conversion & 0x1) audio_plugin_format.uninit(); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
178 if(need_conversion & 0x2) audio_plugin_resample.uninit(); |
2921 | 179 close( fd_audio ); |
3186 | 180 close( fd_control ); /* Just in case */ |
2645 | 181 } |
182 | |
183 // stop playing and empty buffers (for seeking/pause) | |
184 static void reset() | |
185 { | |
2968 | 186 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 ) |
187 printf( "AO: [dxr3] Unable to reset device\n" ); | |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
188 if(need_conversion & 0x1) audio_plugin_format.reset(); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
189 if(need_conversion & 0x2) audio_plugin_resample.reset(); |
2645 | 190 } |
191 | |
192 // stop playing, keep buffers (for pause) | |
193 static void audio_pause() | |
194 { | |
2968 | 195 int ioval; |
3201 | 196 reset(); |
2968 | 197 fd_control = open( "/dev/em8300", O_WRONLY ); |
198 if( fd_control < 0 ) | |
199 printf( "AO: [dxr3] Oops, unable to pause playback\n" ); | |
200 else | |
201 { | |
202 ioval = EM8300_PLAYMODE_PAUSED; | |
203 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) | |
204 printf( "AO: [dxr3] Unable to pause playback\n" ); | |
205 close( fd_control ); | |
206 } | |
2645 | 207 } |
208 | |
209 // resume playing, after audio_pause() | |
210 static void audio_resume() | |
211 { | |
2968 | 212 int ioval; |
213 fd_control = open( "/dev/em8300", O_WRONLY ); | |
214 if( fd_control < 0 ) | |
215 printf( "AO: [dxr3] Oops, unable to resume playback\n" ); | |
216 else | |
217 { | |
218 ioval = EM8300_PLAYMODE_PLAY; | |
219 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) | |
220 printf( "AO: [dxr3] Unable to resume playback\n" ); | |
221 close( fd_control ); | |
222 } | |
2645 | 223 } |
224 | |
225 // return: how many bytes can be played without blocking | |
226 static int get_space() | |
227 { | |
2968 | 228 int space = 0; |
3186 | 229 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &space) < 0 ) |
2968 | 230 { |
3186 | 231 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" ); |
232 return ao_data.outburst; | |
2968 | 233 } |
3186 | 234 space = ao_data.buffersize - space; |
3201 | 235 space /= ao_data.outburst; /* This is a smart way of doing a fast modulo reduction */ |
236 space *= ao_data.outburst; /* fetched from ao_mpegpes.c */ | |
2968 | 237 return space; |
2645 | 238 } |
239 | |
3231
4bc4354ec88e
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
mswitch
parents:
3218
diff
changeset
|
240 // playes 'len' bytes of 'data' |
4bc4354ec88e
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
mswitch
parents:
3218
diff
changeset
|
241 // upsamples if samplerate < 44100 |
4bc4354ec88e
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
mswitch
parents:
3218
diff
changeset
|
242 // return: number of bytes played |
2645 | 243 static int play(void* data,int len,int flags) |
244 { | |
3660
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
245 int tmp = get_space(); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
246 int size = (tmp<len)?tmp:len; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
247 ao_plugin_data.data = data; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
248 ao_plugin_data.len = size; |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
249 if(need_conversion & 0x1) audio_plugin_format.play(); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
250 if(need_conversion & 0x2) audio_plugin_resample.play(); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
251 write(fd_audio,ao_plugin_data.data,ao_plugin_data.len); |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
252 return size; |
2645 | 253 } |
254 | |
3231
4bc4354ec88e
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
mswitch
parents:
3218
diff
changeset
|
255 // return: delay in seconds between first and last sample in buffer |
3186 | 256 static float get_delay() |
2645 | 257 { |
3231
4bc4354ec88e
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
mswitch
parents:
3218
diff
changeset
|
258 int r=0; |
3186 | 259 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 ) |
260 { | |
2968 | 261 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" ); |
3186 | 262 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
263 } | |
3231
4bc4354ec88e
Added support for upsampling since dxr3/h+ only supports 44100Hz and 48000Hz, currently it only works on 44100/(2*ratio)
mswitch
parents:
3218
diff
changeset
|
264 return (((float)r)/(float)ao_data.bps); |
2645 | 265 } |
266 |