~medibuntu-maintainers/mplayer/medibuntu.oneiric

« back to all changes in this revision

Viewing changes to libaf/af_resample.c

  • Committer: Gauvain Pocentek
  • Date: 2010-09-25 09:39:02 UTC
  • mfrom: (66.1.6 maverick)
  • Revision ID: gauvain@images-20100925093902-9q2akz3ls3qzhaaw
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* merge from debian, remaining changes:
  - build depend against, lame, x264, xvid
* debian/patches/60eval-api.patch, backport patch from upstream to
  unbreak compilation for eval.h move not yet in 0.6
* gmplayer is gone now, please see smplayer as alternative frontend.
  LP: #503537, #493088, #467534, #467524, #460326, #390399, #285570,
      #208680, #118709, #513065, #459595, #455913, #179918, #65165.
* enable the mencoder package
* sort build depends alphabetically
* enable dvdnav support, Closes: #582508, #488226, LP: #611749
* prepare new upload
* no longer build mplayer-gui, it doesn't build anymore with shared
  swscale
* merge from debian/experimental, remaining changes:
  - build depend against, lame, x264, xvid
  - enable mencoder and mplayer-gui
* ensure that quilt patches are actually applied
* New Upstream Version, LP: #539315
* Build (against) again the System FFmpeg 
* tighten dependency on FFmpeg 0.6
* remove patches merged upstream
* remove 22disable-xscreensaver.patch
* refresh patches
* readd x264, xvid and mp3lame support, LP: #606125
* remove old parallel building mechanism, fixes FTBFS
* New upstream version
* compile against internal ffmpeg for now, LP: #587203, #588097
* recompile for directfb transtion, LP: #587163
* remove patches that were merged upstream
* avoid removing DOCS/html directory. it is included in release
  tarball
* convert to source Format: 3.0 (quilt)
* refreshed patches
* remove files that are included in upstream tarball
* rework debian/rules file
  - support parallel building
  - merge build rules for mplayer and mencoder package
  - remove unreferenced COMMON_CONFIGURE_FLAGS macro
  - rename DEB_BUILD_CONFIGURE -> CONFIGURE_FLAGS
  - don't build documentation - release tarballs have them prebuilt
  - build HTML documentation only if not already avaiable in the build
    tree
  - remove remaining references to debian/strip.sh from debian/rules
* remove copied vdpau headers
* copy in mencoder.c from upstream
* enable mplayer-gui (Closes: #579925) and mencoder packages. 
  (Closes: #396954, #400940, #580168)
* Fix rtsp vulnerability. Patch applied by DSA. Closes: #581245
* Fix another integer overflow, Closes: #524805
* prepare new upload
* sync libao2/ao_pulse.c with svn r30062, Closes: #558196, #580113
* make configure use pkg-config for fribidi checks. Closes: #582784,
  LP: #556200
* document 23mplayer-debug-printf.patch
* avoid mentioning of GTK frontend in mplayer description
* improve package descriptions of mplayer-doc and mplayer-dbg
* medium urgency because of fixed security issue
* fix SVN_VERION regex in debian rules to unbreak get-orig-source
  target. Closes: #582369
* forcefully disable arts support. Closes: #581225
* Remove mencoder from Depends in mplayer-dbg package.
* new upstream snapshot from rc3 branch.
* remove patches applied upstream:
  
  - 24_enable_fontconfig_by_default.diff
  - 30_add_gmplayer_man_rules.diff
  - 40_improve_desktop_file.patch
  - 41_fix_forcedsubsonly.patch
  - 50_fix_crashes_with_invalid_SDPs.patch
  - 50_fix_initial_volume_setting_pulse_output.patch
  - 61-malloc-bsd.patch
  - 62-disable-vidix-on-kfreebsd-amd64.patch
  - 63-sys-kd-include.patch
* don't install apport hook
* gross hack to avoid building mplayer-nogui and mplayer-gui packages
* add md5sum to remove to avoid spurious conffile prompt, Closes: #568272
* Make mplayer build on kFreeBSD (backports from upstream), Closes: #578622
  - Revert obscure hack that disables the malloc.h check on certain BSD
    platforms. 
  - disable vidix on kFreeBSD-amd64
  - rename 'struct keypad' -> 'struct m_keypad' to avoid FTBFS on
    kFreeBSD/amd64
* enable fontconfig by default. (Closes: #573257)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
   length of the filter. This definition affects the computational
35
35
   complexity (see play()), the performance (see filter.h) and the
36
36
   memory usage. The filter length is chosen to 8 if the machine is
37
 
   slow and to 16 if the machine is fast and has MMX.  
 
37
   slow and to 16 if the machine is fast and has MMX.
38
38
*/
39
39
 
40
40
#if !HAVE_MMX // This machine is slow
41
 
#define L8 
 
41
#define L8
42
42
#else
43
43
#define L16
44
44
#endif
47
47
 
48
48
// Filtering types
49
49
#define RSMP_LIN        (0<<0)  // Linear interpolation
50
 
#define RSMP_INT        (1<<0)  // 16 bit integer 
 
50
#define RSMP_INT        (1<<0)  // 16 bit integer
51
51
#define RSMP_FLOAT      (2<<0)  // 32 bit floating point
52
52
#define RSMP_MASK       (3<<0)
53
53
 
66
66
  void**        xq;     // Circular buffers
67
67
  uint32_t      xi;     // Index for circular buffers
68
68
  uint32_t      wi;     // Index for w
69
 
  uint32_t      i;      // Number of new samples to put in x queue 
 
69
  uint32_t      i;      // Number of new samples to put in x queue
70
70
  uint32_t      dn;     // Down sampling factor
71
 
  uint32_t      up;     // Up sampling factor 
 
71
  uint32_t      up;     // Up sampling factor
72
72
  uint64_t      step;   // Step size for linear interpolation
73
73
  uint64_t      pt;     // Pointer remainder for linear interpolation
74
74
  int           setup;  // Setup parameters cmdline or through postcreate
79
79
{
80
80
  uint32_t      len   = 0;              // Number of input samples
81
81
  uint32_t      nch   = l->nch;         // Words pre transfer
82
 
  uint64_t      step  = s->step; 
 
82
  uint64_t      step  = s->step;
83
83
  int16_t*      in16  = ((int16_t*)c->audio);
84
84
  int16_t*      out16 = ((int16_t*)l->audio);
85
85
  int32_t*      in32  = ((int32_t*)c->audio);
87
87
  uint64_t      end   = ((((uint64_t)c->len)/2LL)<<STEPACCURACY);
88
88
  uint64_t      pt    = s->pt;
89
89
  uint16_t      tmp;
90
 
  
 
90
 
91
91
  switch (nch){
92
92
  case 1:
93
93
    while(pt < end){
94
 
      out16[len++]=in16[pt>>STEPACCURACY];          
 
94
      out16[len++]=in16[pt>>STEPACCURACY];
95
95
      pt+=step;
96
96
    }
97
97
    s->pt=pt & ((1LL<<STEPACCURACY)-1);
98
 
    break;              
 
98
    break;
99
99
  case 2:
100
100
    end/=2;
101
101
    while(pt < end){
102
 
      out32[len++]=in32[pt>>STEPACCURACY];          
 
102
      out32[len++]=in32[pt>>STEPACCURACY];
103
103
      pt+=step;
104
104
    }
105
105
    len=(len<<1);
106
106
    s->pt=pt & ((1LL<<STEPACCURACY)-1);
107
107
    break;
108
 
  default:      
 
108
  default:
109
109
    end /=nch;
110
110
    while(pt < end){
111
111
      tmp=nch;
112
 
      do {       
113
 
        tmp--;   
114
 
        out16[len+tmp]=in16[tmp+(pt>>STEPACCURACY)*nch];            
 
112
      do {
 
113
        tmp--;
 
114
        out16[len+tmp]=in16[tmp+(pt>>STEPACCURACY)*nch];
115
115
      } while (tmp);
116
116
      len+=nch;
117
117
      pt+=step;
118
 
    }   
 
118
    }
119
119
    s->pt=pt & ((1LL<<STEPACCURACY)-1);
120
120
  }
121
121
  return len;
128
128
  int rv = AF_OK;
129
129
  float rd = 0;
130
130
 
131
 
  // Make sure this filter isn't redundant 
 
131
  // Make sure this filter isn't redundant
132
132
  if((af->data->rate == data->rate) || (af->data->rate == 0))
133
133
    return AF_DETACH;
134
134
  /* If sloppy and small resampling difference (2%) */
135
135
  rd = abs((float)af->data->rate - (float)data->rate)/(float)data->rate;
136
 
  if((((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (rd < 0.02) && 
137
 
      (data->format != (AF_FORMAT_FLOAT_NE))) || 
 
136
  if((((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (rd < 0.02) &&
 
137
      (data->format != (AF_FORMAT_FLOAT_NE))) ||
138
138
     ((s->setup & RSMP_MASK) == RSMP_LIN)){
139
139
    s->setup = (s->setup & ~RSMP_MASK) | RSMP_LIN;
140
140
    af->data->format = AF_FORMAT_S16_NE;
141
141
    af->data->bps    = 2;
142
 
    af_msg(AF_MSG_VERBOSE,"[resample] Using linear interpolation. \n");
 
142
    mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Using linear interpolation. \n");
143
143
  }
144
144
  else{
145
145
    /* If the input format is float or if float is explicitly selected
146
146
       use float, otherwise use int */
147
 
    if((data->format == (AF_FORMAT_FLOAT_NE)) || 
 
147
    if((data->format == (AF_FORMAT_FLOAT_NE)) ||
148
148
       ((s->setup & RSMP_MASK) == RSMP_FLOAT)){
149
149
      s->setup = (s->setup & ~RSMP_MASK) | RSMP_FLOAT;
150
150
      af->data->format = AF_FORMAT_FLOAT_NE;
155
155
      af->data->format = AF_FORMAT_S16_NE;
156
156
      af->data->bps    = 2;
157
157
    }
158
 
    af_msg(AF_MSG_VERBOSE,"[resample] Using %s processing and %s frequecy"
 
158
    mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Using %s processing and %s frequecy"
159
159
           " conversion.\n",
160
160
           ((s->setup & RSMP_MASK) == RSMP_FLOAT)?"floating point":"integer",
161
161
           ((s->setup & FREQ_MASK) == FREQ_SLOPPY)?"inexact":"exact");
174
174
{
175
175
  switch(cmd){
176
176
  case AF_CONTROL_REINIT:{
177
 
    af_resample_t* s   = af->setup; 
 
177
    af_resample_t* s   = af->setup;
178
178
    af_data_t*     n   = arg; // New configuration
179
179
    int            i,d = 0;
180
180
    int            rv  = AF_OK;
188
188
 
189
189
    if(AF_DETACH == (rv = set_types(af,n)))
190
190
      return AF_DETACH;
191
 
    
192
 
    // If linear interpolation 
 
191
 
 
192
    // If linear interpolation
193
193
    if((s->setup & RSMP_MASK) == RSMP_LIN){
194
194
      s->pt=0LL;
195
195
      s->step=((uint64_t)n->rate<<STEPACCURACY)/(uint64_t)af->data->rate+1LL;
196
 
      af_msg(AF_MSG_DEBUG0,"[resample] Linear interpolation step: 0x%016"PRIX64".\n",
 
196
      mp_msg(MSGT_AFILTER, MSGL_DBG2, "[resample] Linear interpolation step: 0x%016"PRIX64".\n",
197
197
             s->step);
198
198
      af->mul = (double)af->data->rate / n->rate;
199
199
      return rv;
227
227
      float* wt;
228
228
      float fc;
229
229
      int j;
230
 
      s->up = af->data->rate/d; 
 
230
      s->up = af->data->rate/d;
231
231
      s->dn = n->rate/d;
232
232
      s->wi = 0;
233
233
      s->i = 0;
234
 
      
 
234
 
235
235
      // Calculate cutoff frequency for filter
236
236
      fc = 1/(float)(max(s->up,s->dn));
237
237
      // Allocate space for polyphase filter bank and prototype filter
241
241
      s->w = malloc(L*s->up*af->data->bps);
242
242
 
243
243
      // Design prototype filter type using Kaiser window with beta = 10
244
 
      if(NULL == w || NULL == s->w || 
 
244
      if(NULL == w || NULL == s->w ||
245
245
         -1 == af_filter_design_fir(s->up*L, w, &fc, LP|KAISER , 10.0)){
246
 
        af_msg(AF_MSG_ERROR,"[resample] Unable to design prototype filter.\n");
 
246
        mp_msg(MSGT_AFILTER, MSGL_ERR, "[resample] Unable to design prototype filter.\n");
247
247
        return AF_ERROR;
248
248
      }
249
249
      // Copy data from prototype to polyphase filter
260
260
        }
261
261
      }
262
262
      free(w);
263
 
      af_msg(AF_MSG_VERBOSE,"[resample] New filter designed up: %i "
 
263
      mp_msg(MSGT_AFILTER, MSGL_V, "[resample] New filter designed up: %i "
264
264
             "down: %i\n", s->up, s->dn);
265
265
    }
266
266
 
270
270
    return rv;
271
271
  }
272
272
  case AF_CONTROL_COMMAND_LINE:{
273
 
    af_resample_t* s   = af->setup; 
 
273
    af_resample_t* s   = af->setup;
274
274
    int rate=0;
275
275
    int type=RSMP_INT;
276
276
    int sloppy=1;
277
277
    sscanf((char*)arg,"%i:%i:%i", &rate, &sloppy, &type);
278
 
    s->setup = (sloppy?FREQ_SLOPPY:FREQ_EXACT) | 
 
278
    s->setup = (sloppy?FREQ_SLOPPY:FREQ_EXACT) |
279
279
      (clamp(type,RSMP_LIN,RSMP_FLOAT));
280
280
    return af->control(af,AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET, &rate);
281
281
  }
282
 
  case AF_CONTROL_POST_CREATE:  
 
282
  case AF_CONTROL_POST_CREATE:
283
283
    if((((af_cfg_t*)arg)->force & AF_INIT_FORMAT_MASK) == AF_INIT_FLOAT)
284
284
      ((af_resample_t*)af->setup)->setup = RSMP_FLOAT;
285
285
    return AF_OK;
286
 
  case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET: 
 
286
  case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
287
287
    // Reinit must be called after this function has been called
288
 
    
 
288
 
289
289
    // Sanity check
290
290
    if(((int*)arg)[0] < 8000 || ((int*)arg)[0] > 192000){
291
 
      af_msg(AF_MSG_ERROR,"[resample] The output sample frequency " 
 
291
      mp_msg(MSGT_AFILTER, MSGL_ERR, "[resample] The output sample frequency "
292
292
             "must be between 8kHz and 192kHz. Current value is %i \n",
293
293
             ((int*)arg)[0]);
294
294
      return AF_ERROR;
295
295
    }
296
296
 
297
 
    af->data->rate=((int*)arg)[0]; 
298
 
    af_msg(AF_MSG_VERBOSE,"[resample] Changing sample rate "  
 
297
    af->data->rate=((int*)arg)[0];
 
298
    mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Changing sample rate "
299
299
           "to %iHz\n",af->data->rate);
300
300
    return AF_OK;
301
301
  }
302
302
  return AF_UNKNOWN;
303
303
}
304
304
 
305
 
// Deallocate memory 
 
305
// Deallocate memory
306
306
static void uninit(struct af_instance_s* af)
307
307
{
308
308
  af_resample_t *s = af->setup;
335
335
    if(s->up>s->dn){
336
336
#     define UP
337
337
#     include "af_resample_template.c"
338
 
#     undef UP 
 
338
#     undef UP
339
339
    }
340
340
    else{
341
341
#     define DN
349
349
    if(s->up>s->dn){
350
350
#     define UP
351
351
#     include "af_resample_template.c"
352
 
#     undef UP 
 
352
#     undef UP
353
353
    }
354
354
    else{
355
355
#     define DN
366
366
  c->audio = l->audio;
367
367
  c->len   = len*l->bps;
368
368
  c->rate  = l->rate;
369
 
  
 
369
 
370
370
  return c;
371
371
}
372
372
 
393
393
  AF_FLAGS_REENTRANT,
394
394
  af_open
395
395
};
396