annotate libao2/ao_dxr3.c @ 3827:6e7df97bd120

Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk> Hardware sync-code activated
author mswitch
date Fri, 28 Dec 2001 10:20:16 +0000
parents 1e0052d8c532
children 6f2ae5226367
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"
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
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
19
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
20 void perror( const char *s );
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
21 #include <errno.h>
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
22 int sys_nerr;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
23 extern int verbose;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
24
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
25 static ao_info_t info =
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
26 {
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
27 "DXR3/H+ audio out",
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
28 "dxr3",
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
29 "David Holm <dholm@iname.com>",
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
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
33 LIBAO_EXTERN(dxr3)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
34
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
35 static audio_buf_info dxr3_buf_info;
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
36 static int fd_control = 0, fd_audio = 0;
3662
1e0052d8c532 Argh, forgot to make variable static...
mswitch
parents: 3660
diff changeset
37 static int need_conversion = 0;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
38
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
39 // to set/get/query special features/parameters
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
40 static int control(int cmd,int arg)
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 switch(cmd)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
43 {
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
44 case AOCONTROL_QUERY_FORMAT:
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
45 return CONTROL_TRUE;
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
46 case AOCONTROL_GET_VOLUME:
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
47 case AOCONTROL_SET_VOLUME:
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
48 return CONTROL_OK;
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
49 return CONTROL_ERROR;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
50 }
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
51 return CONTROL_UNKNOWN;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
52 }
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 // open & setup audio device
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
55 // return: 1=success 0=fail
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
56 static int init(int rate,int channels,int format,int flags)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
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
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
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
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
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
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
133
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
134 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
135 {
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
136 int r=0;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
137 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
138 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
139 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
140 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_data.outburst );
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
141 }
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
142 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
143 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
144 ao_data.outburst=r;
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
145 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst);
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
146 }
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
147 }
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
148 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
149 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
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
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
153 ao_data.outburst=dxr3_buf_info.fragsize;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
154 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
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
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
176 ioval = EM8300_PLAYMODE_PLAY;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
177 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
178 printf( "AO: [dxr3] Unable to set playmode\n" );
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
179 close( fd_control );
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
180
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
181 return 1;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
182 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
183
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
184 // close audio device
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
185 static void uninit()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
186 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
187 printf( "AO: [dxr3] Uninitializing\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
188 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
189 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
190 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
191 if(need_conversion & 0x2) audio_plugin_resample.uninit();
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
192 close( fd_audio );
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
193 close( fd_control ); /* Just in case */
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
194 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
195
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
196 // stop playing and empty buffers (for seeking/pause)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
197 static void reset()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
198 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
199 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
200 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
201 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
202 if(need_conversion & 0x2) audio_plugin_resample.reset();
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
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
205 // stop playing, keep buffers (for pause)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
206 static void audio_pause()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
207 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
208 int ioval;
3201
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
209 reset();
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
210 fd_control = open( "/dev/em8300", O_WRONLY );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
211 if( fd_control < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
212 printf( "AO: [dxr3] Oops, unable to pause playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
213 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
214 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
215 ioval = EM8300_PLAYMODE_PAUSED;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
216 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
217 printf( "AO: [dxr3] Unable to pause playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
218 close( fd_control );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
219 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
220 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
221
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
222 // resume playing, after audio_pause()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
223 static void audio_resume()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
224 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
225 int ioval;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
226 fd_control = open( "/dev/em8300", O_WRONLY );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
227 if( fd_control < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
228 printf( "AO: [dxr3] Oops, unable to resume playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
229 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
230 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
231 ioval = EM8300_PLAYMODE_PLAY;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
232 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
233 printf( "AO: [dxr3] Unable to resume playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
234 close( fd_control );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
235 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
236 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
237
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
238 // return: how many bytes can be played without blocking
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
239 static int get_space()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
240 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
241 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
242 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
243 {
3827
6e7df97bd120 Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents: 3662
diff changeset
244 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
245 return ao_data.outburst;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
246 }
3827
6e7df97bd120 Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents: 3662
diff changeset
247 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
248
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
249 return space;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
250 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
251
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
252 // 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
253 // 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
254 // return: number of bytes played
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
255 static int play(void* data,int len,int flags)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
256 {
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
257 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
258 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
259 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
260 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
261 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
262 if(need_conversion & 0x2) audio_plugin_resample.play();
3827
6e7df97bd120 Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents: 3662
diff changeset
263 if( ioctl(fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_data.pts) < 0 )
6e7df97bd120 Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents: 3662
diff changeset
264 printf( "AO: [dxr3] Unable to set pts\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
265 write(fd_audio,ao_plugin_data.data,ao_plugin_data.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
266 return size;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
267 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
268
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
269 // 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
270 static float get_delay()
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
271 {
3827
6e7df97bd120 Lots of fixes for digital audio output submitted by Steven Brookes <stevenjb@mda.co.uk>
mswitch
parents: 3662
diff changeset
272 return 0.0;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
273 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
274