annotate libao2/ao_dxr3.c @ 3345:20065c9b0f09

dithering info wasnt displayed
author michael
date Thu, 06 Dec 2001 01:23:23 +0000
parents 67bcfb9749df
children f8bfaa1c9487
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>
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
3
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
4 #include <linux/em8300.h>
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
5 #include <sys/ioctl.h>
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
6 #include <unistd.h>
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
7 #include <sys/time.h>
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
8 #include <sys/types.h>
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
9 #include <sys/stat.h>
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
10 #include <fcntl.h>
2645
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 "../config.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 "afmt.h"
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
15
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
16 #include "audio_out.h"
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
17 #include "audio_out_internal.h"
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
18
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
19 void perror( const char *s );
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
20 #include <errno.h>
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
21 int sys_nerr;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
22 extern int verbose;
2645
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
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
34 static audio_buf_info dxr3_buf_info;
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
35 static int fd_control = 0, fd_audio = 0;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
36
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
37 // to set/get/query special features/parameters
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
38 static int control(int cmd,int arg)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
39 {
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
40 switch(cmd)
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 case AOCONTROL_QUERY_FORMAT:
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
43 return CONTROL_TRUE;
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
44 case AOCONTROL_GET_VOLUME:
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
45 case AOCONTROL_SET_VOLUME:
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
46 return CONTROL_OK;
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
47 return CONTROL_ERROR;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
48 }
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
49 return CONTROL_UNKNOWN;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
50 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
51
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
52 // open & setup audio device
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
53 // return: 1=success 0=fail
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
54 static int init(int rate,int channels,int format,int flags)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
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
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
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
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
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
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
82 audio_out_format_name(ao_data.format), audio_out_format_name(format));
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
83
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
84 ao_data.channels=channels-1;
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
85 if( ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_data.channels) < 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
86 printf( "AO: [dxr3] Unable to set number of channels\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
87
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
88 ao_data.bps = (channels+1)*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
89 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
90 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
91 {
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
92 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
93 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
94 }
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 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
96 {
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
97 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
98 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
99 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
100 {
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 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
102 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
103 }
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 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
105 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
106 }
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
107 else printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,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
108 if(format == AFMT_AC3 ) ao_data.bps *= 2;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
109
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
110 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
111 {
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
112 int r=0;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
113 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
114 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
115 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
116 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_data.outburst );
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
117 }
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
118 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
119 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
120 ao_data.outburst=r;
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
121 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst);
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
122 }
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
123 }
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
124 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
125 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
126 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n",
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
127 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
128 ao_data.buffersize=(dxr3_buf_info.bytes/2);
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
129 ao_data.outburst=dxr3_buf_info.fragsize;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
130 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
131
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
132 ioval = EM8300_PLAYMODE_PLAY;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
133 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
134 printf( "AO: [dxr3] Unable to set playmode\n" );
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
135 close( fd_control );
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
136
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
137 return 1;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
138 }
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 // close audio device
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
141 static void uninit()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
142 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
143 printf( "AO: [dxr3] Uninitializing\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
144 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
145 printf( "AO: [dxr3] Unable to reset device\n" );
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
146 close( fd_audio );
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
147 close( fd_control ); /* Just in case */
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
148 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
149
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
150 // stop playing and empty buffers (for seeking/pause)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
151 static void reset()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
152 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
153 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
154 printf( "AO: [dxr3] Unable to reset device\n" );
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
155 }
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 // stop playing, keep buffers (for pause)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
158 static void audio_pause()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
159 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
160 int ioval;
3201
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
161 reset();
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
162 fd_control = open( "/dev/em8300", O_WRONLY );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
163 if( fd_control < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
164 printf( "AO: [dxr3] Oops, unable to pause playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
165 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
166 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
167 ioval = EM8300_PLAYMODE_PAUSED;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
168 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
169 printf( "AO: [dxr3] Unable to pause playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
170 close( fd_control );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
171 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
172 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
173
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
174 // resume playing, after audio_pause()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
175 static void audio_resume()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
176 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
177 int ioval;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
178 fd_control = open( "/dev/em8300", O_WRONLY );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
179 if( fd_control < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
180 printf( "AO: [dxr3] Oops, unable to resume playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
181 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
182 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
183 ioval = EM8300_PLAYMODE_PLAY;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
184 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
185 printf( "AO: [dxr3] Unable to resume playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
186 close( fd_control );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
187 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
188 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
189
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
190 // return: how many bytes can be played without blocking
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
191 static int get_space()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
192 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
193 int space = 0;
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
194 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &space) < 0 )
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
195 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
196 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
197 return ao_data.outburst;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
198 }
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
199 space = ao_data.buffersize - space;
3201
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
200 space /= ao_data.outburst; /* This is a smart way of doing a fast modulo reduction */
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
201 space *= ao_data.outburst; /* fetched from ao_mpegpes.c */
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
202 return space;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
203 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
204
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
205 // 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
206 // 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
207 // return: number of bytes played
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
208 static int play(void* data,int len,int flags)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
209 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
210 if( ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_data.pts ) < 0 )
3201
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
211 printf( "AO: [dxr3] Unable to set PTS\n" );
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
212 if( ao_data.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
213 {
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 int i,j,ratio,len2;
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 unsigned char *data2,*s,*d;
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
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
217 ratio = 44100/ao_data.samplerate;ratio/=2;ratio*=2;
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
218 len2 = len * ratio;
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
219 data2 = malloc(len2);
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
220
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
221 s = 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
222 d = data2;
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
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
224 //Upsampler
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
225 if( ao_data.format == AFMT_U8 )
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 {
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
227 for(i=0;i<ratio/2;i++)
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
228 for(j=0;j<len;j++)
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
229 {
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
230 *d = *s;
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
231 d++;
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 *d = *s;
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
233 d++;s++;
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
234 }
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
235 }
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
236 else
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
237 {
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
238 for(i=0;i<ratio/2;i++)
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
239 for(j=0;j<len/2;j++)
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
240 {
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
241 *d = *s;
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
242 d++;s++;
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
243 *d = *s;
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
244 d++;s--;
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
245 *d = *s;
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
246 d++;s++;
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
247 *d = *s;
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
248 d++;s++;
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
249 }
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
250 }
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 if( len2 < 0 ) return 0;
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 write(fd_audio,data2,len2);
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 len;
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
254 }
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
255 return write(fd_audio,data,len);
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
256 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
257
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
258 // return: delay in seconds between first and last sample in buffer
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
259 static float get_delay()
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
260 {
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
261 int r=0;
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
262 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 )
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
263 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
264 printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
265 return ((float)ao_data.buffersize)/(float)ao_data.bps;
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
266 }
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
267 return (((float)r)/(float)ao_data.bps);
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
268 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
269