From ce5ef7a25449a1d0910d70fc8ce8136c2eadfb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Thu, 19 Mar 2009 20:45:42 +0000 Subject: [PATCH] fix 16bit mixer handling on bigendian machines (sb16 hdma, cdda for cd images), also see sf patches #1284246 and #1989569 Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3324 --- include/mixer.h | 12 ++++- src/dos/cdrom_image.cpp | 8 +++- src/hardware/mixer.cpp | 94 ++++++++++++++++++++++++++++++--------- src/hardware/sblaster.cpp | 14 +++++- 4 files changed, 102 insertions(+), 26 deletions(-) diff --git a/include/mixer.h b/include/mixer.h index b8e75926..a614f524 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2007 The DOSBox Team + * Copyright (C) 2002-2009 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $Id: mixer.h,v 1.17 2009-03-19 20:45:42 c2woody Exp $ */ + #ifndef DOSBOX_MIXER_H #define DOSBOX_MIXER_H @@ -50,7 +52,7 @@ public: void SetFreq(Bitu _freq); void Mix(Bitu _needed); void AddSilence(void); //Fill up until needed - template + template void AddSamples(Bitu len, const Type* data); void AddSamples_m8(Bitu len, const Bit8u * data); void AddSamples_s8(Bitu len, const Bit8u * data); @@ -62,6 +64,12 @@ public: void AddSamples_s16u(Bitu len, const Bit16u * data); void AddSamples_m32(Bitu len, const Bit32s * data); void AddSamples_s32(Bitu len, const Bit32s * data); + void AddSamples_m16_nonnative(Bitu len, const Bit16s * data); + void AddSamples_s16_nonnative(Bitu len, const Bit16s * data); + void AddSamples_m16u_nonnative(Bitu len, const Bit16u * data); + void AddSamples_s16u_nonnative(Bitu len, const Bit16u * data); + void AddSamples_m32_nonnative(Bitu len, const Bit32s * data); + void AddSamples_s32_nonnative(Bitu len, const Bit32s * data); void AddStretched(Bitu len,Bit16s * data); //Strech block up into needed data void FillUp(void); diff --git a/src/dos/cdrom_image.cpp b/src/dos/cdrom_image.cpp index 3b5983d7..32bb39a1 100644 --- a/src/dos/cdrom_image.cpp +++ b/src/dos/cdrom_image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2008 The DOSBox Team + * Copyright (C) 2002-2009 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: cdrom_image.cpp,v 1.23 2008-10-05 14:44:52 qbix79 Exp $ */ +/* $Id: cdrom_image.cpp,v 1.24 2009-03-19 20:45:42 c2woody Exp $ */ #include #include @@ -327,7 +327,11 @@ void CDROM_Interface_Image::CDAudioCallBack(Bitu len) } } SDL_mutexV(player.mutex); +#if defined(WORDS_BIGENDIAN) + player.channel->AddSamples_s16_nonnative(len/4,(Bit16s *)player.buffer); +#else player.channel->AddSamples_s16(len/4,(Bit16s *)player.buffer); +#endif memmove(player.buffer, &player.buffer[len], player.bufLen - len); player.bufLen -= len; } diff --git a/src/hardware/mixer.cpp b/src/hardware/mixer.cpp index 84d1a977..fc8a4d98 100644 --- a/src/hardware/mixer.cpp +++ b/src/hardware/mixer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2007 The DOSBox Team + * Copyright (C) 2002-2009 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: mixer.cpp,v 1.49 2009-03-16 18:33:59 harekiet Exp $ */ +/* $Id: mixer.cpp,v 1.50 2009-03-19 20:45:42 c2woody Exp $ */ /* Remove the sdl code from here and have it handeld in the sdlmain. @@ -174,7 +174,7 @@ void MixerChannel::AddSilence(void) { } } -template +template INLINE void MixerChannel::AddSamples(Bitu len, const Type* data) { Bits diff[2]; Bitu mixpos=mixer.pos+done; @@ -182,7 +182,7 @@ INLINE void MixerChannel::AddSamples(Bitu len, const Type* data) { Bitu pos=0;Bitu new_pos; goto thestart; - while (1) { + for (;;) { new_pos=freq_index >> MIXER_SHIFT; if (pos(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_s8(Bitu len,const Bit8u * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_m8s(Bitu len,const Bit8s * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_s8s(Bitu len,const Bit8s * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_m16(Bitu len,const Bit16s * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_s16(Bitu len,const Bit16s * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_m16u(Bitu len,const Bit16u * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_s16u(Bitu len,const Bit16u * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_m32(Bitu len,const Bit32s * data) { - AddSamples(len,data); + AddSamples(len,data); } void MixerChannel::AddSamples_s32(Bitu len,const Bit32s * data) { - AddSamples(len,data); + AddSamples(len,data); +} +void MixerChannel::AddSamples_m16_nonnative(Bitu len,const Bit16s * data) { + AddSamples(len,data); +} +void MixerChannel::AddSamples_s16_nonnative(Bitu len,const Bit16s * data) { + AddSamples(len,data); +} +void MixerChannel::AddSamples_m16u_nonnative(Bitu len,const Bit16u * data) { + AddSamples(len,data); +} +void MixerChannel::AddSamples_s16u_nonnative(Bitu len,const Bit16u * data) { + AddSamples(len,data); +} +void MixerChannel::AddSamples_m32_nonnative(Bitu len,const Bit32s * data) { + AddSamples(len,data); +} +void MixerChannel::AddSamples_s32_nonnative(Bitu len,const Bit32s * data) { + AddSamples(len,data); } void MixerChannel::FillUp(void) { diff --git a/src/hardware/sblaster.cpp b/src/hardware/sblaster.cpp index dd72b40f..2df1273d 100644 --- a/src/hardware/sblaster.cpp +++ b/src/hardware/sblaster.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2008 The DOSBox Team + * Copyright (C) 2002-2009 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: sblaster.cpp,v 1.71 2009-02-01 11:07:11 qbix79 Exp $ */ +/* $Id: sblaster.cpp,v 1.72 2009-03-19 20:45:42 c2woody Exp $ */ #include #include @@ -461,8 +461,13 @@ static void GenerateDMASound(Bitu size) { read=sb.dma.chan->Read(size,(Bit8u *)&sb.dma.buf.b16[sb.dma.remain_size]) >> (sb.dma.mode==DSP_DMA_16_ALIASED ? 1:0); Bitu total=read+sb.dma.remain_size; +#if defined(WORDS_BIGENDIAN) + if (sb.dma.sign) sb.chan->AddSamples_s16_nonnative(total>>1,sb.dma.buf.b16); + else sb.chan->AddSamples_s16u_nonnative(total>>1,(Bit16u *)sb.dma.buf.b16); +#else if (sb.dma.sign) sb.chan->AddSamples_s16(total>>1,sb.dma.buf.b16); else sb.chan->AddSamples_s16u(total>>1,(Bit16u *)sb.dma.buf.b16); +#endif if (total&1) { sb.dma.remain_size=1; sb.dma.buf.b16[0]=sb.dma.buf.b16[total-1]; @@ -470,8 +475,13 @@ static void GenerateDMASound(Bitu size) { } else { read=sb.dma.chan->Read(size,(Bit8u *)sb.dma.buf.b16) >> (sb.dma.mode==DSP_DMA_16_ALIASED ? 1:0); +#if defined(WORDS_BIGENDIAN) + if (sb.dma.sign) sb.chan->AddSamples_m16_nonnative(read,sb.dma.buf.b16); + else sb.chan->AddSamples_m16u_nonnative(read,(Bit16u *)sb.dma.buf.b16); +#else if (sb.dma.sign) sb.chan->AddSamples_m16(read,sb.dma.buf.b16); else sb.chan->AddSamples_m16u(read,(Bit16u *)sb.dma.buf.b16); +#endif } //restore buffer length value to byte size in aliased mode if (sb.dma.mode==DSP_DMA_16_ALIASED) read=read<<1;