2645
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <time.h>
|
|
4 #include <unistd.h>
|
|
5 #include <sys/types.h>
|
|
6 #include <sys/ioctl.h>
|
|
7
|
|
8 #include <libdxr3/api.h>
|
|
9
|
|
10 #include "../config.h"
|
|
11
|
|
12 #include "afmt.h"
|
|
13
|
|
14 #include "audio_out.h"
|
|
15 #include "audio_out_internal.h"
|
|
16
|
|
17 struct
|
|
18 {
|
|
19 int ao_format;
|
|
20 int ao_rate;
|
|
21 int ao_channels;
|
|
22 } ao_device;
|
|
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
|
|
34 // there are some globals:
|
|
35 // ao_samplerate
|
|
36 // ao_channels
|
|
37 // ao_format
|
|
38 // ao_bps
|
|
39 // ao_outburst
|
|
40 // ao_buffersize
|
|
41
|
|
42 // to set/get/query special features/parameters
|
|
43 static int control(int cmd,int arg)
|
|
44 {
|
|
45 switch(cmd)
|
|
46 {
|
|
47 case AOCONTROL_SET_DEVICE:
|
|
48 return CONTROL_OK;
|
|
49 case AOCONTROL_QUERY_FORMAT:
|
|
50 return CONTROL_TRUE;
|
|
51 case AOCONTROL_GET_VOLUME:
|
|
52 case AOCONTROL_SET_VOLUME:
|
|
53 {
|
|
54 return CONTROL_OK;
|
|
55 }
|
|
56 }
|
|
57 return CONTROL_TRUE;
|
|
58 }
|
|
59
|
|
60 // open & setup audio device
|
|
61 // return: 1=success 0=fail
|
|
62 static int init(int rate,int channels,int format,int flags)
|
|
63 {
|
|
64 ao_device.ao_format = format;
|
|
65 ao_device.ao_rate = rate;
|
|
66 ao_device.ao_channels = channels;
|
|
67
|
|
68 if( dxr3_get_status() == DXR3_STATUS_CLOSED )
|
|
69 {
|
|
70 if( dxr3_open( "/dev/em8300", "/etc/dxr3.ux" ) != 0 ) printf( "Error loading /dev/em8300 with /etc/dxr3.ux microcode\n" );
|
|
71 printf( "DXR3 status: &s\n", dxr3_get_status() ? "opened":"closed" );
|
|
72 }
|
|
73 else
|
|
74 printf( "DXR3 already open\n" );
|
|
75
|
|
76 if( dxr3_set_playmode( DXR3_PLAYMODE_PLAY ) != 0 ) printf( "Error setting playmode of DXR3\n" );
|
|
77
|
|
78 if( format == AFMT_AC3 )
|
|
79 {
|
|
80 if( dxr3_audio_set_mode( DXR3_AUDIOMODE_DIGITALAC3 ) != 0 )
|
|
81 {
|
|
82 printf( "Cannot set DXR3 to AC3 playback!\n" );
|
|
83 return -1;
|
|
84 }
|
|
85 }
|
|
86 else
|
|
87 {
|
|
88 if( dxr3_audio_set_mode( DXR3_AUDIOMODE_ANALOG ) != 0 )
|
|
89 {
|
|
90 printf( "Cannot set DXR3 to analog playback!\n" );
|
|
91 return -1;
|
|
92 }
|
|
93 if( format == AFMT_U8 )
|
|
94 dxr3_audio_set_samplesize( 8 );
|
|
95 else if( format == AFMT_S16_LE )
|
|
96 dxr3_audio_set_samplesize( 16 );
|
|
97 else
|
|
98 {
|
|
99 printf( "Unsupported audio format\n" );
|
|
100 return -1;
|
|
101 }
|
|
102 }
|
|
103
|
|
104 dxr3_audio_set_stereo( (channels > 1) ? "true":"false" );
|
|
105 dxr3_audio_set_rate( rate );
|
|
106
|
|
107 return 1;
|
|
108 }
|
|
109
|
|
110 // close audio device
|
|
111 static void uninit()
|
|
112 {
|
|
113 dxr3_close();
|
|
114 }
|
|
115
|
|
116 // stop playing and empty buffers (for seeking/pause)
|
|
117 static void reset()
|
|
118 {
|
|
119 uninit();
|
|
120 if( !init( ao_device.ao_rate, ao_device.ao_channels, ao_device.ao_format, 0 ) )
|
|
121 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
|
|
122 }
|
|
123
|
|
124 // stop playing, keep buffers (for pause)
|
|
125 static void audio_pause()
|
|
126 {
|
|
127 // for now, just call reset();
|
|
128 reset();
|
|
129 }
|
|
130
|
|
131 // resume playing, after audio_pause()
|
|
132 static void audio_resume()
|
|
133 {
|
|
134 }
|
|
135
|
|
136
|
|
137 // return: how many bytes can be played without blocking
|
|
138 static int get_space()
|
|
139 {
|
|
140 return dxr3_audio_get_buffersize()-dxr3_audio_get_bytesleft();
|
|
141 }
|
|
142
|
|
143 // plays 'len' bytes of 'data'
|
|
144 // it should round it down to outburst*n
|
|
145 // return: number of bytes played
|
|
146 static int play(void* data,int len,int flags)
|
|
147 {
|
|
148 if(len)
|
|
149 if( ao_device.ao_format == AFMT_AC3 )
|
|
150 return dxr3_audio_write_ac3( data, len );
|
|
151 else
|
|
152 return dxr3_audio_write_ac3( data, len );
|
|
153
|
|
154 printf( "Invalid audio data\n" );
|
|
155 return 0;
|
|
156 }
|
|
157
|
|
158 // return: how many unplayed bytes are in the buffer
|
|
159 static int get_delay()
|
|
160 {
|
|
161 return dxr3_audio_get_bytesleft();
|
|
162 }
|
|
163
|