From 77c4523723436978f0c1f97f375d8400986ca81f Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sat, 8 Feb 2020 14:56:14 +0100 Subject: [PATCH] Byteswap captured audio samples on PPC Fixes: #161 --- include/mem.h | 8 ++++++++ src/hardware/mixer.cpp | 24 +++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/mem.h b/include/mem.h index d1d52858..5f1a5c54 100644 --- a/include/mem.h +++ b/include/mem.h @@ -116,6 +116,10 @@ static INLINE void host_writed(HostPt off,Bit32u val) { #if defined(WORDS_BIGENDIAN) +constexpr static INLINE int16_t host_to_le(int16_t val) { + return __builtin_bswap16(val); +} + constexpr static INLINE uint16_t host_to_le(uint16_t val) { return __builtin_bswap16(val); } @@ -126,6 +130,10 @@ constexpr static INLINE uint32_t host_to_le(uint32_t val) { #else +constexpr static INLINE int16_t host_to_le(int16_t val) { + return val; +} + constexpr static INLINE uint16_t host_to_le(uint16_t val) { return val; } diff --git a/src/hardware/mixer.cpp b/src/hardware/mixer.cpp index 96fac84e..0b8400a6 100644 --- a/src/hardware/mixer.cpp +++ b/src/hardware/mixer.cpp @@ -78,7 +78,7 @@ static INLINE Bit16s MIXER_CLIP(Bits SAMP) { } static struct { - Bit32s work[MIXER_BUFSIZE][2]; + int32_t work[MIXER_BUFSIZE][2]; //Write/Read pointers for the buffer Bitu pos,done; Bitu needed, min_needed, max_needed; @@ -497,19 +497,17 @@ static void MIXER_MixData(Bitu needed) { chan=chan->next; } if (CaptureState & (CAPTURE_WAVE|CAPTURE_VIDEO)) { - Bit16s convert[1024][2]; - Bitu added=needed-mixer.done; - if (added>1024) - added=1024; - Bitu readpos=(mixer.pos+mixer.done)&MIXER_BUFMASK; - for (Bitu i=0;i> MIXER_VOLSHIFT; - convert[i][0]=MIXER_CLIP(sample); - sample=mixer.work[readpos][1] >> MIXER_VOLSHIFT; - convert[i][1]=MIXER_CLIP(sample); - readpos=(readpos+1)&MIXER_BUFMASK; + int16_t convert[1024][2]; + const size_t added = std::min(needed - mixer.done, 1024); + size_t readpos = (mixer.pos + mixer.done) & MIXER_BUFMASK; + for (size_t i = 0; i < added; i++) { + const int32_t sample_1 = mixer.work[readpos][0] >> MIXER_VOLSHIFT; + const int32_t sample_2 = mixer.work[readpos][1] >> MIXER_VOLSHIFT; + convert[i][0] = host_to_le(MIXER_CLIP(sample_1)); + convert[i][1] = host_to_le(MIXER_CLIP(sample_2)); + readpos = (readpos + 1) & MIXER_BUFMASK; } - CAPTURE_AddWave( mixer.freq, added, (Bit16s*)convert ); + CAPTURE_AddWave(mixer.freq, added, reinterpret_cast(convert)); } //Reset the the tick_add for constant speed if( Mixer_irq_important() )