annotate libao2/ao_dxr3.c @ 3755:b805040d6645

release todo
author arpi
date Wed, 26 Dec 2001 02:42:44 +0000
parents 1e0052d8c532
children 6e7df97bd120
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
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
82 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
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.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
85 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
86 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
87 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
88 {
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
89 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
90 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
91 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
92 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
93 }
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
3615
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
95 ao_data.channels=channels;
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
96 if(format != AFMT_AC3)
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
97 if(channels>2)
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
98 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
99 printf( "AO: [dxr3] Unable to set number of channels\n" );
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
100 else
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
101 {
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
102 int c = channels-1;
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
103 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
104 printf( "AO: [dxr3] Unable to set number of channels for AC3\n" );
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
105 }
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
106
3615
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
107 ao_data.bps = channels*rate;
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
108 if(format != AFMT_U8 && format != AFMT_S8)
2a75bbac913e Remove lame upsampler, cleaned out stuff relating to setting channels.
mswitch
parents: 3387
diff changeset
109 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
110 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
111 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
112 {
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
113 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
114 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
115 }
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
116 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
117 {
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
118 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
119 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
120 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
121 }
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 if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
124 {
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
125 int r=0;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
126 printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
127 if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
128 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
129 printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_data.outburst );
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
130 }
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
131 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
132 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
133 ao_data.outburst=r;
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
134 printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst);
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
135 }
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
136 }
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
137 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
138 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
139 printf("AO: [dxr3] frags: %3d/%d (%d bytes/frag) free: %6d\n",
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
140 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
141 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
142 ao_data.outburst=dxr3_buf_info.fragsize;
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
143 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
144
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
145 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
146 {
a515ff1954fd Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents: 3615
diff changeset
147
a515ff1954fd Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents: 3615
diff changeset
148 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
149 {
a515ff1954fd Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents: 3615
diff changeset
150 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
151 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
152 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
153 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
154 }
a515ff1954fd Added format conversion and resampling through pl_format and pl_resample. Someone please check my implementation for bugs.
mswitch
parents: 3615
diff changeset
155 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
156 {
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 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
158 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
159 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
160 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
161 }
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 }
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
163 ioval = EM8300_PLAYMODE_PLAY;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
164 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
165 printf( "AO: [dxr3] Unable to set playmode\n" );
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
166 close( fd_control );
2770
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
167
b9732eaa82d9 DXR3 beta2 patch by David Holm.
atmos4
parents: 2645
diff changeset
168 return 1;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
169 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
170
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
171 // close audio device
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
172 static void uninit()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
173 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
174 printf( "AO: [dxr3] Uninitializing\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
175 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
176 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
177 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
178 if(need_conversion & 0x2) audio_plugin_resample.uninit();
2921
ee37c7fc3022 dxr3-patch4 by David Holm
arpi
parents: 2770
diff changeset
179 close( fd_audio );
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
180 close( fd_control ); /* Just in case */
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
181 }
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 // stop playing and empty buffers (for seeking/pause)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
184 static void reset()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
185 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
186 if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
187 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
188 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
189 if(need_conversion & 0x2) audio_plugin_resample.reset();
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
190 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
191
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
192 // stop playing, keep buffers (for pause)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
193 static void audio_pause()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
194 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
195 int ioval;
3201
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
196 reset();
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
197 fd_control = open( "/dev/em8300", O_WRONLY );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
198 if( fd_control < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
199 printf( "AO: [dxr3] Oops, unable to pause playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
200 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
201 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
202 ioval = EM8300_PLAYMODE_PAUSED;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
203 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
204 printf( "AO: [dxr3] Unable to pause playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
205 close( fd_control );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
206 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
207 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
208
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
209 // resume playing, after audio_pause()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
210 static void audio_resume()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
211 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
212 int ioval;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
213 fd_control = open( "/dev/em8300", O_WRONLY );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
214 if( fd_control < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
215 printf( "AO: [dxr3] Oops, unable to resume playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
216 else
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
217 {
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
218 ioval = EM8300_PLAYMODE_PLAY;
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
219 if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
220 printf( "AO: [dxr3] Unable to resume playback\n" );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
221 close( fd_control );
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
222 }
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
223 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
224
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
225 // return: how many bytes can be played without blocking
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
226 static int get_space()
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
227 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
228 int space = 0;
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
229 if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &space) < 0 )
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
230 {
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
231 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
232 return ao_data.outburst;
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
233 }
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
234 space = ao_data.buffersize - space;
3201
039a973b3dda Newest DXR3 patch (improved 1.0rc2) by David Holm.
atmos4
parents: 3186
diff changeset
235 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
236 space *= ao_data.outburst; /* fetched from ao_mpegpes.c */
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
237 return space;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
238 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
239
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
240 // 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
241 // 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
242 // return: number of bytes played
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
243 static int play(void* data,int len,int flags)
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
244 {
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
245 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
246 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
247 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
248 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
249 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
250 if(need_conversion & 0x2) audio_plugin_resample.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
251 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
252 return size;
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
253 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
254
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
255 // 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
256 static float get_delay()
2645
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 int r=0;
3186
1d4fb4d9aab5 Patch by D. Holm to make audio with dxr3 working.
atmos4
parents: 2968
diff changeset
259 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
260 {
2968
9989497ab31e Minor fixes by David.
atmos4
parents: 2921
diff changeset
261 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
262 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
263 }
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
264 return (((float)r)/(float)ao_data.bps);
2645
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
265 }
9d8d69fc517c ao_dxr3 by David Holm <dholm@telia.com>
arpi
parents:
diff changeset
266