comparison libao2/ao_dxr3.c @ 3827:6e7df97bd120

Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk> Hardware sync-code activated
author mswitch
date Fri, 28 Dec 2001 10:20:16 +0000
parents 1e0052d8c532
children 6f2ae5226367
comparison
equal deleted inserted replaced
3826:8a88ed2473aa 3827:6e7df97bd120
77 { 77 {
78 printf("AO: [dxr3] Can't open em8300 control /dev/em8300\n"); 78 printf("AO: [dxr3] Can't open em8300 control /dev/em8300\n");
79 return 0; 79 return 0;
80 } 80 }
81 81
82 ioval = (format==AFMT_AC3)?EM8300_AUDIOMODE_DIGITALAC3:
83 EM8300_AUDIOMODE_ANALOG;
84 if( ioctl( fd_control, EM8300_IOCTL_SET_AUDIOMODE, &ioval ) < 0 )
85 printf( "AO: [dxr3] Unable to set audiomode\n" );
86
82 ioctl(fd_audio, SNDCTL_DSP_RESET, NULL); 87 ioctl(fd_audio, SNDCTL_DSP_RESET, NULL);
83 88
84 ao_data.format = format; 89 ao_data.format = format;
85 if( ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_data.format) < 0 ) 90 if( ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_data.format) < 0 )
86 printf( "AO: [dxr3] Unable to set audio format\n" ); 91 printf( "AO: [dxr3] Unable to set audio format\n" );
92 ao_plugin_cfg.pl_format_type = ao_data.format; 97 ao_plugin_cfg.pl_format_type = ao_data.format;
93 } 98 }
94 99
95 ao_data.channels=channels; 100 ao_data.channels=channels;
96 if(format != AFMT_AC3) 101 if(format != AFMT_AC3)
102 {
97 if(channels>2) 103 if(channels>2)
104 {
98 if( ioctl (fd_audio, SNDCTL_DSP_CHANNELS, &ao_data.channels) < 0 ) 105 if( ioctl (fd_audio, SNDCTL_DSP_CHANNELS, &ao_data.channels) < 0 )
99 printf( "AO: [dxr3] Unable to set number of channels\n" ); 106 printf( "AO: [dxr3] Unable to set number of channels\n" );
100 else 107 }
101 { 108 else
102 int c = channels-1; 109 {
110 int c = channels-1;
103 if( ioctl(fd_audio,SNDCTL_DSP_STEREO,&c) < 0) 111 if( ioctl(fd_audio,SNDCTL_DSP_STEREO,&c) < 0)
104 printf( "AO: [dxr3] Unable to set number of channels for AC3\n" ); 112 printf( "AO: [dxr3] Unable to set number of channels for AC3\n" );
113 }
105 } 114 }
106 115
107 ao_data.bps = channels*rate; 116 ao_data.bps = channels*rate;
108 if(format != AFMT_U8 && format != AFMT_S8) 117 if(format != AFMT_U8 && format != AFMT_S8)
109 ao_data.bps*=2; 118 ao_data.bps*=2;
119 if(format == AFMT_AC3)
120 ao_data.bps*=2;
110 ao_data.samplerate=rate; 121 ao_data.samplerate=rate;
111 if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate) < 0 ) 122 if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate) < 0 )
112 { 123 {
113 printf( "AO: [dxr3] Unable to set samplerate\n" ); 124 printf( "AO: [dxr3] Unable to set samplerate\n" );
114 return 0; 125 return 0;
135 } 146 }
136 } 147 }
137 else 148 else
138 { 149 {
139 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n", 150 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); 151 dxr3_buf_info.fragments, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes);
141 ao_data.buffersize=(dxr3_buf_info.bytes/2); 152 ao_data.buffersize=dxr3_buf_info.bytes;
142 ao_data.outburst=dxr3_buf_info.fragsize; 153 ao_data.outburst=dxr3_buf_info.fragsize;
143 } 154 }
144 155
145 if(need_conversion) 156 if(need_conversion)
146 { 157 {
158 return 0; 169 return 0;
159 ao_plugin_data.len = ao_data.buffersize*2; 170 ao_plugin_data.len = ao_data.buffersize*2;
160 audio_plugin_resample.control(AOCONTROL_PLUGIN_SET_LEN,0); 171 audio_plugin_resample.control(AOCONTROL_PLUGIN_SET_LEN,0);
161 } 172 }
162 } 173 }
174
175
163 ioval = EM8300_PLAYMODE_PLAY; 176 ioval = EM8300_PLAYMODE_PLAY;
164 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) 177 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
165 printf( "AO: [dxr3] Unable to set playmode\n" ); 178 printf( "AO: [dxr3] Unable to set playmode\n" );
166 close( fd_control ); 179 close( fd_control );
167 180
224 237
225 // return: how many bytes can be played without blocking 238 // return: how many bytes can be played without blocking
226 static int get_space() 239 static int get_space()
227 { 240 {
228 int space = 0; 241 int space = 0;
229 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &space) < 0 ) 242 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
230 { 243 {
231 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" ); 244 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
232 return ao_data.outburst; 245 return ao_data.outburst;
233 } 246 }
234 space = ao_data.buffersize - space; 247 space=dxr3_buf_info.fragments*dxr3_buf_info.fragsize;
235 space /= ao_data.outburst; /* This is a smart way of doing a fast modulo reduction */ 248
236 space *= ao_data.outburst; /* fetched from ao_mpegpes.c */
237 return space; 249 return space;
238 } 250 }
239 251
240 // playes 'len' bytes of 'data' 252 // playes 'len' bytes of 'data'
241 // upsamples if samplerate < 44100 253 // upsamples if samplerate < 44100
246 int size = (tmp<len)?tmp:len; 258 int size = (tmp<len)?tmp:len;
247 ao_plugin_data.data = data; 259 ao_plugin_data.data = data;
248 ao_plugin_data.len = size; 260 ao_plugin_data.len = size;
249 if(need_conversion & 0x1) audio_plugin_format.play(); 261 if(need_conversion & 0x1) audio_plugin_format.play();
250 if(need_conversion & 0x2) audio_plugin_resample.play(); 262 if(need_conversion & 0x2) audio_plugin_resample.play();
263 if( ioctl(fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_data.pts) < 0 )
264 printf( "AO: [dxr3] Unable to set pts\n" );
251 write(fd_audio,ao_plugin_data.data,ao_plugin_data.len); 265 write(fd_audio,ao_plugin_data.data,ao_plugin_data.len);
252 return size; 266 return size;
253 } 267 }
254 268
255 // return: delay in seconds between first and last sample in buffer 269 // return: delay in seconds between first and last sample in buffer
256 static float get_delay() 270 static float get_delay()
257 { 271 {
258 int r=0; 272 return 0.0;
259 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 ) 273 }
260 { 274
261 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
262 return ((float)ao_data.buffersize)/(float)ao_data.bps;
263 }
264 return (((float)r)/(float)ao_data.bps);
265 }
266