mirror of
https://github.com/mpv-player/mpv
synced 2025-01-24 19:37:30 +01:00
On big-endian architectures, all audio decoders default to big-endian 16-bit
audio sample format. Add support to play both big- and little-endian 16-bit audio format to the sun audio_out driver. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1321 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
7b813ca0ec
commit
61bce79d66
@ -61,7 +61,11 @@ extern int init_acm_audio_codec(sh_audio_t *sh_audio);
|
|||||||
extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen);
|
extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen);
|
||||||
|
|
||||||
sh_audio->samplesize=2;
|
sh_audio->samplesize=2;
|
||||||
|
#if WORDS_BIGENDIAN
|
||||||
|
sh_audio->sample_format=AFMT_S16_BE;
|
||||||
|
#else
|
||||||
sh_audio->sample_format=AFMT_S16_LE;
|
sh_audio->sample_format=AFMT_S16_LE;
|
||||||
|
#endif
|
||||||
sh_audio->samplerate=0;
|
sh_audio->samplerate=0;
|
||||||
//sh_audio->pcm_bswap=0;
|
//sh_audio->pcm_bswap=0;
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ static int oss2sunfmt(int oss_format)
|
|||||||
return AUDIO_ENCODING_ULAW;
|
return AUDIO_ENCODING_ULAW;
|
||||||
case AFMT_A_LAW:
|
case AFMT_A_LAW:
|
||||||
return AUDIO_ENCODING_ALAW;
|
return AUDIO_ENCODING_ALAW;
|
||||||
|
case AFMT_S16_BE:
|
||||||
case AFMT_S16_LE:
|
case AFMT_S16_LE:
|
||||||
return AUDIO_ENCODING_LINEAR;
|
return AUDIO_ENCODING_LINEAR;
|
||||||
case AFMT_U8:
|
case AFMT_U8:
|
||||||
@ -248,7 +249,10 @@ static int init(int rate,int channels,int format,int flags){
|
|||||||
|
|
||||||
AUDIO_INITINFO(&info);
|
AUDIO_INITINFO(&info);
|
||||||
info.play.encoding = oss2sunfmt(ao_format = format);
|
info.play.encoding = oss2sunfmt(ao_format = format);
|
||||||
info.play.precision = (format==AFMT_S16_LE? AUDIO_PRECISION_16:AUDIO_PRECISION_8);
|
info.play.precision =
|
||||||
|
(format==AFMT_S16_LE || format==AFMT_S16_BE
|
||||||
|
? AUDIO_PRECISION_16
|
||||||
|
: AUDIO_PRECISION_8);
|
||||||
info.play.channels = ao_channels = channels;
|
info.play.channels = ao_channels = channels;
|
||||||
info.play.sample_rate = ao_samplerate = rate;
|
info.play.sample_rate = ao_samplerate = rate;
|
||||||
if(ioctl (audio_fd, AUDIO_SETINFO, &info)<0)
|
if(ioctl (audio_fd, AUDIO_SETINFO, &info)<0)
|
||||||
@ -331,7 +335,10 @@ static void reset(){
|
|||||||
|
|
||||||
AUDIO_INITINFO(&info);
|
AUDIO_INITINFO(&info);
|
||||||
info.play.encoding = oss2sunfmt(ao_format);
|
info.play.encoding = oss2sunfmt(ao_format);
|
||||||
info.play.precision = (ao_format==AFMT_S16_LE? AUDIO_PRECISION_16:AUDIO_PRECISION_8);
|
info.play.precision =
|
||||||
|
(ao_format==AFMT_S16_LE || ao_format==AFMT_S16_BE
|
||||||
|
? AUDIO_PRECISION_16
|
||||||
|
: AUDIO_PRECISION_8);
|
||||||
info.play.channels = ao_channels;
|
info.play.channels = ao_channels;
|
||||||
info.play.sample_rate = ao_samplerate;
|
info.play.sample_rate = ao_samplerate;
|
||||||
info.play.samples = 0;
|
info.play.samples = 0;
|
||||||
@ -390,16 +397,22 @@ static int get_space(){
|
|||||||
// it should round it down to outburst*n
|
// it should round it down to outburst*n
|
||||||
// return: number of bytes played
|
// return: number of bytes played
|
||||||
static int play(void* data,int len,int flags){
|
static int play(void* data,int len,int flags){
|
||||||
|
#if WORDS_BIGENDIAN
|
||||||
|
int native_endian = AFMT_S16_BE;
|
||||||
|
#else
|
||||||
|
int native_endian = AFMT_S16_LE;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (len < ao_outburst) return 0;
|
if (len < ao_outburst) return 0;
|
||||||
len /= ao_outburst;
|
len /= ao_outburst;
|
||||||
len *= ao_outburst;
|
len *= ao_outburst;
|
||||||
|
|
||||||
#if WORDS_BIGENDIAN
|
/* 16-bit format using the 'wrong' byteorder? swap words */
|
||||||
{
|
if ((ao_format == AFMT_S16_LE || ao_format == AFMT_S16_BE)
|
||||||
|
&& ao_format != native_endian) {
|
||||||
static void *swab_buf;
|
static void *swab_buf;
|
||||||
static int swab_len;
|
static int swab_len;
|
||||||
if (ao_format == AFMT_S16_LE && len > swab_len) {
|
if (len > swab_len) {
|
||||||
if (swab_buf)
|
if (swab_buf)
|
||||||
swab_buf = realloc(swab_buf, len);
|
swab_buf = realloc(swab_buf, len);
|
||||||
else
|
else
|
||||||
@ -410,7 +423,6 @@ static int play(void* data,int len,int flags){
|
|||||||
swab(data, swab_buf, len);
|
swab(data, swab_buf, len);
|
||||||
data = swab_buf;
|
data = swab_buf;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
len = write(audio_fd, data, len);
|
len = write(audio_fd, data, len);
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user