Mercurial > mplayer.hg
annotate libao2/ao_dxr3.c @ 4005:7c07bc1e0a81
Fixes to sync code
author | mswitch |
---|---|
date | Sun, 06 Jan 2002 14:29:58 +0000 |
parents | 6f2ae5226367 |
children | 14b0b19f7629 |
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 |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
82 ioval = (format==AFMT_AC3)?EM8300_AUDIOMODE_DIGITALAC3: |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
83 EM8300_AUDIOMODE_ANALOG; |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
84 if( ioctl( fd_control, EM8300_IOCTL_SET_AUDIOMODE, &ioval ) < 0 ) |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
85 printf( "AO: [dxr3] Unable to set audiomode\n" ); |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
86 |
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
|
87 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
|
88 |
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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 { |
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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 } |
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 |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
100 ao_data.channels=channels; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
101 if(format != AFMT_AC3) |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
102 { |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
103 if(channels>2) |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
104 { |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
105 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
|
106 printf( "AO: [dxr3] Unable to set number of channels\n" ); |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
107 } |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
108 else |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
109 { |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
110 int c = channels-1; |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
111 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
|
112 printf( "AO: [dxr3] Unable to set number of channels for AC3\n" ); |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
113 } |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
114 } |
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
|
115 |
3615
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
116 ao_data.bps = channels*rate; |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
117 if(format != AFMT_U8 && format != AFMT_S8) |
2a75bbac913e
Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents:
3387
diff
changeset
|
118 ao_data.bps*=2; |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
119 if(format == AFMT_AC3) |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 { |
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
|
124 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
|
125 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
|
126 } |
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
|
127 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
|
128 { |
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
|
129 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
|
130 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
|
131 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
|
132 } |
2770 | 133 |
2968 | 134 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 ) |
135 { | |
2770 | 136 int r=0; |
2968 | 137 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"); |
138 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 ) | |
139 { | |
3186 | 140 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_data.outburst ); |
2968 | 141 } |
142 else | |
143 { | |
3186 | 144 ao_data.outburst=r; |
145 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); | |
2770 | 146 } |
2968 | 147 } |
148 else | |
149 { | |
150 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n", | |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
151 dxr3_buf_info.fragments, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes); |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
152 ao_data.buffersize=dxr3_buf_info.bytes; |
3186 | 153 ao_data.outburst=dxr3_buf_info.fragsize; |
2770 | 154 } |
2645 | 155 |
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
|
156 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
|
157 { |
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 |
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 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
|
160 { |
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 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
|
162 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
|
163 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
|
164 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
|
165 } |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
166 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
|
167 { |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 } |
a515ff1954fd
Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents:
3615
diff
changeset
|
173 } |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
174 |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
175 |
2921 | 176 ioval = EM8300_PLAYMODE_PLAY; |
2968 | 177 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) |
178 printf( "AO: [dxr3] Unable to set playmode\n" ); | |
2921 | 179 close( fd_control ); |
2770 | 180 |
181 return 1; | |
2645 | 182 } |
183 | |
184 // close audio device | |
185 static void uninit() | |
186 { | |
2968 | 187 printf( "AO: [dxr3] Uninitializing\n" ); |
4004 | 188 reset( ); |
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
|
189 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
|
190 if(need_conversion & 0x2) audio_plugin_resample.uninit(); |
2921 | 191 close( fd_audio ); |
3186 | 192 close( fd_control ); /* Just in case */ |
2645 | 193 } |
194 | |
195 // stop playing and empty buffers (for seeking/pause) | |
196 static void reset() | |
197 { | |
2968 | 198 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 ) |
199 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
|
200 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
|
201 if(need_conversion & 0x2) audio_plugin_resample.reset(); |
2645 | 202 } |
203 | |
204 // stop playing, keep buffers (for pause) | |
205 static void audio_pause() | |
206 { | |
2968 | 207 int ioval; |
3201 | 208 reset(); |
2968 | 209 fd_control = open( "/dev/em8300", O_WRONLY ); |
210 if( fd_control < 0 ) | |
211 printf( "AO: [dxr3] Oops, unable to pause playback\n" ); | |
212 else | |
213 { | |
214 ioval = EM8300_PLAYMODE_PAUSED; | |
215 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) | |
216 printf( "AO: [dxr3] Unable to pause playback\n" ); | |
217 close( fd_control ); | |
218 } | |
2645 | 219 } |
220 | |
221 // resume playing, after audio_pause() | |
222 static void audio_resume() | |
223 { | |
2968 | 224 int ioval; |
225 fd_control = open( "/dev/em8300", O_WRONLY ); | |
226 if( fd_control < 0 ) | |
227 printf( "AO: [dxr3] Oops, unable to resume playback\n" ); | |
228 else | |
229 { | |
230 ioval = EM8300_PLAYMODE_PLAY; | |
231 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 ) | |
232 printf( "AO: [dxr3] Unable to resume playback\n" ); | |
233 close( fd_control ); | |
234 } | |
2645 | 235 } |
236 | |
237 // return: how many bytes can be played without blocking | |
238 static int get_space() | |
239 { | |
2968 | 240 int space = 0; |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
241 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 ) |
2968 | 242 { |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
243 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" ); |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
244 return ao_data.outburst; |
2968 | 245 } |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
246 space=dxr3_buf_info.fragments*dxr3_buf_info.fragsize; |
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
247 |
2968 | 248 return space; |
2645 | 249 } |
250 | |
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
|
251 // 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
|
252 // 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
|
253 // return: number of bytes played |
2645 | 254 static int play(void* data,int len,int flags) |
255 { | |
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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 if(need_conversion & 0x2) audio_plugin_resample.play(); |
4004 | 262 return write(fd_audio,ao_plugin_data.data,ao_plugin_data.len); |
2645 | 263 } |
264 | |
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
|
265 // return: delay in seconds between first and last sample in buffer |
3186 | 266 static float get_delay() |
2645 | 267 { |
3827
6e7df97bd120
Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents:
3662
diff
changeset
|
268 return 0.0; |
2645 | 269 } |
270 |