annotate libao2/ao_dxr3.c @ 2690:a2bb142ce67d

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