2009-01-05 12:41:40 +00:00
|
|
|
/*
|
|
|
|
* This audio filter changes the sample rate.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Anders Johansson ajh@atri.curtin.edu.au
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2007-11-01 06:52:06 +00:00
|
|
|
#include "libavutil/common.h"
|
2009-01-25 19:20:30 +00:00
|
|
|
#include "libavutil/mathematics.h"
|
2002-10-01 06:45:08 +00:00
|
|
|
#include "af.h"
|
|
|
|
#include "dsp.h"
|
|
|
|
|
|
|
|
/* Below definition selects the length of each poly phase component.
|
|
|
|
Valid definitions are L8 and L16, where the number denotes the
|
|
|
|
length of the filter. This definition affects the computational
|
|
|
|
complexity (see play()), the performance (see filter.h) and the
|
2009-03-06 11:31:18 +00:00
|
|
|
memory usage. The filter length is chosen to 8 if the machine is
|
2009-05-13 02:58:57 +00:00
|
|
|
slow and to 16 if the machine is fast and has MMX.
|
2002-10-01 06:45:08 +00:00
|
|
|
*/
|
|
|
|
|
2009-01-16 09:32:54 +00:00
|
|
|
#if !HAVE_MMX // This machine is slow
|
2009-05-13 02:58:57 +00:00
|
|
|
#define L8
|
2002-12-28 13:59:53 +00:00
|
|
|
#else
|
|
|
|
#define L16
|
|
|
|
#endif
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2009-01-02 16:13:22 +00:00
|
|
|
#include "af_resample_template.c"
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
// Filtering types
|
2003-01-10 01:01:38 +00:00
|
|
|
#define RSMP_LIN (0<<0) // Linear interpolation
|
2009-05-13 02:58:57 +00:00
|
|
|
#define RSMP_INT (1<<0) // 16 bit integer
|
2003-01-10 01:01:38 +00:00
|
|
|
#define RSMP_FLOAT (2<<0) // 32 bit floating point
|
|
|
|
#define RSMP_MASK (3<<0)
|
|
|
|
|
|
|
|
// Defines for sloppy or exact resampling
|
|
|
|
#define FREQ_SLOPPY (0<<2)
|
|
|
|
#define FREQ_EXACT (1<<2)
|
|
|
|
#define FREQ_MASK (1<<2)
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
// Accuracy for linear interpolation
|
|
|
|
#define STEPACCURACY 32
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
// local data
|
|
|
|
typedef struct af_resample_s
|
|
|
|
{
|
2002-12-28 13:59:53 +00:00
|
|
|
void* w; // Current filter weights
|
|
|
|
void** xq; // Circular buffers
|
2002-10-02 10:47:18 +00:00
|
|
|
uint32_t xi; // Index for circular buffers
|
|
|
|
uint32_t wi; // Index for w
|
2009-05-13 02:58:57 +00:00
|
|
|
uint32_t i; // Number of new samples to put in x queue
|
2002-10-02 10:47:18 +00:00
|
|
|
uint32_t dn; // Down sampling factor
|
2009-05-13 02:58:57 +00:00
|
|
|
uint32_t up; // Up sampling factor
|
2002-12-28 13:59:53 +00:00
|
|
|
uint64_t step; // Step size for linear interpolation
|
|
|
|
uint64_t pt; // Pointer remainder for linear interpolation
|
2003-01-10 01:01:38 +00:00
|
|
|
int setup; // Setup parameters cmdline or through postcreate
|
2002-10-01 06:45:08 +00:00
|
|
|
} af_resample_t;
|
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
// Fast linear interpolation resample with modest audio quality
|
|
|
|
static int linint(af_data_t* c,af_data_t* l, af_resample_t* s)
|
2002-10-01 06:45:08 +00:00
|
|
|
{
|
2002-12-28 13:59:53 +00:00
|
|
|
uint32_t len = 0; // Number of input samples
|
|
|
|
uint32_t nch = l->nch; // Words pre transfer
|
2009-05-13 02:58:57 +00:00
|
|
|
uint64_t step = s->step;
|
2002-12-28 13:59:53 +00:00
|
|
|
int16_t* in16 = ((int16_t*)c->audio);
|
|
|
|
int16_t* out16 = ((int16_t*)l->audio);
|
|
|
|
int32_t* in32 = ((int32_t*)c->audio);
|
|
|
|
int32_t* out32 = ((int32_t*)l->audio);
|
|
|
|
uint64_t end = ((((uint64_t)c->len)/2LL)<<STEPACCURACY);
|
|
|
|
uint64_t pt = s->pt;
|
|
|
|
uint16_t tmp;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
switch (nch){
|
|
|
|
case 1:
|
|
|
|
while(pt < end){
|
2009-05-13 02:58:57 +00:00
|
|
|
out16[len++]=in16[pt>>STEPACCURACY];
|
2002-12-28 13:59:53 +00:00
|
|
|
pt+=step;
|
|
|
|
}
|
|
|
|
s->pt=pt & ((1LL<<STEPACCURACY)-1);
|
2009-05-13 02:58:57 +00:00
|
|
|
break;
|
2002-12-28 13:59:53 +00:00
|
|
|
case 2:
|
|
|
|
end/=2;
|
|
|
|
while(pt < end){
|
2009-05-13 02:58:57 +00:00
|
|
|
out32[len++]=in32[pt>>STEPACCURACY];
|
2002-12-28 13:59:53 +00:00
|
|
|
pt+=step;
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
2002-12-28 13:59:53 +00:00
|
|
|
len=(len<<1);
|
|
|
|
s->pt=pt & ((1LL<<STEPACCURACY)-1);
|
|
|
|
break;
|
2009-05-13 02:58:57 +00:00
|
|
|
default:
|
2002-12-28 13:59:53 +00:00
|
|
|
end /=nch;
|
|
|
|
while(pt < end){
|
|
|
|
tmp=nch;
|
2009-05-13 02:58:57 +00:00
|
|
|
do {
|
|
|
|
tmp--;
|
|
|
|
out16[len+tmp]=in16[tmp+(pt>>STEPACCURACY)*nch];
|
2002-12-28 13:59:53 +00:00
|
|
|
} while (tmp);
|
|
|
|
len+=nch;
|
|
|
|
pt+=step;
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
2002-12-28 13:59:53 +00:00
|
|
|
s->pt=pt & ((1LL<<STEPACCURACY)-1);
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2003-01-10 01:01:38 +00:00
|
|
|
/* Determine resampling type and format */
|
|
|
|
static int set_types(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
|
|
|
af_resample_t* s = af->setup;
|
|
|
|
int rv = AF_OK;
|
|
|
|
float rd = 0;
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
// Make sure this filter isn't redundant
|
2003-01-10 01:01:38 +00:00
|
|
|
if((af->data->rate == data->rate) || (af->data->rate == 0))
|
|
|
|
return AF_DETACH;
|
|
|
|
/* If sloppy and small resampling difference (2%) */
|
|
|
|
rd = abs((float)af->data->rate - (float)data->rate)/(float)data->rate;
|
2009-05-13 02:58:57 +00:00
|
|
|
if((((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (rd < 0.02) &&
|
|
|
|
(data->format != (AF_FORMAT_FLOAT_NE))) ||
|
2003-01-10 01:01:38 +00:00
|
|
|
((s->setup & RSMP_MASK) == RSMP_LIN)){
|
|
|
|
s->setup = (s->setup & ~RSMP_MASK) | RSMP_LIN;
|
2004-12-27 17:30:15 +00:00
|
|
|
af->data->format = AF_FORMAT_S16_NE;
|
2003-01-10 01:01:38 +00:00
|
|
|
af->data->bps = 2;
|
2009-03-28 19:57:56 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Using linear interpolation. \n");
|
2003-01-10 01:01:38 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
/* If the input format is float or if float is explicitly selected
|
|
|
|
use float, otherwise use int */
|
2009-05-13 02:58:57 +00:00
|
|
|
if((data->format == (AF_FORMAT_FLOAT_NE)) ||
|
2003-01-10 01:01:38 +00:00
|
|
|
((s->setup & RSMP_MASK) == RSMP_FLOAT)){
|
|
|
|
s->setup = (s->setup & ~RSMP_MASK) | RSMP_FLOAT;
|
2004-12-27 17:30:15 +00:00
|
|
|
af->data->format = AF_FORMAT_FLOAT_NE;
|
2003-01-10 01:01:38 +00:00
|
|
|
af->data->bps = 4;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
s->setup = (s->setup & ~RSMP_MASK) | RSMP_INT;
|
2004-12-27 17:30:15 +00:00
|
|
|
af->data->format = AF_FORMAT_S16_NE;
|
2003-01-10 01:01:38 +00:00
|
|
|
af->data->bps = 2;
|
|
|
|
}
|
2009-03-28 19:57:56 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Using %s processing and %s frequecy"
|
2003-01-10 01:01:38 +00:00
|
|
|
" conversion.\n",
|
|
|
|
((s->setup & RSMP_MASK) == RSMP_FLOAT)?"floating point":"integer",
|
|
|
|
((s->setup & FREQ_MASK) == FREQ_SLOPPY)?"inexact":"exact");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(af->data->format != data->format || af->data->bps != data->bps)
|
|
|
|
rv = AF_FALSE;
|
|
|
|
data->format = af->data->format;
|
|
|
|
data->bps = af->data->bps;
|
|
|
|
af->data->nch = data->nch;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Initialization and runtime control
|
|
|
|
static int control(struct af_instance_s* af, int cmd, void* arg)
|
|
|
|
{
|
|
|
|
switch(cmd){
|
|
|
|
case AF_CONTROL_REINIT:{
|
2009-05-13 02:58:57 +00:00
|
|
|
af_resample_t* s = af->setup;
|
2009-03-06 11:47:51 +00:00
|
|
|
af_data_t* n = arg; // New configuration
|
2002-10-01 06:45:08 +00:00
|
|
|
int i,d = 0;
|
|
|
|
int rv = AF_OK;
|
|
|
|
|
2009-03-06 11:31:18 +00:00
|
|
|
// Free space for circular buffers
|
2003-01-10 01:01:38 +00:00
|
|
|
if(s->xq){
|
2009-03-06 11:39:13 +00:00
|
|
|
free(s->xq[0]);
|
2003-01-10 01:01:38 +00:00
|
|
|
free(s->xq);
|
2006-11-18 17:07:17 +00:00
|
|
|
s->xq = NULL;
|
2003-01-10 01:01:38 +00:00
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2003-01-10 01:01:38 +00:00
|
|
|
if(AF_DETACH == (rv = set_types(af,n)))
|
|
|
|
return AF_DETACH;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
|
|
|
// If linear interpolation
|
2003-01-10 01:01:38 +00:00
|
|
|
if((s->setup & RSMP_MASK) == RSMP_LIN){
|
2002-12-28 13:59:53 +00:00
|
|
|
s->pt=0LL;
|
|
|
|
s->step=((uint64_t)n->rate<<STEPACCURACY)/(uint64_t)af->data->rate+1LL;
|
2009-03-28 19:57:56 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_DBG2, "[resample] Linear interpolation step: 0x%016"PRIX64".\n",
|
2002-12-28 13:59:53 +00:00
|
|
|
s->step);
|
2007-11-01 06:52:01 +00:00
|
|
|
af->mul = (double)af->data->rate / n->rate;
|
2003-01-12 08:05:51 +00:00
|
|
|
return rv;
|
2002-12-28 13:59:53 +00:00
|
|
|
}
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Calculate up and down sampling factors
|
2009-01-17 11:29:36 +00:00
|
|
|
d=av_gcd(af->data->rate,n->rate);
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-10-31 11:06:19 +00:00
|
|
|
// If sloppy resampling is enabled limit the upsampling factor
|
2003-01-10 01:01:38 +00:00
|
|
|
if(((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (af->data->rate/d > 5000)){
|
2002-10-31 11:06:19 +00:00
|
|
|
int up=af->data->rate/2;
|
|
|
|
int dn=n->rate/2;
|
|
|
|
int m=2;
|
|
|
|
while(af->data->rate/(d*m) > 5000){
|
2009-01-17 11:29:36 +00:00
|
|
|
d=av_gcd(up,dn);
|
2002-10-31 11:06:19 +00:00
|
|
|
up/=2; dn/=2; m*=2;
|
|
|
|
}
|
|
|
|
d*=m;
|
|
|
|
}
|
|
|
|
|
2009-03-06 11:31:18 +00:00
|
|
|
// Create space for circular buffers
|
2003-01-10 01:01:38 +00:00
|
|
|
s->xq = malloc(n->nch*sizeof(void*));
|
2009-03-06 11:42:45 +00:00
|
|
|
s->xq[0] = calloc(n->nch, 2*L*af->data->bps);
|
2009-03-06 11:39:13 +00:00
|
|
|
for(i=1;i<n->nch;i++)
|
|
|
|
s->xq[i] = (uint8_t *)s->xq[i-1] + 2*L*af->data->bps;
|
2003-01-10 01:01:38 +00:00
|
|
|
s->xi = 0;
|
|
|
|
|
2009-03-06 11:31:18 +00:00
|
|
|
// Check if the design needs to be redone
|
2002-10-01 06:45:08 +00:00
|
|
|
if(s->up != af->data->rate/d || s->dn != n->rate/d){
|
|
|
|
float* w;
|
|
|
|
float* wt;
|
|
|
|
float fc;
|
|
|
|
int j;
|
2009-05-13 02:58:57 +00:00
|
|
|
s->up = af->data->rate/d;
|
2002-10-01 06:45:08 +00:00
|
|
|
s->dn = n->rate/d;
|
2006-11-19 18:10:04 +00:00
|
|
|
s->wi = 0;
|
|
|
|
s->i = 0;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2009-03-06 11:31:18 +00:00
|
|
|
// Calculate cutoff frequency for filter
|
2002-10-01 06:45:08 +00:00
|
|
|
fc = 1/(float)(max(s->up,s->dn));
|
2009-03-06 11:31:18 +00:00
|
|
|
// Allocate space for polyphase filter bank and prototype filter
|
2002-10-01 06:45:08 +00:00
|
|
|
w = malloc(sizeof(float) * s->up *L);
|
|
|
|
if(NULL != s->w)
|
|
|
|
free(s->w);
|
2003-01-10 01:01:38 +00:00
|
|
|
s->w = malloc(L*s->up*af->data->bps);
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
// Design prototype filter type using Kaiser window with beta = 10
|
2009-05-13 02:58:57 +00:00
|
|
|
if(NULL == w || NULL == s->w ||
|
2004-12-29 19:50:44 +00:00
|
|
|
-1 == af_filter_design_fir(s->up*L, w, &fc, LP|KAISER , 10.0)){
|
2009-03-28 19:57:56 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_ERR, "[resample] Unable to design prototype filter.\n");
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
|
|
|
// Copy data from prototype to polyphase filter
|
|
|
|
wt=w;
|
|
|
|
for(j=0;j<L;j++){//Columns
|
|
|
|
for(i=0;i<s->up;i++){//Rows
|
2003-01-10 01:01:38 +00:00
|
|
|
if((s->setup & RSMP_MASK) == RSMP_INT){
|
2002-12-28 13:59:53 +00:00
|
|
|
float t=(float)s->up*32767.0*(*wt);
|
|
|
|
((int16_t*)s->w)[i*L+j] = (int16_t)((t>=0.0)?(t+0.5):(t-0.5));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
((float*)s->w)[i*L+j] = (float)s->up*(*wt);
|
2002-10-01 06:45:08 +00:00
|
|
|
wt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(w);
|
2009-03-28 19:57:56 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_V, "[resample] New filter designed up: %i "
|
2002-12-28 13:59:53 +00:00
|
|
|
"down: %i\n", s->up, s->dn);
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
|
|
|
|
2002-10-08 10:20:36 +00:00
|
|
|
// Set multiplier and delay
|
2007-11-01 06:52:50 +00:00
|
|
|
af->delay = 0; // not set correctly, but shouldn't be too large anyway
|
2007-11-01 06:52:01 +00:00
|
|
|
af->mul = (double)s->up / s->dn;
|
2002-10-01 06:45:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-10-31 11:06:19 +00:00
|
|
|
case AF_CONTROL_COMMAND_LINE:{
|
2009-05-13 02:58:57 +00:00
|
|
|
af_resample_t* s = af->setup;
|
2002-10-31 11:06:19 +00:00
|
|
|
int rate=0;
|
2003-01-10 01:01:38 +00:00
|
|
|
int type=RSMP_INT;
|
|
|
|
int sloppy=1;
|
2003-01-10 01:45:34 +00:00
|
|
|
sscanf((char*)arg,"%i:%i:%i", &rate, &sloppy, &type);
|
2009-05-13 02:58:57 +00:00
|
|
|
s->setup = (sloppy?FREQ_SLOPPY:FREQ_EXACT) |
|
2003-01-10 01:01:38 +00:00
|
|
|
(clamp(type,RSMP_LIN,RSMP_FLOAT));
|
2002-12-28 13:59:53 +00:00
|
|
|
return af->control(af,AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET, &rate);
|
2002-10-31 11:06:19 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
case AF_CONTROL_POST_CREATE:
|
2003-01-10 01:01:38 +00:00
|
|
|
if((((af_cfg_t*)arg)->force & AF_INIT_FORMAT_MASK) == AF_INIT_FLOAT)
|
2003-01-10 01:45:34 +00:00
|
|
|
((af_resample_t*)af->setup)->setup = RSMP_FLOAT;
|
2002-12-28 13:59:53 +00:00
|
|
|
return AF_OK;
|
2009-05-13 02:58:57 +00:00
|
|
|
case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
|
2002-10-01 06:45:08 +00:00
|
|
|
// Reinit must be called after this function has been called
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Sanity check
|
2002-10-06 11:28:03 +00:00
|
|
|
if(((int*)arg)[0] < 8000 || ((int*)arg)[0] > 192000){
|
2009-05-13 02:58:57 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_ERR, "[resample] The output sample frequency "
|
2002-12-28 13:59:53 +00:00
|
|
|
"must be between 8kHz and 192kHz. Current value is %i \n",
|
|
|
|
((int*)arg)[0]);
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
af->data->rate=((int*)arg)[0];
|
|
|
|
mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Changing sample rate "
|
2002-12-28 13:59:53 +00:00
|
|
|
"to %iHz\n",af->data->rate);
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
|
|
|
return AF_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
// Deallocate memory
|
2002-10-01 06:45:08 +00:00
|
|
|
static void uninit(struct af_instance_s* af)
|
|
|
|
{
|
2009-03-06 11:46:06 +00:00
|
|
|
af_resample_t *s = af->setup;
|
|
|
|
if (s) {
|
|
|
|
if (s->xq) free(s->xq[0]);
|
|
|
|
free(s->xq);
|
|
|
|
free(s->w);
|
|
|
|
free(s);
|
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
if(af->data)
|
2007-02-10 18:12:03 +00:00
|
|
|
free(af->data->audio);
|
|
|
|
free(af->data);
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter data through filter
|
|
|
|
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
|
|
|
int len = 0; // Length of output data
|
|
|
|
af_data_t* c = data; // Current working data
|
|
|
|
af_data_t* l = af->data; // Local data
|
2009-03-06 11:47:51 +00:00
|
|
|
af_resample_t* s = af->setup;
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Run resampling
|
2003-01-10 01:01:38 +00:00
|
|
|
switch(s->setup & RSMP_MASK){
|
|
|
|
case(RSMP_INT):
|
2002-12-28 13:59:53 +00:00
|
|
|
# define FORMAT_I 1
|
|
|
|
if(s->up>s->dn){
|
|
|
|
# define UP
|
2009-01-02 16:13:22 +00:00
|
|
|
# include "af_resample_template.c"
|
2009-05-13 02:58:57 +00:00
|
|
|
# undef UP
|
2002-12-28 13:59:53 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
# define DN
|
2009-01-02 16:13:22 +00:00
|
|
|
# include "af_resample_template.c"
|
2002-12-28 13:59:53 +00:00
|
|
|
# undef DN
|
|
|
|
}
|
|
|
|
break;
|
2003-01-10 01:01:38 +00:00
|
|
|
case(RSMP_FLOAT):
|
2002-12-28 13:59:53 +00:00
|
|
|
# undef FORMAT_I
|
|
|
|
# define FORMAT_F 1
|
|
|
|
if(s->up>s->dn){
|
|
|
|
# define UP
|
2009-01-02 16:13:22 +00:00
|
|
|
# include "af_resample_template.c"
|
2009-05-13 02:58:57 +00:00
|
|
|
# undef UP
|
2002-12-28 13:59:53 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
# define DN
|
2009-01-02 16:13:22 +00:00
|
|
|
# include "af_resample_template.c"
|
2002-12-28 13:59:53 +00:00
|
|
|
# undef DN
|
|
|
|
}
|
|
|
|
break;
|
2003-01-10 01:01:38 +00:00
|
|
|
case(RSMP_LIN):
|
2002-12-28 13:59:53 +00:00
|
|
|
len = linint(c, l, s);
|
|
|
|
break;
|
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
// Set output data
|
|
|
|
c->audio = l->audio;
|
2002-12-28 13:59:53 +00:00
|
|
|
c->len = len*l->bps;
|
2002-10-01 06:45:08 +00:00
|
|
|
c->rate = l->rate;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate memory and set function pointers
|
2007-03-20 09:46:00 +00:00
|
|
|
static int af_open(af_instance_t* af){
|
2002-10-01 06:45:08 +00:00
|
|
|
af->control=control;
|
|
|
|
af->uninit=uninit;
|
|
|
|
af->play=play;
|
2007-11-01 06:52:01 +00:00
|
|
|
af->mul=1;
|
2002-10-01 06:45:08 +00:00
|
|
|
af->data=calloc(1,sizeof(af_data_t));
|
|
|
|
af->setup=calloc(1,sizeof(af_resample_t));
|
|
|
|
if(af->data == NULL || af->setup == NULL)
|
|
|
|
return AF_ERROR;
|
2003-01-10 01:01:38 +00:00
|
|
|
((af_resample_t*)af->setup)->setup = RSMP_INT | FREQ_SLOPPY;
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Description of this plugin
|
|
|
|
af_info_t af_info_resample = {
|
|
|
|
"Sample frequency conversion",
|
|
|
|
"resample",
|
|
|
|
"Anders",
|
|
|
|
"",
|
2002-10-06 11:26:14 +00:00
|
|
|
AF_FLAGS_REENTRANT,
|
2007-03-20 09:46:00 +00:00
|
|
|
af_open
|
2002-10-01 06:45:08 +00:00
|
|
|
};
|