Ticket #5890: soundtouch.patch

File soundtouch.patch, 12.5 KB (added by foobum@…, 15 years ago)
  • libs/libmythsoundtouch/cpu_detect_x86_gcc.cpp

     
    191191/// Checks which instruction set extensions are supported by the CPU.
    192192uint detectCPUextensions(void)
    193193{
    194 #ifdef ARCH_X86_64
    195     return 0;
    196 #endif
    197194#ifndef ARCH_X86
    198195    return 0; // always disable extensions on non-x86 platforms.
    199196#else
  • libs/libmythsoundtouch/libmythsoundtouch.pro

     
    99
    1010#build position independent code since the library is linked into a shared library
    1111QMAKE_CXXFLAGS += -fPIC -DPIC
    1212
     13contains(CONFIG_DEFINES, MMX) {
     14    DEFINES += ALLOW_MMX
     15}
     16
    1317QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)
    1418
    1519# Input
     
    2731SOURCES += TDStretch.cpp
    2832SOURCES += cpu_detect_x86_gcc.cpp
    2933SOURCES += mmx_gcc.cpp
     34SOURCES += sse_gcc.cpp
    3035
    3136include ( ../libs-targetfix.pro )
  • libs/libmythsoundtouch/TDStretch.cpp

     
    5151#include "STTypes.h"
    5252#include "cpu_detect.h"
    5353#include "TDStretch.h"
     54#include "config.h"
    5455
    5556using namespace soundtouch;
    5657
     
    804805
    805806    // Check if MMX/SSE/3DNow! instruction set extensions supported by CPU
    806807
     808#ifndef ARCH_X86_64
    807809#ifdef ALLOW_MMX
    808810    // MMX routines available only with integer sample types
    809811    if (uExtensions & MM_MMX)
     
    812814    }
    813815    else
    814816#endif // ALLOW_MMX
     817#endif // ARCH_X86_64
    815818
    816 
    817 #ifdef ALLOW_SSE
     819#ifdef ARCH_X86_64
    818820    if (uExtensions & MM_SSE)
    819821    {
    820822        // SSE support
    821823        return ::new TDStretchSSE;
    822824    }
    823825    else
    824 #endif // ALLOW_SSE
     826#endif // ARCH_x86_64
    825827
    826828
    827829#ifdef ALLOW_3DNOW
  • libs/libmythsoundtouch/sse_gcc.cpp

     
     1// SSE2 version of the expensive routines for 16 bit integer samples
     2#include "STTypes.h"
     3#include "TDStretch.h"
     4using namespace std;
     5using namespace soundtouch;
     6
     7#ifdef ALLOW_MMX
     8#ifdef ARCH_X86_64
     9long TDStretchSSE::calcCrossCorrMulti(const short *mPos, const short *cPos) const
     10{
     11       
     12    long corr = 0;
     13    int i, out[4];
     14    int count = (overlapLength * channels) - channels;
     15    long loops = count >> 5;
     16    long remainder = count - (loops<<5);
     17
     18    mPos += channels;
     19    cPos += channels;
     20
     21    asm(
     22        "xorps      %%xmm8, %%xmm8      \n\t"
     23        "movd       %4, %%xmm9          \n\t"
     24        "1:                             \n\t"
     25        "movupd     (%1), %%xmm0        \n\t"
     26        "movupd     16(%1), %%xmm2      \n\t"
     27        "movupd     32(%1), %%xmm4      \n\t"
     28        "movupd     48(%1), %%xmm6      \n\t"
     29        "movupd     (%2), %%xmm1        \n\t"
     30        "movupd     16(%2), %%xmm3      \n\t"
     31        "movupd     32(%2), %%xmm5      \n\t"
     32        "movupd     48(%2), %%xmm7      \n\t"
     33        "pmaddwd    %%xmm0, %%xmm1      \n\t"
     34        "pmaddwd    %%xmm2, %%xmm3      \n\t"
     35        "pmaddwd    %%xmm4, %%xmm5      \n\t"
     36        "pmaddwd    %%xmm6, %%xmm7      \n\t"
     37        "psrad      %%xmm9, %%xmm1      \n\t"
     38        "psrad      %%xmm9, %%xmm3      \n\t"
     39        "paddd      %%xmm1, %%xmm8      \n\t"
     40        "psrad      %%xmm9, %%xmm5      \n\t"
     41        "paddd      %%xmm3, %%xmm8      \n\t"
     42        "psrad      %%xmm9, %%xmm7      \n\t"
     43        "add        $64, %1             \n\t"
     44        "paddd      %%xmm5, %%xmm8      \n\t"
     45        "add        $64, %2             \n\t"
     46        "paddd      %%xmm7, %%xmm8      \n\t"
     47        "loop       1b                  \n\t"
     48        "movdqa     %%xmm8, %0          \n\t"
     49        :"=m"(out)
     50        :"r"(mPos), "r"(cPos), "c"(loops), "r"(overlapDividerBits)
     51    );
     52
     53    corr = out[0] + out[1] + out[2] + out[3];
     54
     55    mPos += loops<<5;
     56    cPos += loops<<5;
     57
     58    for (i = 0; i < remainder; i++)
     59        corr += (mPos[i] * cPos[i]) >> overlapDividerBits;
     60
     61    return corr;
     62
     63}
     64
     65long TDStretchSSE::calcCrossCorrStereo(const short *mPos, const short *cPos) const
     66{
     67       
     68    long corr = 0;
     69    int i, out[4];
     70    int count = (overlapLength<<1) - 2;
     71    long loops = count >> 5;
     72    long remainder = count - (loops<<5);
     73
     74    mPos += 2;
     75    cPos += 2;
     76
     77    asm(
     78        "xorps      %%xmm8, %%xmm8      \n\t"
     79        "movd       %4, %%xmm9          \n\t"
     80        "1:                             \n\t"
     81        "movupd     (%1), %%xmm0        \n\t"
     82        "movupd     16(%1), %%xmm2      \n\t"
     83        "movupd     32(%1), %%xmm4      \n\t"
     84        "movupd     48(%1), %%xmm6      \n\t"
     85        "movupd     (%2), %%xmm1        \n\t"
     86        "movupd     16(%2), %%xmm3      \n\t"
     87        "movupd     32(%2), %%xmm5      \n\t"
     88        "movupd     48(%2), %%xmm7      \n\t"
     89        "pmaddwd    %%xmm0, %%xmm1      \n\t"
     90        "pmaddwd    %%xmm2, %%xmm3      \n\t"
     91        "pmaddwd    %%xmm4, %%xmm5      \n\t"
     92        "pmaddwd    %%xmm6, %%xmm7      \n\t"
     93        "psrad      %%xmm9, %%xmm1      \n\t"
     94        "psrad      %%xmm9, %%xmm3      \n\t"
     95        "paddd      %%xmm1, %%xmm8      \n\t"
     96        "psrad      %%xmm9, %%xmm5      \n\t"
     97        "paddd      %%xmm3, %%xmm8      \n\t"
     98        "psrad      %%xmm9, %%xmm7      \n\t"
     99        "add        $64, %1             \n\t"
     100        "paddd      %%xmm5, %%xmm8      \n\t"
     101        "add        $64, %2             \n\t"
     102        "paddd      %%xmm7, %%xmm8      \n\t"
     103        "loop       1b                  \n\t"
     104        "movdqa     %%xmm8, %0          \n\t"
     105        :"=m"(out)
     106        :"r"(mPos), "r"(cPos), "c"(loops), "r"(overlapDividerBits)
     107    );
     108
     109    corr = out[0] + out[1] + out[2] + out[3];
     110
     111    mPos += loops<<5;
     112    cPos += loops<<5;
     113
     114    for (i = 0; i < remainder; i += 2)
     115        corr += (mPos[i] * cPos[i] +
     116                 mPos[i+1] * cPos[i+1]) >> overlapDividerBits;
     117
     118    return corr;
     119
     120}
     121
     122void TDStretchSSE::overlapMulti(short *output, const short *input) const
     123{
     124    unsigned long ones = 0x0001ffff0001ffffUL;
     125   
     126    asm(
     127        "movd       %%ecx, %%xmm0       \n\t"
     128        "punpckldq  %%xmm0, %%xmm0      \n\t"
     129        "shl        %6                  \n\t"
     130        "punpckldq  %%xmm0, %%xmm0      \n\t"
     131        "movd       %1, %%xmm1          \n\t"
     132        "movq       %2, %%xmm2          \n\t"
     133        "punpckldq  %%xmm2, %%xmm2      \n\t"
     134        "1:                             \n\t"
     135        "movdqu     (%3), %%xmm3        \n\t"
     136        "movdqu     (%4), %%xmm4        \n\t"
     137        "movdqu     %%xmm4, %%xmm5      \n\t"
     138        "punpcklwd  %%xmm3, %%xmm4      \n\t"
     139        "punpckhwd  %%xmm3, %%xmm5      \n\t"
     140        "add        %6, %3              \n\t"
     141        "pmaddwd    %%xmm0, %%xmm4      \n\t"
     142        "pmaddwd    %%xmm0, %%xmm5      \n\t"
     143        "psrad      %%xmm1, %%xmm4      \n\t"
     144        "psrad      %%xmm1, %%xmm5      \n\t"
     145        "add        %6, %4              \n\t"
     146        "packssdw   %%xmm5, %%xmm4      \n\t"
     147        "movdqu     %%xmm4, (%5)        \n\t"
     148        "add        %6, %5              \n\t"
     149        "paddw      %%xmm2, %%xmm0      \n\t"
     150        "loop       1b                  \n\t"
     151        ::"c"(overlapLength),"r"(overlapDividerBits),
     152        "r"(ones),"r"(input),"r"(pMidBuffer),"r"(output),
     153        "r"((long)channels)
     154    );
     155}
     156
     157void TDStretchSSE::overlapStereo(short *output, const short *input) const
     158{
     159    // 4 bytes per sample - use MMX
     160    unsigned long ones = 0x0001ffff0001ffffUL;
     161
     162    asm(
     163        "movd       %%ecx, %%mm0        \n\t"
     164        "shr        $1, %%ecx           \n\t"
     165        "punpckldq  %%mm0, %%mm0        \n\t"
     166        "movq       %1, %%mm1           \n\t"
     167        "movq       %%mm0, %%mm6        \n\t"
     168        "movq       %2, %%mm2           \n\t"
     169        "paddw      %%mm2, %%mm6        \n\t"
     170        "paddw      %%mm2, %%mm2        \n\t"
     171        "1:                             \n\t"
     172        "movq       (%3), %%mm3         \n\t"
     173        "movq       (%4), %%mm4         \n\t"
     174        "movq       %%mm4, %%mm5        \n\t"
     175        "punpcklwd  %%mm3, %%mm4        \n\t"
     176        "punpckhwd  %%mm3, %%mm5        \n\t"
     177        "add        $8, %3              \n\t"
     178        "pmaddwd    %%mm0, %%mm4        \n\t"
     179        "pmaddwd    %%mm6, %%mm5        \n\t"
     180        "psrad      %%mm1, %%mm4        \n\t"
     181        "psrad      %%mm1, %%mm5        \n\t"
     182        "add        $8, %4              \n\t"
     183        "packssdw   %%mm5, %%mm4        \n\t"
     184        "movq       %%mm4, (%5)         \n\t"
     185        "add        $8, %5              \n\t"
     186        "paddw      %%mm2, %%mm0        \n\t"
     187        "paddw      %%mm2, %%mm6        \n\t"
     188        "loop       1b                  \n\t"
     189        "emms                           \n\t"
     190        ::"c"(overlapLength),"r"((long)overlapDividerBits),
     191        "r"(ones),"r"(input),"r"(pMidBuffer),"r"(output)
     192    );
     193
     194}
     195#endif // ARCH_X86_64
     196#endif // ALLOW_MMX
  • libs/libmythsoundtouch/TDStretch.h

     
    4747#include "STTypes.h"
    4848#include "RateTransposer.h"
    4949#include "FIFOSamplePipe.h"
     50#include "config.h"
    5051
    5152#ifdef MULTICHANNEL
    5253#define USE_MULTI_MMX
     
    238239
    239240// Implementation-specific class declarations:
    240241
     242#ifndef ARCH_X86_64
    241243#ifdef ALLOW_MMX
    242244    /// Class that implements MMX optimized routines for 16bit integer samples type.
    243245    class TDStretchMMX : public TDStretch
     
    253255        virtual void clearCrossCorrState();
    254256    };
    255257#endif /// ALLOW_MMX
     258#endif /// ARCH_X86_64
    256259
    257260
    258261#ifdef ALLOW_3DNOW
     
    268271#endif /// ALLOW_3DNOW
    269272
    270273
    271 #ifdef ALLOW_SSE
    272     /// Class that implements SSE optimized routines for floating point samples type.
     274#ifdef ARCH_X86_64
     275    /// Class that implements SSE optimized routines for 16bit integer samples type.
    273276    class TDStretchSSE : public TDStretch
    274277    {
    275278    protected:
    276279#ifdef MULTICHANNEL
    277         //double calcCrossCorrMulti(const float *mixingPos, const float *compare) const;
     280        long calcCrossCorrMulti(const short *mixingPos, const short *compare) const;
    278281#endif
    279         double calcCrossCorrStereo(const float *mixingPos, const float *compare) const;
     282        long calcCrossCorrStereo(const short *mixingPos, const short *compare) const;
     283#ifdef MULTICHANNEL
     284        virtual void overlapMulti(short *output, const short *input) const;
     285#endif
     286        virtual void overlapStereo(short *output, const short *input) const;
    280287    };
     288#endif /// ARCH_X86_64
    281289
    282 #endif /// ALLOW_SSE
    283 
    284290}
    285291#endif  /// TDStretch_H
  • libs/libmythsoundtouch/mmx_gcc.cpp

     
    4444////////////////////////////////////////////////////////////////////////////////
    4545
    4646#include "STTypes.h"
     47#include "config.h"
    4748using namespace std;
    4849using namespace soundtouch;
    4950
     
    7071#include "cpu_detect.h"
    7172#include "TDStretch.h"
    7273
     74#ifndef ARCH_X86_64
     75
    7376// MMX routines available only with integer sample type   
    7477
    7578//////////////////////////////////////////////////////////////////////////////
     
    421424    _mm_empty();
    422425}
    423426#endif
     427#endif // ARCH_X86_64
    424428
    425429//////////////////////////////////////////////////////////////////////////////
    426430//
  • libs/libmythsoundtouch/FIFOSampleBuffer.cpp

     
    164164    if (capacityRequirement > getCapacity())
    165165    {
    166166        // enlarge the buffer in 4kbyte steps (round up to next 4k boundary)
    167         sizeInBytes = (capacityRequirement * channels * sizeof(SAMPLETYPE) + 4095) & -4096;
     167        sizeInBytes = (capacityRequirement * channels * sizeof(SAMPLETYPE) + 4099) & -4096;
    168168        assert(sizeInBytes % 2 == 0);
    169169        tempUnaligned = new SAMPLETYPE[sizeInBytes / sizeof(SAMPLETYPE) + 16 / sizeof(SAMPLETYPE)];
    170170        if (tempUnaligned == NULL)