From c3f4ff953293d0941ad9b68e60389b867053342f Mon Sep 17 00:00:00 2001 From: oparviai Date: Thu, 8 Nov 2012 18:53:01 +0000 Subject: [PATCH] Fixed pointer aligning for mingw64 compilation --- README.html | 31 +++++++++++++++++--------- include/STTypes.h | 12 ++++++++++ source/SoundTouch/FIFOSampleBuffer.cpp | 2 +- source/SoundTouch/TDStretch.cpp | 2 +- source/SoundTouch/mmx_optimized.cpp | 2 +- source/SoundTouch/sse_optimized.cpp | 6 ++--- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.html b/README.html index 110dd65..fc4c0aa 100644 --- a/README.html +++ b/README.html @@ -712,13 +712,23 @@ switch "-bpm"

Kudos for these people who have contributed to development or submitted bugfixes since SoundTouch v1.3.1:

Moral greetings to all other contributors and users also!

@@ -749,10 +761,9 @@ General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

-
+

- README.html file updated on 29-Sep-2012

+ README.html file updated on 8-Nov-2012

diff --git a/include/STTypes.h b/include/STTypes.h index 9ae26ff..c031952 100644 --- a/include/STTypes.h +++ b/include/STTypes.h @@ -42,6 +42,18 @@ typedef unsigned int uint; typedef unsigned long ulong; +// Patch for MinGW: on Win64 long is 32-bit +#ifdef _WIN64 + typedef unsigned long long ulongptr; +#else + typedef ulong ulongptr; +#endif + + +// Helper macro for aligning pointer up to next 16-byte boundary +#define SOUNDTOUCH_ALIGN_POINTER_16(x) ( ( (ulongptr)(x) + 15 ) & ~(ulongptr)15 ) + + #ifdef __GNUC__ // In GCC, include soundtouch_config.h made by config scritps #include "soundtouch_config.h" diff --git a/source/SoundTouch/FIFOSampleBuffer.cpp b/source/SoundTouch/FIFOSampleBuffer.cpp index 9e624c9..b3f84cd 100644 --- a/source/SoundTouch/FIFOSampleBuffer.cpp +++ b/source/SoundTouch/FIFOSampleBuffer.cpp @@ -177,7 +177,7 @@ void FIFOSampleBuffer::ensureCapacity(uint capacityRequirement) ST_THROW_RT_ERROR("Couldn't allocate memory!\n"); } // Align the buffer to begin at 16byte cache line boundary for optimal performance - temp = (SAMPLETYPE *)(((ulong)tempUnaligned + 15) & (ulong)-16); + temp = (SAMPLETYPE *)SOUNDTOUCH_ALIGN_POINTER_16(tempUnaligned); if (samplesInBuffer) { memcpy(temp, ptrBegin(), samplesInBuffer * channels * sizeof(SAMPLETYPE)); diff --git a/source/SoundTouch/TDStretch.cpp b/source/SoundTouch/TDStretch.cpp index 54aee42..e272811 100644 --- a/source/SoundTouch/TDStretch.cpp +++ b/source/SoundTouch/TDStretch.cpp @@ -590,7 +590,7 @@ void TDStretch::acceptNewOverlapLength(int newOverlapLength) pMidBufferUnaligned = new SAMPLETYPE[overlapLength * 2 + 16 / sizeof(SAMPLETYPE)]; // ensure that 'pMidBuffer' is aligned to 16 byte boundary for efficiency - pMidBuffer = (SAMPLETYPE *)((((ulong)pMidBufferUnaligned) + 15) & (ulong)-16); + pMidBuffer = (SAMPLETYPE *)SOUNDTOUCH_ALIGN_POINTER_16(pMidBufferUnaligned); clearMidBuffer(); } diff --git a/source/SoundTouch/mmx_optimized.cpp b/source/SoundTouch/mmx_optimized.cpp index 684bad0..a201b14 100644 --- a/source/SoundTouch/mmx_optimized.cpp +++ b/source/SoundTouch/mmx_optimized.cpp @@ -239,7 +239,7 @@ void FIRFilterMMX::setCoefficients(const short *coeffs, uint newLength, uint uRe // Ensure that filter coeffs array is aligned to 16-byte boundary delete[] filterCoeffsUnalign; filterCoeffsUnalign = new short[2 * newLength + 8]; - filterCoeffsAlign = (short *)(((ulong)filterCoeffsUnalign + 15) & -16); + filterCoeffsAlign = (short *)SOUNDTOUCH_ALIGN_POINTER_16(filterCoeffsUnalign); // rearrange the filter coefficients for mmx routines for (i = 0;i < length; i += 4) diff --git a/source/SoundTouch/sse_optimized.cpp b/source/SoundTouch/sse_optimized.cpp index ddafb08..7b4e45d 100644 --- a/source/SoundTouch/sse_optimized.cpp +++ b/source/SoundTouch/sse_optimized.cpp @@ -93,7 +93,7 @@ double TDStretchSSE::calcCrossCorr(const float *pV1, const float *pV2) const #define _MM_LOAD _mm_load_ps - if (((ulong)pV1) & 15) return -1e50; // skip unaligned locations + if (((ulongptr)pV1) & 15) return -1e50; // skip unaligned locations #else // No cheating allowed, use unaligned load & take the resulting @@ -218,7 +218,7 @@ void FIRFilterSSE::setCoefficients(const float *coeffs, uint newLength, uint uRe // Ensure that filter coeffs array is aligned to 16-byte boundary delete[] filterCoeffsUnalign; filterCoeffsUnalign = new float[2 * newLength + 4]; - filterCoeffsAlign = (float *)(((unsigned long)filterCoeffsUnalign + 15) & (ulong)-16); + filterCoeffsAlign = (float *)SOUNDTOUCH_ALIGN_POINTER_16(filterCoeffsUnalign); fDivider = (float)resultDivider; @@ -246,7 +246,7 @@ uint FIRFilterSSE::evaluateFilterStereo(float *dest, const float *source, uint n assert(dest != NULL); assert((length % 8) == 0); assert(filterCoeffsAlign != NULL); - assert(((ulong)filterCoeffsAlign) % 16 == 0); + assert(((ulongptr)filterCoeffsAlign) % 16 == 0); // filter is evaluated for two stereo samples with each iteration, thus use of 'j += 2' for (j = 0; j < count; j += 2)