~ubuntu-branches/ubuntu/precise/gst-plugins-base0.10/precise-updates

« back to all changes in this revision

Viewing changes to gst/audioresample/resample.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2011-12-12 12:40:13 UTC
  • mfrom: (36.1.15 experimental)
  • Revision ID: package-import@ubuntu.com-20111212124013-onyadfb150d8c5dk
Tags: 0.10.35.2-2
* debian/libgstreamer-plugins-base.install:
  + Add license translations file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
#ifdef OUTSIDE_SPEEX
65
65
#include <stdlib.h>
66
66
 
 
67
#ifdef HAVE_STRING_H
 
68
#include <string.h>
 
69
#endif
 
70
 
67
71
#include <glib.h>
68
72
 
 
73
#ifdef HAVE_ORC
 
74
#include <orc/orc.h>
 
75
#endif
 
76
 
69
77
#define EXPORT G_GNUC_INTERNAL
70
78
 
 
79
#ifdef _USE_SSE
 
80
#ifndef HAVE_XMMINTRIN_H
 
81
#undef _USE_SSE
 
82
#endif
 
83
#endif
 
84
 
 
85
#ifdef _USE_SSE2
 
86
#ifndef HAVE_EMMINTRIN_H
 
87
#undef _USE_SSE2
 
88
#endif
 
89
#endif
 
90
 
71
91
static inline void *
72
92
speex_alloc (int size)
73
93
{
110
130
#define NULL 0
111
131
#endif
112
132
 
113
 
#ifdef _USE_SSE
 
133
#if defined _USE_SSE || defined _USE_SSE2
114
134
#include "resample_sse.h"
115
135
#endif
116
136
 
121
141
#define FIXED_STACK_ALLOC 1024
122
142
#endif
123
143
 
 
144
/* Allow selecting SSE or not when compiled with SSE support */
 
145
#ifdef _USE_SSE
 
146
#define SSE_FALLBACK(macro) \
 
147
  if (st->use_sse) goto sse_##macro##_sse; {
 
148
#define SSE_IMPLEMENTATION(macro) \
 
149
  goto sse_##macro##_end; } sse_##macro##_sse: {
 
150
#define SSE_END(macro) sse_##macro##_end:; }
 
151
#else
 
152
#define SSE_FALLBACK(macro)
 
153
#endif
 
154
 
 
155
#ifdef _USE_SSE2
 
156
#define SSE2_FALLBACK(macro) \
 
157
  if (st->use_sse2) goto sse2_##macro##_sse2; {
 
158
#define SSE2_IMPLEMENTATION(macro) \
 
159
  goto sse2_##macro##_end; } sse2_##macro##_sse2: {
 
160
#define SSE2_END(macro) sse2_##macro##_end:; }
 
161
#else
 
162
#define SSE2_FALLBACK(macro)
 
163
#endif
 
164
 
 
165
 
124
166
typedef int (*resampler_basic_func) (SpeexResamplerState *, spx_uint32_t,
125
167
    const spx_word16_t *, spx_uint32_t *, spx_word16_t *, spx_uint32_t *);
126
168
 
155
197
 
156
198
  int in_stride;
157
199
  int out_stride;
 
200
 
 
201
  int use_sse:1;
 
202
  int use_sse2:1;
158
203
};
159
204
 
160
205
static double kaiser12_table[68] = {
410
455
    const spx_word16_t *sinc = &sinc_table[samp_frac_num * N];
411
456
    const spx_word16_t *iptr = &in[last_sample];
412
457
 
413
 
#ifndef OVERRIDE_INNER_PRODUCT_SINGLE
 
458
    SSE_FALLBACK (INNER_PRODUCT_SINGLE)
414
459
    sum = 0;
415
460
    for (j = 0; j < N; j++)
416
461
      sum += MULT16_16 (sinc[j], iptr[j]);
417
462
 
418
463
/*    This code is slower on most DSPs which have only 2 accumulators.
419
 
      Plus this this forces truncation to 32 bits and you lose the HW guard bits.
 
464
      Plus this forces truncation to 32 bits and you lose the HW guard bits.
420
465
      I think we can trust the compiler and let it vectorize and/or unroll itself.
421
466
      spx_word32_t accum[4] = {0,0,0,0};
422
467
      for(j=0;j<N;j+=4) {
427
472
      }
428
473
      sum = accum[0] + accum[1] + accum[2] + accum[3];
429
474
*/
430
 
#else
 
475
#ifdef OVERRIDE_INNER_PRODUCT_SINGLE
 
476
    SSE_IMPLEMENTATION (INNER_PRODUCT_SINGLE)
431
477
    sum = inner_product_single (sinc, iptr, N);
 
478
    SSE_END(INNER_PRODUCT_SINGLE)
432
479
#endif
433
480
 
434
481
    out[out_stride * out_sample++] = SATURATE32 (PSHR32 (sum, 15), 32767);
471
518
    const spx_word16_t *sinc = &sinc_table[samp_frac_num * N];
472
519
    const spx_word16_t *iptr = &in[last_sample];
473
520
 
474
 
#ifndef OVERRIDE_INNER_PRODUCT_DOUBLE
 
521
    SSE2_FALLBACK (INNER_PRODUCT_DOUBLE)
475
522
    double accum[4] = { 0, 0, 0, 0 };
476
523
 
477
524
    for (j = 0; j < N; j += 4) {
481
528
      accum[3] += sinc[j + 3] * iptr[j + 3];
482
529
    }
483
530
    sum = accum[0] + accum[1] + accum[2] + accum[3];
484
 
#else
 
531
#ifdef OVERRIDE_INNER_PRODUCT_DOUBLE
 
532
    SSE2_IMPLEMENTATION (INNER_PRODUCT_DOUBLE)
485
533
    sum = inner_product_double (sinc, iptr, N);
 
534
    SSE2_END (INNER_PRODUCT_DOUBLE)
486
535
#endif
487
536
 
488
537
    out[out_stride * out_sample++] = PSHR32 (sum, 15);
534
583
    spx_word16_t interp[4];
535
584
 
536
585
 
537
 
#ifndef OVERRIDE_INTERPOLATE_PRODUCT_SINGLE
 
586
    SSE_FALLBACK (INTERPOLATE_PRODUCT_SINGLE)
538
587
    spx_word32_t accum[4] = { 0, 0, 0, 0 };
539
588
 
540
589
    for (j = 0; j < N; j++) {
559
608
            1)) + MULT16_32_Q15 (interp[1], SHR32 (accum[1],
560
609
            1)) + MULT16_32_Q15 (interp[2], SHR32 (accum[2],
561
610
            1)) + MULT16_32_Q15 (interp[3], SHR32 (accum[3], 1));
562
 
#else
 
611
#ifdef OVERRIDE_INTERPOLATE_PRODUCT_SINGLE
 
612
    SSE_IMPLEMENTATION (INTERPOLATE_PRODUCT_SINGLE)
563
613
    cubic_coef (frac, interp);
564
614
    sum =
565
615
        interpolate_product_single (iptr,
566
616
        st->sinc_table + st->oversample + 4 - offset - 2, N, st->oversample,
567
617
        interp);
 
618
    SSE_END (INTERPOLATE_PRODUCT_SINGLE)
568
619
#endif
569
620
 
570
621
    out[out_stride * out_sample++] = SATURATE32 (PSHR32 (sum, 14), 32767);
624
675
    spx_word16_t interp[4];
625
676
 
626
677
 
627
 
#ifndef OVERRIDE_INTERPOLATE_PRODUCT_DOUBLE
 
678
    SSE2_FALLBACK (INTERPOLATE_PRODUCT_DOUBLE)
628
679
    double accum[4] = { 0, 0, 0, 0 };
629
680
 
630
681
    for (j = 0; j < N; j++) {
648
699
        MULT16_32_Q15 (interp[0], accum[0]) + MULT16_32_Q15 (interp[1],
649
700
        accum[1]) + MULT16_32_Q15 (interp[2],
650
701
        accum[2]) + MULT16_32_Q15 (interp[3], accum[3]);
651
 
#else
 
702
#ifdef OVERRIDE_INTERPOLATE_PRODUCT_DOUBLE
 
703
    SSE2_IMPLEMENTATION (INTERPOLATE_PRODUCT_DOUBLE)
652
704
    cubic_coef (frac, interp);
653
705
    sum =
654
706
        interpolate_product_double (iptr,
655
707
        st->sinc_table + st->oversample + 4 - offset - 2, N, st->oversample,
656
708
        interp);
 
709
    SSE2_END (INTERPOLATE_PRODUCT_DOUBLE)
657
710
#endif
658
711
 
659
712
    out[out_stride * out_sample++] = PSHR32 (sum, 15);
875
928
      out_rate, quality, err);
876
929
}
877
930
 
 
931
#if defined HAVE_ORC && !defined DISABLE_ORC
 
932
static void
 
933
check_insn_set (SpeexResamplerState * st, const char *name)
 
934
{
 
935
  if (!name)
 
936
    return;
 
937
  if (!strcmp (name, "sse"))
 
938
    st->use_sse = 1;
 
939
  if (!strcmp (name, "sse2"))
 
940
    st->use_sse = st->use_sse2 = 1;
 
941
}
 
942
#endif
 
943
 
878
944
EXPORT SpeexResamplerState *
879
945
speex_resampler_init_frac (spx_uint32_t nb_channels, spx_uint32_t ratio_num,
880
946
    spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate,
912
978
  st->buffer_size = 160;
913
979
#endif
914
980
 
 
981
  st->use_sse = st->use_sse2 = 0;
 
982
#if defined HAVE_ORC && !defined DISABLE_ORC
 
983
  orc_init ();
 
984
  {
 
985
    OrcTarget *target = orc_target_get_default ();
 
986
    if (target) {
 
987
      unsigned int flags = orc_target_get_default_flags (target);
 
988
      check_insn_set (st, orc_target_get_name (target));
 
989
      for (i = 0; i < 32; ++i) {
 
990
        if (flags & (1 << i)) {
 
991
          check_insn_set (st, orc_target_get_flag_name (target, i));
 
992
        }
 
993
      }
 
994
    }
 
995
  }
 
996
#endif
 
997
 
915
998
  /* Per channel data */
916
999
  st->last_sample = (spx_int32_t *) speex_alloc (nb_channels * sizeof (int));
917
1000
  st->magic_samples = (spx_uint32_t *) speex_alloc (nb_channels * sizeof (int));