summaryrefslogtreecommitdiffstats
path: root/libao2/ao_sun.c
diff options
context:
space:
mode:
authorjkeil <jkeil@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-08-31 20:34:17 +0000
committerjkeil <jkeil@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-08-31 20:34:17 +0000
commitac2fbcbf2551c1974f8a5701969492d235b9cdcb (patch)
treebd607113a9030dcd2f4acc1bde68428dc229e4cf /libao2/ao_sun.c
parent5b596b34132044c56758265119b9e9a49f4af650 (diff)
downloadmpv-ac2fbcbf2551c1974f8a5701969492d235b9cdcb.tar.bz2
mpv-ac2fbcbf2551c1974f8a5701969492d235b9cdcb.tar.xz
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
is available, convert to AFMT_S8 in software. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1808 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libao2/ao_sun.c')
-rw-r--r--libao2/ao_sun.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libao2/ao_sun.c b/libao2/ao_sun.c
index 7c7ec4c8aa..e32886dd1d 100644
--- a/libao2/ao_sun.c
+++ b/libao2/ao_sun.c
@@ -54,6 +54,7 @@ static char *audio_dev = "/dev/audio";
static int queued_bursts = 0;
static int queued_samples = 0;
static int bytes_per_sample = 0;
+static int convert_u8_s8;
static int audio_fd = -1;
static enum {
RTSC_UNKNOWN = 0,
@@ -230,6 +231,7 @@ static int init(int rate,int channels,int format,int flags){
audio_info_t info;
int byte_per_sec;
+ int ok;
if (ao_subdevice) audio_dev = ao_subdevice;
@@ -257,9 +259,23 @@ static int init(int rate,int channels,int format,int flags){
: AUDIO_PRECISION_8);
info.play.channels = ao_channels = channels;
info.play.sample_rate = ao_samplerate = rate;
- if(ioctl (audio_fd, AUDIO_SETINFO, &info)<0)
+ convert_u8_s8 = 0;
+ ok = ioctl(audio_fd, AUDIO_SETINFO, &info) >= 0;
+ if (!ok && info.play.encoding == AUDIO_ENCODING_LINEAR8) {
+ /* sun audiocs hardware does not support U8 format, try S8... */
+ info.play.encoding = AUDIO_ENCODING_LINEAR;
+ ok = ioctl(audio_fd, AUDIO_SETINFO, &info) >= 0;
+ if (ok) {
+ /* we must perform software U8 -> S8 conversion */
+ convert_u8_s8 = 1;
+ }
+ }
+ if (!ok) {
printf("audio_setup: your card doesn't support %d channel, %s, %d Hz samplerate\n",
channels, audio_out_format_name(format), rate);
+ return 0;
+ }
+
bytes_per_sample = channels * info.play.precision / 8;
byte_per_sec = bytes_per_sample * rate;
ao_outburst = byte_per_sec > 100000 ? 16384 : 8192;
@@ -424,6 +440,12 @@ static int play(void* data,int len,int flags){
}
swab(data, swab_buf, len);
data = swab_buf;
+ } else if (ao_format == AFMT_U8 && convert_u8_s8) {
+ int i;
+ unsigned char *p = data;
+
+ for (i = 0, p = data; i < len; i++, p++)
+ *p ^= 0x80;
}
len = write(audio_fd, data, len);