Mercurial > mplayer.hg
annotate libao2/ao_dxr3.c @ 3615:2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
author | mswitch |
---|---|
date | Wed, 19 Dec 2001 14:31:31 +0000 |
parents | f8bfaa1c9487 |
children | a515ff1954fd |
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" | |
18 | |
3186 | 19 void perror( const char *s ); |
20 #include <errno.h> | |
21 int sys_nerr; | |
2770 | 22 extern int verbose; |
2645 | 23 |
24 static ao_info_t info = | |
25 { | |
26 "DXR3/H+ audio out", | |
27 "dxr3", | |
28 "David Holm <dholm@iname.com>", | |
29 "" | |
30 }; | |
31 | |
32 LIBAO_EXTERN(dxr3) | |
33 | |
2770 | 34 static audio_buf_info dxr3_buf_info; |
2921 | 35 static int fd_control = 0, fd_audio = 0; |
2770 | 36 |
2645 | 37 // to set/get/query special features/parameters |
38 static int control(int cmd,int arg) | |
39 { | |
40 switch(cmd) | |
41 { | |
42 case AOCONTROL_QUERY_FORMAT: | |
43 return CONTROL_TRUE; | |
44 case AOCONTROL_GET_VOLUME: | |
45 case AOCONTROL_SET_VOLUME: | |
2770 | 46 return CONTROL_OK; |
47 return CONTROL_ERROR; | |
2645 | 48 } |
2770 | 49 return CONTROL_UNKNOWN; |
2645 | 50 } |
51 | |
52 // open & setup audio device | |
53 // return: 1=success 0=fail | |
54 static int init(int rate,int channels,int format,int flags) | |
55 { | |
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
|
56 int ioval; |
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
|
57 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
|
58 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
|
59 { |
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
|
60 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
|
61 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
|
62 } |
2770 | 63 |
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
|
64 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
|
65 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
|
66 { |
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
|
67 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
|
68 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
|
69 } |
3186 | 70 |
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
|
71 ioctl(fd_audio, SNDCTL_DSP_RESET, NULL); |
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 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
|
73 if( ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_data.format) < 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
|
74 printf( "AO: [dxr3] Unable to set audio format\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
|
75 if(format == AFMT_AC3 && ao_data.format != AFMT_AC3) |
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 { |
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 printf("AO: [dxr3] Can't set audio device /dev/em8300_ma to AC3 output\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
|
78 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
|
79 } |
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 |
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
|
81 printf("AO: [dxr3] Sample format: %s (requested: %s)\n", |
3186 | 82 audio_out_format_name(ao_data.format), audio_out_format_name(format)); |
2770 | 83 |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
84 ao_data.channels=channels; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
85 if(format != AFMT_AC3) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
86 if(channels>2) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
87 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
|
88 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
|
89 else |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
90 { |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
91 int c = channels-1; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
92 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
|
93 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
|
94 } |
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
|
95 |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
96 ao_data.bps = channels*rate; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
97 if(format != AFMT_U8 && format != AFMT_S8) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 { |
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
|
102 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
|
103 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
|
104 } |
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
|
105 if( rate < ao_data.samplerate ) |
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 { |
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
|
107 ao_data.samplerate = 44100; |
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
|
108 ioctl(fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
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
|
109 if( ao_data.samplerate != 44100 ) |
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 { |
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 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
|
112 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
|
113 } |
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 printf("AO: [dxr3] Using %d Hz samplerate (requested: %d) (Upsampling)\n",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
|
115 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
|
116 } |
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
|
117 else printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); |
2770 | 118 |
2968 | 119 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 ) |
120 { | |
2770 | 121 int r=0; |
2968 | 122 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"); |
123 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 ) | |
124 { | |
3186 | 125 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_data.outburst ); |
2968 | 126 } |
127 else | |
128 { | |
3186 | 129 ao_data.outburst=r; |
130 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); | |
2770 | 131 } |
2968 | 132 } |
133 else | |
134 { | |
135 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n", | |
136 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
|
137 ao_data.buffersize=(dxr3_buf_info.bytes/2); |
3186 | 138 ao_data.outburst=dxr3_buf_info.fragsize; |
2770 | 139 } |
2645 | 140 |
2921 | 141 ioval = EM8300_PLAYMODE_PLAY; |
2968 | 142 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) |
143 printf( "AO: [dxr3] Unable to set playmode\n" ); | |
2921 | 144 close( fd_control ); |
2770 | 145 |
146 return 1; | |
2645 | 147 } |
148 | |
149 // close audio device | |
150 static void uninit() | |
151 { | |
2968 | 152 printf( "AO: [dxr3] Uninitializing\n" ); |
153 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 ) | |
154 printf( "AO: [dxr3] Unable to reset device\n" ); | |
2921 | 155 close( fd_audio ); |
3186 | 156 close( fd_control ); /* Just in case */ |
2645 | 157 } |
158 | |
159 // stop playing and empty buffers (for seeking/pause) | |
160 static void reset() | |
161 { | |
2968 | 162 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 ) |
163 printf( "AO: [dxr3] Unable to reset device\n" ); | |
2645 | 164 } |
165 | |
166 // stop playing, keep buffers (for pause) | |
167 static void audio_pause() | |
168 { | |
2968 | 169 int ioval; |
3201 | 170 reset(); |
2968 | 171 fd_control = open( "/dev/em8300", O_WRONLY ); |
172 if( fd_control < 0 ) | |
173 printf( "AO: [dxr3] Oops, unable to pause playback\n" ); | |
174 else | |
175 { | |
176 ioval = EM8300_PLAYMODE_PAUSED; | |
177 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) | |
178 printf( "AO: [dxr3] Unable to pause playback\n" ); | |
179 close( fd_control ); | |
180 } | |
2645 | 181 } |
182 | |
183 // resume playing, after audio_pause() | |
184 static void audio_resume() | |
185 { | |
2968 | 186 int ioval; |
187 fd_control = open( "/dev/em8300", O_WRONLY ); | |
188 if( fd_control < 0 ) | |
189 printf( "AO: [dxr3] Oops, unable to resume playback\n" ); | |
190 else | |
191 { | |
192 ioval = EM8300_PLAYMODE_PLAY; | |
193 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) | |
194 printf( "AO: [dxr3] Unable to resume playback\n" ); | |
195 close( fd_control ); | |
196 } | |
2645 | 197 } |
198 | |
199 // return: how many bytes can be played without blocking | |
200 static int get_space() | |
201 { | |
2968 | 202 int space = 0; |
3186 | 203 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &space) < 0 ) |
2968 | 204 { |
3186 | 205 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" ); |
206 return ao_data.outburst; | |
2968 | 207 } |
3186 | 208 space = ao_data.buffersize - space; |
3201 | 209 space /= ao_data.outburst; /* This is a smart way of doing a fast modulo reduction */ |
210 space *= ao_data.outburst; /* fetched from ao_mpegpes.c */ | |
2968 | 211 return space; |
2645 | 212 } |
213 | |
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
|
214 // 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
|
215 // 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
|
216 // return: number of bytes played |
2645 | 217 static int play(void* data,int len,int flags) |
218 { | |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
219 len /= ao_data.outburst; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
220 return write(fd_audio,data,len*ao_data.outburst); |
2645 | 221 } |
222 | |
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
|
223 // return: delay in seconds between first and last sample in buffer |
3186 | 224 static float get_delay() |
2645 | 225 { |
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
|
226 int r=0; |
3186 | 227 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 ) |
228 { | |
2968 | 229 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" ); |
3186 | 230 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
231 } | |
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
|
232 return (((float)r)/(float)ao_data.bps); |
2645 | 233 } |
234 |